Example usage for org.apache.commons.collections15.bidimap DualHashBidiMap DualHashBidiMap

List of usage examples for org.apache.commons.collections15.bidimap DualHashBidiMap DualHashBidiMap

Introduction

In this page you can find the example usage for org.apache.commons.collections15.bidimap DualHashBidiMap DualHashBidiMap.

Prototype

public DualHashBidiMap() 

Source Link

Document

Creates an empty HashBidiMap.

Usage

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>/* www .j a  v  a2  s . co 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

public ISWRLRule<OWLIndividual, OWLLiteral, OWLClass, OWLProperty> convertRule(final SWRLRule sourceRule) {
    final BidiMap<IRI, String> varNames = new DualHashBidiMap<>();
    final Set<ISWRLAtomicTerm<OWLIndividual, OWLLiteral, OWLClass, OWLProperty>> bodyAtoms = convertAtoms(
            sourceRule.getBody(), varNames);
    final Set<ISWRLAtomicTerm<OWLIndividual, OWLLiteral, OWLClass, OWLProperty>> headAtoms = convertAtoms(
            sourceRule.getHead(), varNames);
    final ISWRLRule<OWLIndividual, OWLLiteral, OWLClass, OWLProperty> targetRule = _swrlFactory.getSWRLRule(
            SWRLTermUtil.joinIntoIntersection(headAtoms, _swrlFactory),
            SWRLTermUtil.joinIntoIntersection(bodyAtoms, _swrlFactory));
    return targetRule;
}

From source file:edu.utah.further.core.util.context.EnumAliasService.java

/**
 * Set the static enum alias map field./*from ww  w.  j  a v  a2s  . co  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:edu.uci.ics.jung.io.GraphMLReader.java

/**
 * Creates a <code>GraphMLReader</code> instance with the specified
 * vertex and edge factories./*from  w w  w.ja va  2 s. co  m*/
 *
 * @param vertex_factory the vertex factory to use to create vertex objects
 * @param edge_factory the edge factory to use to create edge objects
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public GraphMLReader(Factory<V> vertex_factory, Factory<E> edge_factory)
        throws ParserConfigurationException, SAXException {
    current_vertex = null;
    current_edge = null;

    SAXParserFactory factory = SAXParserFactory.newInstance();
    saxp = factory.newSAXParser();

    current_states = new LinkedList<TagState>();

    tag_state = new DualHashBidiMap<String, TagState>();
    tag_state.put("node", TagState.VERTEX);
    tag_state.put("edge", TagState.EDGE);
    tag_state.put("hyperedge", TagState.HYPEREDGE);
    tag_state.put("endpoint", TagState.ENDPOINT);
    tag_state.put("graph", TagState.GRAPH);
    tag_state.put("data", TagState.DATA);
    tag_state.put("key", TagState.KEY);
    tag_state.put("desc", TagState.DESC);
    tag_state.put("default", TagState.DEFAULT_KEY);
    tag_state.put("graphml", TagState.GRAPHML);

    this.key_type = KeyType.NONE;

    this.vertex_factory = vertex_factory;
    this.edge_factory = edge_factory;
}

From source file:net.itransformers.topologyviewer.gui.MyGraphMLReader.java

/**
 * Creates a <code>GraphMLReader</code> instance with the specified
 * vertex and edge factories./*from  www  .j  ava2 s .  com*/
 *
 * @param vertex_factory the vertex factory to use to create vertex objects
 * @param edge_factory the edge factory to use to create edge objects
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public MyGraphMLReader(Factory<V> vertex_factory, Factory<E> edge_factory)
        throws ParserConfigurationException, SAXException {
    current_vertex = null;
    current_edge = null;

    SAXParserFactory factory = SAXParserFactory.newInstance();
    saxp = factory.newSAXParser();

    current_states = new LinkedList<TagState>();

    tag_state = new DualHashBidiMap<String, TagState>();
    tag_state.put("node", TagState.VERTEX);
    tag_state.put("edge", TagState.EDGE);
    tag_state.put("hyperedge", TagState.HYPEREDGE);
    tag_state.put("endpoint", TagState.ENDPOINT);
    tag_state.put("graph", TagState.GRAPH);
    tag_state.put("data", TagState.DATA);
    tag_state.put("key", TagState.KEY);
    tag_state.put("desc", TagState.DESC);
    tag_state.put("default", TagState.DEFAULT_KEY);
    tag_state.put("graphml", TagState.GRAPHML);

    this.key_type = KeyType.NONE;

    this.vertex_factory = vertex_factory;
    this.edge_factory = edge_factory;
}

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);
    }/*from   w w w .j  a v a  2s .  c om*/
    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.uci.ics.jung.io.GraphMLReader.java

/**
 * This is separate from initialize() because these data structures are shared among all
 * graphs loaded (i.e., they're defined inside <code>graphml</code> rather than <code>graph</code>.
 *//*from  w w w . ja  v  a 2  s.  co m*/
protected void initializeData() {
    this.vertex_ids = new DualHashBidiMap<V, String>();
    this.vertex_desc = new HashMap<V, String>();
    this.vertex_metadata = new HashMap<String, GraphMLMetadata<V>>();

    this.edge_ids = new DualHashBidiMap<E, String>();
    this.edge_desc = new HashMap<E, String>();
    this.edge_metadata = new HashMap<String, GraphMLMetadata<E>>();

    this.graph_desc = new HashMap<G, String>();
    this.graph_metadata = new HashMap<String, GraphMLMetadata<G>>();

    this.hyperedge_vertices = new ArrayList<V>();
}

From source file:edu.mit.magnum.net.Network.java

