Example usage for org.apache.commons.collections4 BidiMap get

List of usage examples for org.apache.commons.collections4 BidiMap get

Introduction

In this page you can find the example usage for org.apache.commons.collections4 BidiMap get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:de.decoit.simu.cbor.xml.dictionary.DictionaryTest.java

@Test
public void testAddNamespace() {
    DictionaryNamespace dns = new DictionaryNamespace(xmlName, cborName);

    Dictionary instance = new Dictionary();
    instance.addNamespace(dns);//from   w w  w.j  a v  a  2s.c om

    BidiMap<String, DictionaryNamespace> result = instance.getUnmodifiableNamespaces();
    assertTrue(result.containsKey(xmlName));
    assertTrue(result.containsValue(dns));
    assertEquals(dns, result.get(xmlName));
}

From source file:net.sf.jasperreports.engine.data.JRCsvDataSource.java

protected void assignColumnNames() {
    BidiMap<Integer, String> indexColumns = new DualHashBidiMap<Integer, String>();
    for (int i = 0; i < crtRecordColumnValues.size(); i++) {
        String name = crtRecordColumnValues.get(i);

        Integer existingIdx = indexColumns.getKey(name);
        if (existingIdx == null) {
            //use the name from the file if possible
            indexColumns.put(i, name);//from ww  w.  ja  v a2 s . c o m
        } else {
            //the name is taken, force COLUMN_i for this column and recursively if COLUMN_x is already used
            Integer forceIndex = i;
            do {
                String indexName = INDEXED_COLUMN_PREFIX + forceIndex;
                Integer existingIndex = indexColumns.getKey(indexName);
                indexColumns.put(forceIndex, indexName);
                forceIndex = existingIndex;
            } while (forceIndex != null);
        }
    }

    this.columnNames = new LinkedHashMap<String, Integer>();
    for (int i = 0; i < crtRecordColumnValues.size(); i++) {
        String columnName = indexColumns.get(i);
        this.columnNames.put(columnName, i);
    }
}

From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java

/**
 * Creates the account two account./*w  w w  .  j ava2 s .  co m*/
 *
 * @param _parameter the parameter
 * @param _basePeriodInst the base period inst
 * @param _periodInst the period inst
 * @param _existing2new the existing 2 new
 * @throws EFapsException the eFaps exception
 */
protected void createAccount2Account(final Parameter _parameter, final Instance _basePeriodInst,
        final Instance _periodInst, final BidiMap<Instance, Instance> _existing2new) throws EFapsException {
    final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.Account2AccountAbstract);

    final QueryBuilder attrQueryBldr = new QueryBuilder(CIAccounting.AccountAbstract);
    attrQueryBldr.addWhereAttrEqValue(CIAccounting.AccountAbstract.PeriodAbstractLink, _basePeriodInst);
    final AttributeQuery attrQuery = attrQueryBldr.getAttributeQuery(CIAccounting.AccountAbstract.ID);
    queryBldr.addWhereAttrInQuery(CIAccounting.Account2AccountAbstract.FromAccountLink, attrQuery);
    queryBldr.addWhereAttrInQuery(CIAccounting.Account2AccountAbstract.ToAccountLink, attrQuery);

    final MultiPrintQuery multi = queryBldr.getPrint();
    final SelectBuilder selFromAccInst = SelectBuilder.get()
            .linkto(CIAccounting.Account2AccountAbstract.FromAccountLink).instance();
    final SelectBuilder selToAccInst = SelectBuilder.get()
            .linkto(CIAccounting.Account2AccountAbstract.ToAccountLink).instance();
    multi.addSelect(selFromAccInst, selToAccInst);
    multi.addAttribute(CIAccounting.Account2AccountAbstract.Denominator,
            CIAccounting.Account2AccountAbstract.Numerator, CIAccounting.Account2AccountAbstract.Config);
    multi.execute();
    while (multi.next()) {
        final Instance fromAccInst = multi.getSelect(selFromAccInst);
        final Instance toAccInst = multi.getSelect(selToAccInst);
        final Instance newFromAccInst = _existing2new.get(fromAccInst);
        final Instance newToAccInst = _existing2new.get(toAccInst);
        if (InstanceUtils.isValid(newFromAccInst) && InstanceUtils.isValid(newToAccInst)) {
            final Insert insert = new Insert(multi.getCurrentInstance().getType());
            insert.add(CIAccounting.Account2AccountAbstract.FromAccountLink, newFromAccInst);
            insert.add(CIAccounting.Account2AccountAbstract.ToAccountLink, newToAccInst);
            insert.add(CIAccounting.Account2AccountAbstract.Denominator,
                    multi.<Object>getAttribute(CIAccounting.Account2AccountAbstract.Denominator));
            insert.add(CIAccounting.Account2AccountAbstract.Numerator,
                    multi.<Object>getAttribute(CIAccounting.Account2AccountAbstract.Numerator));
            insert.add(CIAccounting.Account2AccountAbstract.Config,
                    multi.<Object>getAttribute(CIAccounting.Account2AccountAbstract.Config));
            insert.execute();
        }
    }
    LOG.info("created Account2Account");
}

