List of usage examples for org.apache.commons.collections15 BidiMap put
V put(K key, V value);
From source file:edu.uci.ics.jung.algorithms.util.Indexer.java
/** * Returns a <code>BidiMap</code> mapping each element of the collection to its * index as encountered while iterating over the collection. The purpose * of the index operation is to supply an O(1) replacement operation for the * O(n) <code>indexOf(element)</code> method of a <code>List</code> * @param <T>// w w w.j a va2 s.c o m * @param collection * @param start start index * @return a bidirectional map from collection elements to start-based indices */ public static <T> BidiMap<T, Integer> create(Collection<T> collection, int start) { BidiMap<T, Integer> map = new DualHashBidiMap<T, Integer>(); int i = start; for (T t : collection) { map.put(t, i++); } return map; }
From source file:de.uniba.wiai.kinf.pw.projects.lillytab.io.OWLAPISWRLLoader.java
private String getVarName(final IRI sourceName, final BidiMap<IRI, String> varNames) { String varName = varNames.get(sourceName); if (varName == null) { final String fragment = sourceName.getRemainder().or(""); if ((!fragment.isEmpty()) && (!varNames.containsValue(fragment))) { varNames.put(sourceName, varName); varName = fragment;// w ww .jav a 2 s. c om } else { /* * generate an indexed varname */ for (int i = 0; (varName == null) || (varNames.containsValue(varName)); ++i) { varName = String.format("v%d", i); } } } assert varName != null; return varName; }
From source file:com.net2plan.gui.tools.GUINetworkDesign.java
@Override public void configure(JPanel contentPane) { this.currentNetPlan = new NetPlan(); BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>(); Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>(); for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) { mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size()); layerVisibilityMap.put(layer, true); }// w w w. ja va2 s.c o m this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap, MAXSIZEUNDOLISTPICK); topologyPanel = new TopologyPanel(this, JUNGCanvas.class); JPanel leftPane = new JPanel(new BorderLayout()); JPanel logSection = configureLeftBottomPanel(); if (logSection == null) { leftPane.add(topologyPanel, BorderLayout.CENTER); } else { JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPaneTopology.setTopComponent(topologyPanel); splitPaneTopology.setBottomComponent(logSection); splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener()); splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground())); splitPaneTopology.setOneTouchExpandable(true); splitPaneTopology.setDividerSize(7); leftPane.add(splitPaneTopology, BorderLayout.CENTER); } contentPane.add(leftPane, "grow"); viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout()); reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT); setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState .generateCanvasDefaultVisualizationLayerInfo(getDesign()); vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond()); /* Initialize the undo/redo manager, and set its initial design */ this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES); this.undoRedoManager.addNetPlanChange(); onlineSimulationPane = new OnlineSimulationPane(this); executionPane = new OfflineExecutionPanel(this); whatIfAnalysisPane = new WhatIfAnalysisPane(this); // Closing windows WindowUtils.clearFloatingWindows(); final JTabbedPane tabPane = new JTabbedPane(); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network), viewEditTopTables); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online), onlineSimulationPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif), whatIfAnalysisPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane); // Installing customized mouse listener MouseListener[] ml = tabPane.getListeners(MouseListener.class); for (int i = 0; i < ml.length; i++) { tabPane.removeMouseListener(ml[i]); } // Left click works as usual, right click brings up a pop-up menu. tabPane.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { JTabbedPane tabPane = (JTabbedPane) e.getSource(); int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY()); if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) { if (tabIndex == tabPane.getSelectedIndex()) { if (tabPane.isRequestFocusEnabled()) { tabPane.requestFocus(); tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex)); } } else { tabPane.setSelectedIndex(tabIndex); } if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) { final JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem popWindow = new JMenuItem("Pop window out"); popWindow.addActionListener(e1 -> { final int selectedIndex = tabPane.getSelectedIndex(); final String tabName = tabPane.getTitleAt(selectedIndex); final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent(); // Pops up the selected tab. final WindowController.WindowToTab windowToTab = WindowController.WindowToTab .parseString(tabName); if (windowToTab != null) { switch (windowToTab) { case offline: WindowController.buildOfflineWindow(selectedComponent); WindowController.showOfflineWindow(true); break; case online: WindowController.buildOnlineWindow(selectedComponent); WindowController.showOnlineWindow(true); break; case whatif: WindowController.buildWhatifWindow(selectedComponent); WindowController.showWhatifWindow(true); break; case report: WindowController.buildReportWindow(selectedComponent); WindowController.showReportWindow(true); break; default: return; } } tabPane.setSelectedIndex(0); }); // Disabling the pop up button for the network state tab. if (WindowController.WindowToTab.parseString(tabPane .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) { popWindow.setEnabled(false); } popupMenu.add(popWindow); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); // Building windows WindowController.buildTableControlWindow(tabPane); WindowController.showTablesWindow(false); addAllKeyCombinationActions(); updateVisualizationAfterNewTopology(); }
From source file:edu.utah.further.core.util.context.EnumAliasService.java
/** * Set the static enum alias map field./* w w w . ja v a2 s. c o m*/ * <p> * Warning: do not call this method outside this class. It is meant to be called by * Spring when instantiating the singleton instance of this bean. */ @SuppressWarnings("unchecked") private BidiMap<String, Class<? extends Enum<?>>> initializeEnumAliases() { final Class<Alias> annotationClass = Alias.class; // TODO: move to CollectionUtil as a generic factory method final BidiMap<String, Class<? extends Enum<?>>> map = new DualHashBidiMap<>(); for (final Class<?> annotatedClass : this.getObject()) { if (annotatedClass.isEnum()) { final String alias = annotatedClass.getAnnotation(annotationClass).value(); final Class<? extends Enum<?>> otherClass = map.get(alias); if (otherClass != null) { // This is the second time that we encountered the alias // key, signal name collision final String errorMessage = "Enum alias collision!!! Both " + otherClass + ", " + annotatedClass + " have the same alias: " + quote(alias) + ". Rename the @" + annotationClass.getSimpleName() + " annotation value one of them."; // Log message before throwing, otherwise Spring will // show an incomprehensible TargetInvocationException // without its cause here. log.error(errorMessage); throw new ApplicationException(errorMessage); } map.put(alias, (Class<? extends Enum<?>>) annotatedClass); } } return map; }
From source file:org.drugis.mtc.gui.Util.java
public static <E> BidiMap<E, E> identityMap(final Collection<? extends E> objs) { BidiMap<E, E> map = new DualHashBidiMap<E, E>(); for (E e : objs) { map.put(e, e); }/*from ww w.j a v a 2 s.c om*/ return map; }
From source file:org.drugis.mtc.presentation.AbstractSimulationWrapperTest.java
@Before public void setUp() { d_treatments = Arrays.asList("A", "B", "C"); BidiMap<String, Treatment> treatmentMap = new DualHashBidiMap<String, Treatment>(); ArrayList<Treatment> treatmentList = new ArrayList<Treatment>(); for (String s : d_treatments) { final Treatment t = new Treatment(s, ""); treatmentMap.put(s, t); treatmentList.add(t);/*from w w w .ja va2s . c o m*/ } ConsistencyModel mtc = MockConsistencyModel.buildMockSimulationConsistencyModel(treatmentList); d_model = new AbstractMTCSimulationWrapper<String, ConsistencyModel>(mtc, "Stub Model", treatmentMap) { }; }
From source file:org.openanzo.glitter.query.QueryController.java
/** * Pretty print query string/*from w w w .j a va 2s.co m*/ * * @param printFlags * print flags * @param startIndentLevel * @return pretty print version of query */ @SuppressWarnings("all") public String prettyPrintQueryString(EnumSet<QueryStringPrintOptions> printFlags, int startIndentLevel) { QueryResultForm queryResultForm = this.getQueryResultForm(); StringBuilder s = new StringBuilder(); // output the base, if any if (this.baseUri != null) { s.append("BASE <"); s.append(this.baseUri); s.append(">"); printSeparator(printFlags, 0, s); } // add prefixes for all URIs mentioned in the query final BidiMap<String, String> prefix2uri = new TreeBidiMap<String, String>(); Map<String, String> uri2prefix = prefix2uri.inverseBidiMap(); for (Entry<String, URI> e : this.prefixMap.entrySet()) prefix2uri.put(e.getKey(), e.getValue().toString()); for (Entry<String, URI> e : this.queryOptions.entrySet()) prefix2uri.put(e.getKey(), e.getValue().toString()); if (printFlags.contains(QueryStringPrintOptions.GENERATE_NEW_PREFIXES)) { visitURIs(new URIVisitor() { private int p = 0; public boolean visitURI(URI u) { if (!prefix2uri.containsValue(u.getNamespace())) { // TODO - could use next-to-last URI component to name prefix while (prefix2uri.containsKey("p" + ++p)) ; prefix2uri.put("p" + p, u.getNamespace()); } return true; } }, false, true); } // output prefixes MapIterator<String, String> it = prefix2uri.mapIterator(); while (it.hasNext()) { String key = it.next(); String value = it.getValue(); s.append("PREFIX "); s.append(key); s.append(": <"); s.append(value); s.append(">"); printSeparator(printFlags, 0, s); } this.resultForm.prettyPrintQueryPart(printFlags, startIndentLevel, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); if (isDatasetFromQuery()) { for (URI u : getQueryDataset().getDefaultGraphURIs()) { s.append("FROM "); printURI(u, printFlags, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); } for (URI u : getQueryDataset().getNamedGraphURIs()) { s.append("FROM NAMED "); printURI(u, printFlags, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); } for (URI u : getQueryDataset().getNamedDatasetURIs()) { s.append("FROM DATASET "); printURI(u, printFlags, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); } } s.append("WHERE {"); printSeparator(printFlags, startIndentLevel + 1, s); this.queryPattern.prettyPrintQueryPart(printFlags, startIndentLevel + 1, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); s.append("}"); if (queryResultForm instanceof Projection) { Projection projection = (Projection) queryResultForm; if (!projection.getGroupByVariables().isEmpty()) { printSeparator(printFlags, startIndentLevel, s); projection.prettyPrintGroupByQueryPart(printFlags, startIndentLevel, uri2prefix, s); } } if (this.ordering.size() > 0) { printSeparator(printFlags, startIndentLevel, s); s.append("ORDER BY "); for (int i = 0; i < this.ordering.size(); i++) { OrderingCondition c = this.ordering.get(i); if (i != 0) s.append(' '); c.prettyPrintQueryPart(printFlags, startIndentLevel, uri2prefix, s); } printSeparator(printFlags, startIndentLevel, s); } if (this.limit > -1) { printSeparator(printFlags, startIndentLevel, s); s.append("LIMIT "); s.append(this.limit); } if (this.offset > -1) { printSeparator(printFlags, startIndentLevel, s); s.append("OFFSET "); s.append(this.offset); } if (printFlags.contains(QueryStringPrintOptions.REMOVE_UNUSED_PREFIXES)) { String q = s.toString(); s = new StringBuilder(); String[] lines = q.split("\n"); Pattern p = Pattern.compile("^PREFIX\\s*(\\w+:)", Pattern.CASE_INSENSITIVE); boolean first = true; for (String line : lines) { Matcher m = p.matcher(line); if (m.find()) { Pattern prefix = Pattern.compile("\\W" + m.group(1)); if (prefix.split(q).length <= 2) continue; } if (!first) s.append('\n'); s.append(line); first = false; } } return s.toString(); }
From source file:org.openanzo.glitter.query.SubqueryController.java
/** * Pretty print query string// w w w .jav a2 s .co m * * @param printFlags * print flags * @param startIndentLevel * @return pretty print version of query */ @SuppressWarnings("all") public void prettyPrintQueryStringPart(EnumSet<QueryStringPrintOptions> printFlags, int startIndentLevel, StringBuilder s) { QueryResultForm queryResultForm = this.getQueryResultForm(); final BidiMap<String, String> prefix2uri = new TreeBidiMap<String, String>(); Map<String, String> uri2prefix = prefix2uri.inverseBidiMap(); for (Entry<String, URI> e : this.parent.prefixMap.entrySet()) prefix2uri.put(e.getKey(), e.getValue().toString()); this.resultForm.prettyPrintQueryPart(printFlags, startIndentLevel, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); s.append("WHERE {"); printSeparator(printFlags, startIndentLevel + 1, s); this.queryPattern.prettyPrintQueryPart(printFlags, startIndentLevel + 1, uri2prefix, s); printSeparator(printFlags, startIndentLevel, s); s.append("}"); if (queryResultForm instanceof Projection) { Projection projection = (Projection) queryResultForm; if (!projection.getGroupByVariables().isEmpty()) { printSeparator(printFlags, startIndentLevel, s); projection.prettyPrintGroupByQueryPart(printFlags, startIndentLevel, uri2prefix, s); } } if (this.ordering.size() > 0) { printSeparator(printFlags, 0, s); s.append("ORDER BY "); for (int i = 0; i < this.ordering.size(); i++) { OrderingCondition c = this.ordering.get(i); if (i != 0) s.append(' '); c.prettyPrintQueryPart(printFlags, startIndentLevel, uri2prefix, s); } printSeparator(printFlags, startIndentLevel, s); } if (this.limit > -1) { printSeparator(printFlags, startIndentLevel, s); s.append("LIMIT "); s.append(this.limit); } if (this.offset > -1) { printSeparator(printFlags, startIndentLevel, s); s.append("OFFSET "); s.append(this.offset); } }