/** Load the set of reference nodes */
public void loadRefNodes(File file) {

    // Open the file
    FileParser parser = new FileParser(mag.log, file);
    String[] nextLine = parser.readLine();
    refNodeIndexMap_ = new DualHashBidiMap<Node, Integer>();

    // For each node
    while (nextLine != null) {
        if (nextLine.length != 1)
            throw new RuntimeException("Line " + parser.getLineCounter() + " has " + nextLine.length
                    + " columns (file format is one node ID per line)");

        // Get the node
        String id = nextLine[0];//from ww w .ja v a2  s. c  om
        Node node = getNode(id);
        if (node == null)
            throw new RuntimeException(
                    "Line " + parser.getLineCounter() + ": node '" + id + "' is not part of the network");

        if (refNodeIndexMap_.containsKey(node))
            throw new RuntimeException(
                    "Line " + parser.getLineCounter() + ": node '" + id + "' is listed multiple times");

        // Add the ref node
        refNodeIndexMap_.put(node, parser.getLineCounter() - 1);

        // Read the next line
        nextLine = parser.readLine();
    }
    assert parser.getLineCounter() - 1 == refNodeIndexMap_.size();

    numRefNodes_ = refNodeIndexMap_.size();
    useRefNodes_ = true;
}

From source file:com.net2plan.gui.GUINet2Plan.java

private void start() {
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    setMinimumSize(new Dimension(800, 600));

    itemObject = new DualHashBidiMap<JMenuItem, Object>();

    URL iconURL = GUINet2Plan.class.getResource("/resources/gui/icon.png");
    ImageIcon icon = new ImageIcon(iconURL);
    setIconImage(icon.getImage());/*ww  w  . j  av  a  2 s. co m*/
    setTitle("Net2Plan");
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(CLOSE_NET2PLAN);

    getContentPane().setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]"));
    container = new JPanel(new MigLayout("", "[]", "[]"));
    container.setBorder(new LineBorder(Color.BLACK));
    container.setLayout(new MigLayout("fill"));
    getContentPane().add(container, "grow");

    /* Create menu bar */
    menu = new JMenuBar();
    setJMenuBar(menu);

    /* File menu */
    JMenu file = new JMenu("File");
    file.setMnemonic('F');
    menu.add(file);

    optionsItem = new JMenuItem("Options");
    optionsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_DOWN_MASK));
    optionsItem.addActionListener(this);
    file.add(optionsItem);

    classPathEditorItem = new JMenuItem("Classpath editor");
    classPathEditorItem.addActionListener(this);
    file.add(classPathEditorItem);

    errorConsoleItem = new JMenuItem("Show Java console");
    errorConsoleItem.addActionListener(this);
    errorConsoleItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, InputEvent.ALT_DOWN_MASK));
    file.add(errorConsoleItem);

    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_DOWN_MASK));
    file.add(exitItem);

    /* Help menu */
    JMenu help = new JMenu("Help");
    help.setMnemonic('H');
    menu.add(help);

    aboutItem = new JMenuItem("About");
    aboutItem.addActionListener(this);
    help.add(aboutItem);
    itemObject.put(aboutItem, showAbout());

    helpItem = new JMenuItem("User's guide");
    helpItem.addActionListener(this);
    helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.VK_UNDEFINED));
    help.add(helpItem);

    javadocItem = new JMenuItem("Library API Javadoc");
    javadocItem.addActionListener(this);
    help.add(javadocItem);

    javadocExamplesItem = new JMenuItem("Built-in Examples Javadoc");
    javadocExamplesItem.addActionListener(this);
    help.add(javadocExamplesItem);

    keyCombinationItem = new JMenuItem("Show tool key combinations");
    keyCombinationItem.addActionListener(this);
    keyCombinationItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.ALT_DOWN_MASK));
    help.add(keyCombinationItem);

    usedKeyStrokes = new LinkedHashSet<KeyStroke>();
    refreshMenu();

    container.add(showAbout(), "align center");
    container.revalidate();

    new JFileChooser(); /* Do not remove! It is used to avoid slow JFileChooser first-time loading once Net2Plan is shown to the user */

    setVisible(true);
}

From source file:edu.mit.magnum.net.Network.java

/** Put all the nodes from the graph into the nodes_ hash map */
private void initializeNodeMaps() {

    // Create Node-Index bidi map
    nodeIndexMap_ = Indexer.create(graph_.getVertices());

    // Create a sorted list of nodes
    ArrayList<Node> nodes = new ArrayList<Node>(graph_.getVertices());
    Collections.sort(nodes, Node.getNodeComparator());

    // Create the index map
    nodeIndexMap_ = new DualHashBidiMap<Node, Integer>();
    for (int i = 0; i < nodes.size(); i++)
        nodeIndexMap_.put(nodes.get(i), i);

    // All nodes are reference nodes by default
    refNodeIndexMap_ = nodeIndexMap_;/*from   w w  w  . j a  v a  2 s.  c  o m*/

    // Create Label-Index map
    //nodeLabelMap_ = new HashMap<String, Node>();
    labelIndexMap_ = new HashMap<String, Integer>();

    // Loop over the nodes, put then into the map
    Iterator<Node> iter = graph_.getVertices().iterator();
    while (iter.hasNext()) {
        Node n = iter.next();
        //nodeLabelMap_.put(n.getId(), n);
        labelIndexMap_.put(n.getId(), nodeIndexMap_.get(n));
    }

    //assert(nodeLabelMap_.size() == graph_.getVertexCount());
    assert (nodeIndexMap_.size() == graph_.getVertexCount());
}