From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java

/**
 * Creates the period two account./* w ww.j  a  v a  2s  . c  om*/
 *
 * @param _parameter the parameter
 * @param _basePeriodInst the base period inst
 * @param _periodInst the period inst
 * @param _existing2new the existing 2 new
 * @throws EFapsException the eFaps exception
 */
protected void createPeriod2Account(final Parameter _parameter, final Instance _basePeriodInst,
        final Instance _periodInst, final BidiMap<Instance, Instance> _existing2new) throws EFapsException {

    final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.Period2Account);
    queryBldr.addWhereAttrEqValue(CIAccounting.Period2Account.PeriodLink, _basePeriodInst);
    final MultiPrintQuery multi = queryBldr.getPrint();
    final SelectBuilder selAccountInst = SelectBuilder.get()
            .linkto(CIAccounting.Period2Account.FromAccountAbstractLink).instance();
    multi.addSelect(selAccountInst);
    multi.addAttribute(CIAccounting.Period2Account.SalesAccountLink);
    multi.execute();
    while (multi.next()) {
        final Instance accountInst = multi.getSelect(selAccountInst);
        final Instance targetAccInst = _existing2new.get(accountInst);
        if (InstanceUtils.isValid(targetAccInst)) {
            final Insert insert = new Insert(CIAccounting.Period2Account);
            insert.add(CIAccounting.Period2Account.PeriodLink, _periodInst);
            insert.add(CIAccounting.Period2Account.FromAccountAbstractLink, targetAccInst);
            insert.add(CIAccounting.Period2Account.SalesAccountLink,
                    multi.<Object>getAttribute(CIAccounting.Period2Account.SalesAccountLink));
            insert.execute();
        }
    }
    LOG.info("created Period2Acount");
}

From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java

/**
 * Creates the report two case.//w w  w  .j  ava  2  s.  com
 *
 * @param _parameter the parameter
 * @param _currentCaseInst the current case inst
 * @param _existing2new the existing 2 new
 * @throws EFapsException the e faps exception
 */
protected void createReport2Case(final Parameter _parameter, final Instance _currentCaseInst,
        final BidiMap<Instance, Instance> _existing2new) throws EFapsException {
    final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.Report2Case);
    queryBldr.addWhereAttrEqValue(CIAccounting.Report2Case.ToLink, _currentCaseInst);
    final MultiPrintQuery multi = queryBldr.getPrint();
    final SelectBuilder selRepInst = SelectBuilder.get().linkto(CIAccounting.Report2Case.FromLink).instance();
    multi.addSelect(selRepInst);
    multi.execute();
    while (multi.next()) {
        final Instance repInst = multi.getSelect(selRepInst);
        final Instance newRepInst = _existing2new.get(repInst);
        final Instance newCaseInst = _existing2new.get(_currentCaseInst);
        if (InstanceUtils.isValid(newRepInst) && InstanceUtils.isValid(newCaseInst)) {
            final Insert insert = new Insert(multi.getCurrentInstance().getType());
            insert.add(CIAccounting.Report2Case.ToLink, newCaseInst);
            insert.add(CIAccounting.Report2Case.FromLink, newRepInst);
            insert.execute();
        }
    }
}

From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java

/**
 * Creates the account two case./*from w w w.j  a  v a  2 s  . c o m*/
 *
 * @param _parameter the parameter
 * @param _currentCaseInst the current case inst
 * @param _existing2new the existing 2 new
 * @throws EFapsException the eFaps exception
 */
protected void createAccount2Case(final Parameter _parameter, final Instance _currentCaseInst,
        final BidiMap<Instance, Instance> _existing2new) throws EFapsException {

    final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.Account2CaseAbstract);
    queryBldr.addWhereAttrEqValue(CIAccounting.Account2CaseAbstract.ToCaseAbstractLink, _currentCaseInst);
    final MultiPrintQuery multi = queryBldr.getPrint();
    final SelectBuilder selAccountInst = SelectBuilder.get()
            .linkto(CIAccounting.Account2CaseAbstract.FromAccountAbstractLink).instance();
    multi.addSelect(selAccountInst);
    multi.addAttribute(CIAccounting.Account2CaseAbstract.AmountConfig);
    multi.execute();
    while (multi.next()) {
        final Instance currentInst = multi.getCurrentInstance();
        final Insert insert = new Insert(currentInst.getType());
        insert.add(CIAccounting.Account2CaseAbstract.AmountConfig,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.AmountConfig));
        insert.add(CIAccounting.Account2CaseAbstract.Config,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.Config));
        insert.add(CIAccounting.Account2CaseAbstract.CurrencyLink,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.CurrencyLink));
        insert.add(CIAccounting.Account2CaseAbstract.Denominator,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.Denominator));
        insert.add(CIAccounting.Account2CaseAbstract.Key,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.Key));
        insert.add(CIAccounting.Account2CaseAbstract.Numerator,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.Numerator));
        insert.add(CIAccounting.Account2CaseAbstract.Order,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.Order));
        insert.add(CIAccounting.Account2CaseAbstract.Remark,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.Remark));
        insert.add(CIAccounting.Account2CaseAbstract.LinkValue,
                multi.<Object>getAttribute(CIAccounting.Account2CaseAbstract.LinkValue));
        final Instance accInst = multi.getSelect(selAccountInst);

        insert.add(CIAccounting.Account2CaseAbstract.FromAccountAbstractLink, _existing2new.get(accInst));
        insert.add(CIAccounting.Account2CaseAbstract.ToCaseAbstractLink, _existing2new.get(_currentCaseInst));
        insert.execute();
    }
}

From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java

/**
 * Creates the accounts.// w  w  w  .ja v  a  2s  .  com
 *
 * @param _parameter the parameter
 * @param _basePeriodInst the base period inst
 * @param _periodInst the period inst
 * @param _existing2new the existing 2 new
 * @throws EFapsException the eFaps exception
 */
protected void createAccounts(final Parameter _parameter, final Instance _basePeriodInst,
        final Instance _periodInst, final BidiMap<Instance, Instance> _existing2new) throws EFapsException {
    final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.AccountAbstract);
    queryBldr.addWhereAttrEqValue(CIAccounting.AccountAbstract.PeriodAbstractLink, _basePeriodInst);
    queryBldr.addWhereAttrEqValue(CIAccounting.AccountAbstract.Active, true);
    final MultiPrintQuery multi = queryBldr.getPrint();
    final SelectBuilder selParentInst = SelectBuilder.get().linkto(CIAccounting.AccountAbstract.ParentLink)
            .instance();
    multi.addSelect(selParentInst);
    multi.addAttribute(CIAccounting.AccountAbstract.Description, CIAccounting.AccountAbstract.Name,
            CIAccounting.AccountAbstract.Summary);
    multi.execute();
    final Map<Instance, Instance> child2parent = new HashMap<>();
    while (multi.next()) {
        final Instance currentAccInst = multi.getCurrentInstance();
        final Instance parentInst = multi.getSelect(selParentInst);
        if (InstanceUtils.isValid(parentInst)) {
            child2parent.put(currentAccInst, parentInst);
        }
        final String name = multi.getAttribute(CIAccounting.AccountAbstract.Name);
        final String descr = multi.<String>getAttribute(CIAccounting.AccountAbstract.Description);
        final Insert insert = new Insert(currentAccInst.getType());
        insert.add(CIAccounting.AccountAbstract.PeriodAbstractLink, _periodInst);
        insert.add(CIAccounting.AccountAbstract.Name, name);
        insert.add(CIAccounting.AccountAbstract.Description, descr);
        insert.add(CIAccounting.AccountAbstract.Summary,
                multi.<Boolean>getAttribute(CIAccounting.AccountAbstract.Summary));
        insert.add(CIAccounting.AccountAbstract.Active, true);
        insert.execute();
        final Instance newAccInst = insert.getInstance();

        _existing2new.put(currentAccInst, newAccInst);
        LOG.info("added Account {} - {}", name, descr);
    }
    for (final Entry<Instance, Instance> entry : child2parent.entrySet()) {
        final Instance childInst = _existing2new.get(entry.getKey());
        final Instance parentInst = _existing2new.get(entry.getValue());
        final Update update = new Update(childInst);
        update.add(CIAccounting.AccountAbstract.ParentLink, parentInst);
        update.execute();
    }
}

From source file:org.kitodo.dataaccess.format.xml.Namespaces.java

/**
 * Grants that a prefix is available for a namespace. Missing prefixes are
 * either fetched from the constants or the presets or else are created
 * alphabetically ascending.//from  w ww  .  j a  v a  2 s .  com
 *
 * @param namespace
 *            the namespace
 */
private void available(String namespace) {
    if (!used.containsKey(namespace)) {
        if (CONSTANTS.containsKey(namespace)) {
            used.put(namespace, CONSTANTS.get(namespace));
        } else {
            String withHash = namespace.endsWith("/") || namespace.endsWith("#") ? namespace
                    : namespace.concat("#");
            BidiMap<String, String> inversedSuper = super.inverseBidiMap();
            if (inversedSuper.containsKey(withHash)) {
                used.put(namespace, inversedSuper.get(withHash));
            } else {
                String prefix;
                do {
                    prefix = asLetters(++next);
                } while (super.containsKey(prefix) || CONSTANTS.containsValue(prefix));
                used.put(namespace, prefix);
            }
        }
    }
}

From source file:research.NetworkAligner.java

public void align_networks_from_data(AlignmentNetwork network0, AlignmentNetwork network1,
        AlignmentNetwork aligned, TaskMonitor tm) throws Exception {
    String name = network0.get_suggested_name() + "_" + network1.get_suggested_name();
    aligned.set_suggested_name(name);/*from   w  w  w  .  j av a2  s  . c o  m*/
    if (tm != null) {
        tm.setStatusMessage("aligning " + name + "...");
    }

    List<CyRow> rows = m_table.getAllRows();

    // keep track of progress
    int j = 0;
    int total = rows.size() + network0.get_node_count() + network0.get_edge_count() + network1.get_node_count()
            + network1.get_edge_count();

    // Create the bidirectional maps for lookup
    BidiMap<String, String> network0_1 = new DualHashBidiMap<>();
    for (CyRow row : rows) {
        List<String> sigs = row.getList(c_NodesSignatureSlot, String.class);
        network0_1.put(sigs.get(0), sigs.get(1));
        Util.advance_progress(tm, j, total);
    }
    NodeSignatureManager sig_mgr = new NodeSignatureManager();
    // Update the signatures with the one in the real network
    for (AlignmentNetwork.NodeIterator i = network0.NodeIterator(); i.hasNext();) {
        String real_sig = i.next();
        sig_mgr.override_with(real_sig);
        String plain_sig = the_only_element_in(sig_mgr.get_all_node_signatures());
        String val = network0_1.get(plain_sig);
        if (val != null) {
            network0_1.remove(plain_sig);
            network0_1.put(real_sig, val);
        }
    }
    for (AlignmentNetwork.NodeIterator i = network1.NodeIterator(); i.hasNext();) {
        String real_sig = i.next();
        sig_mgr.override_with(real_sig);
        String plain_sig = the_only_element_in(sig_mgr.get_all_node_signatures());
        String key = network0_1.getKey(plain_sig);
        if (key != null) {
            network0_1.removeValue(plain_sig);
            network0_1.put(key, real_sig);
        }
    }

    // Add all the data from the first network, and add belongings according to alignment data
    // Add nodes 0
    for (AlignmentNetwork.NodeIterator i = network0.NodeIterator(); i.hasNext();) {
        String sig = i.next();

        sig_mgr.override_with(sig);
        CyNode node = aligned.make_node(sig_mgr);

        if (network0_1.containsKey(sig)) {
            // This node can be aligned
            aligned.add_node_belongings(node, network0.get_network());
            aligned.add_node_belongings(node, network1.get_network());
        } else {
            // This node cannot be aligned
            aligned.add_node_belongings(node, network0.get_network());
        }
        Util.advance_progress(tm, j, total);
    }
    // Add edges 0
    for (AlignmentNetwork.EdgeIterator i = network0.EdgeIterator(); i.hasNext();) {
        AlignmentNetwork.Edge edge_sig = i.next();
        CyNode node0, node1;

        sig_mgr.override_with(edge_sig.m_e0);
        node0 = aligned.get_node_from_signature(sig_mgr);

        sig_mgr.override_with(edge_sig.m_e1);
        node1 = aligned.get_node_from_signature(sig_mgr);

        if (node0 == null || node1 == null) {
            throw new Exception(getClass() + " - Edge and node doesn't match: The pair (node0:" + edge_sig.m_e0
                    + "node1:" + edge_sig.m_e1 + ") cannot be found");
        }
        CyEdge edge = aligned.make_edge(node0, node1);
        aligned.add_edge_belongings(edge, network0.get_network());
        if (network0_1.containsKey(edge_sig.m_e0) && network0_1.containsKey(edge_sig.m_e1)) {
            // This edge can be aligned
            aligned.add_edge_belongings(edge, network1.get_network());
        }
        Util.advance_progress(tm, j, total);
    }
    // Add second network but exclude nodes and edges that are already in the first network
    // Add nodes 1
    for (AlignmentNetwork.NodeIterator i = network1.NodeIterator(); i.hasNext();) {
        String sig = i.next();
        if (!network0_1.containsValue(sig)) {
            // This node is not aligned
            sig_mgr.override_with(sig);
            CyNode node = aligned.make_node(sig_mgr);
            aligned.add_node_belongings(node, network1.get_network());
        }
        Util.advance_progress(tm, j, total);
    }
    // Add edges 1
    for (AlignmentNetwork.EdgeIterator i = network1.EdgeIterator(); i.hasNext();) {
        AlignmentNetwork.Edge edge_sig = i.next();
        CyNode node0, node1;
        if (network0_1.containsValue(edge_sig.m_e0)) {
            String translated = network0_1.getKey(edge_sig.m_e0);
            sig_mgr.override_with(translated);
            node0 = aligned.get_node_from_signature(sig_mgr);
        } else {
            sig_mgr.override_with(edge_sig.m_e0);
            node0 = aligned.get_node_from_signature(sig_mgr);
        }
        if (network0_1.containsValue(edge_sig.m_e1)) {
            String translated = network0_1.getKey(edge_sig.m_e1);
            sig_mgr.override_with(translated);
            node1 = aligned.get_node_from_signature(sig_mgr);
        } else {
            sig_mgr.override_with(edge_sig.m_e1);
            node1 = aligned.get_node_from_signature(sig_mgr);
        }
        if (node0 == null) {
            if (network0_1.containsValue(edge_sig.m_e0)) {
                //                                        throw new Exception(" - node0 not found from the g0 network: "
                //                                                            + edge_sig.m_e0 + "->" + network0_1.get(edge_sig.m_e0));
                System.out.println(getClass() + " - node0 not found from the g0 network: " + edge_sig.m_e0
                        + "->" + network0_1.get(edge_sig.m_e0));
            } else {
                //                                        throw new Exception(" - node0 not found from the g1 network: "
                //                                                            + edge_sig.m_e0);
                System.out.println(getClass() + " - node0 not found from the g1 network: " + edge_sig.m_e0);
            }
            continue;
        }
        if (node1 == null) {
            if (network0_1.containsValue(edge_sig.m_e1)) {
                //                                        throw new Exception(" - node1 not found from the g0 network: "
                //                                                            + edge_sig.m_e1 + "->" + network0_1.get(edge_sig.m_e1));
                System.out.println(getClass() + " - node1 not found from the g0 network: " + edge_sig.m_e1
                        + "->" + network0_1.get(edge_sig.m_e1));
            } else {
                //                                        throw new Exception(" - node1 not found from the g1 network: "
                //                                                            + edge_sig.m_e1);
                System.out.println(getClass() + " - node1 not found from the g1 network: " + edge_sig.m_e1);
            }
            continue;
        }
        if (!network0_1.containsValue(edge_sig.m_e0) || !network0_1.containsValue(edge_sig.m_e1)) {
            // This edge is not aligned
            CyEdge edge = aligned.make_edge(node0, node1);
            aligned.add_edge_belongings(edge, network1.get_network());
        }
        Util.advance_progress(tm, j, total);
    }
    // Finally adjust the aligned node name by adding the signature from network1
    for (AlignmentNetwork.NodeIterator i = network1.NodeIterator(); i.hasNext();) {
        String sig = i.next();
        if (network0_1.containsValue(sig)) {
            // This node is aligned but we shall change the signature
            // to reflect the relation of the aligned node
            String translated = network0_1.getKey(sig);
            sig_mgr.override_with(translated);
            CyNode node = aligned.get_node_from_signature(sig_mgr);
            if (node == null) {
                // have to skip the incorrect node.
                continue;
            }
            sig_mgr.append_with(sig);
            aligned.mutate_node_signature(node, sig_mgr);
        }
        Util.advance_progress(tm, j, total);
    }
}