List of usage examples for org.apache.commons.collections4 BidiMap put
V put(K key, V value);
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); } else {/*from w w w . j ava 2 s . c o m*/ //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 reports./* w w w .j a v a2 s. c o 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 createReports(final Parameter _parameter, final Instance _basePeriodInst, final Instance _periodInst, final BidiMap<Instance, Instance> _existing2new) throws EFapsException { final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.ReportAbstract); queryBldr.addWhereAttrEqValue(CIAccounting.ReportAbstract.PeriodLink, _basePeriodInst); final MultiPrintQuery multi = queryBldr.getPrint(); multi.addAttribute(CIAccounting.ReportAbstract.Name, CIAccounting.ReportAbstract.Description, CIAccounting.ReportAbstract.Numbering, CIAccounting.ReportAbstract.Int1); multi.execute(); while (multi.next()) { final Instance currentRepInst = multi.getCurrentInstance(); final Insert insert = new Insert(currentRepInst.getType()); insert.add(CIAccounting.ReportAbstract.Name, multi.<Object>getAttribute(CIAccounting.ReportAbstract.Name)); insert.add(CIAccounting.ReportAbstract.Description, multi.<Object>getAttribute(CIAccounting.ReportAbstract.Description)); insert.add(CIAccounting.ReportAbstract.Numbering, multi.<Object>getAttribute(CIAccounting.ReportAbstract.Numbering)); insert.add(CIAccounting.ReportAbstract.PeriodLink, _periodInst); insert.add(CIAccounting.ReportAbstract.Int1, multi.<Object>getAttribute(CIAccounting.ReportAbstract.Int1)); insert.execute(); _existing2new.put(currentRepInst, insert.getInstance()); } }
From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java
/** * Creates the cases./*from w w w . j a v a 2s. 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 createCases(final Parameter _parameter, final Instance _basePeriodInst, final Instance _periodInst, final BidiMap<Instance, Instance> _existing2new) throws EFapsException { final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.CaseAbstract); queryBldr.addWhereAttrEqValue(CIAccounting.CaseAbstract.PeriodAbstractLink, _basePeriodInst); queryBldr.addWhereAttrEqValue(CIAccounting.CaseAbstract.StatusAbstract, Status.find(CIAccounting.CaseStatus.Active)); final MultiPrintQuery multi = queryBldr.getPrint(); multi.addAttribute(CIAccounting.CaseAbstract.ArchiveConfig, CIAccounting.CaseAbstract.Description, CIAccounting.CaseAbstract.Label, CIAccounting.CaseAbstract.Name, CIAccounting.CaseAbstract.StatusAbstract, CIAccounting.CaseAbstract.SummarizeConfig); multi.execute(); while (multi.next()) { final Instance currentCaseInst = multi.getCurrentInstance(); final String name = multi.getAttribute(CIAccounting.CaseAbstract.Name); final Insert insert = new Insert(currentCaseInst.getType()); insert.add(CIAccounting.CaseAbstract.PeriodAbstractLink, _periodInst); insert.add(CIAccounting.CaseAbstract.ArchiveConfig, multi.<Object>getAttribute(CIAccounting.CaseAbstract.ArchiveConfig)); insert.add(CIAccounting.CaseAbstract.Description, multi.<Object>getAttribute(CIAccounting.CaseAbstract.Description)); insert.add(CIAccounting.CaseAbstract.Label, multi.<Object>getAttribute(CIAccounting.CaseAbstract.Label)); insert.add(CIAccounting.CaseAbstract.Name, name); insert.add(CIAccounting.CaseAbstract.StatusAbstract, multi.<Object>getAttribute(CIAccounting.CaseAbstract.StatusAbstract)); insert.add(CIAccounting.CaseAbstract.SummarizeConfig, multi.<Object>getAttribute(CIAccounting.CaseAbstract.SummarizeConfig)); insert.execute(); LOG.info("added Case {}", name); final Instance newCaseInst = insert.getInstance(); _existing2new.put(currentCaseInst, newCaseInst); createAccount2Case(_parameter, currentCaseInst, _existing2new); createReport2Case(_parameter, currentCaseInst, _existing2new); } }
From source file:org.efaps.esjp.accounting.util.PeriodCarryOver_Base.java
/** * Creates the accounts.//from ww w. j a va 2s . c o 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 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.jspresso.framework.qooxdoo.rpc.RemoteCallUtils.java
/** * Encode string.//from w ww . j a v a 2 s .co m * * @param original * the original * @return the string */ protected String encode(String original) { BidiMap<String, String> codec = CODEC.get(); String key = codec.getKey(original); if (key == null) { key = Integer.toHexString(codec.size()); codec.put(key, original); } return key; }
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 ww w. j a va 2 s.co 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); } }
From source file:uniol.apt.analysis.isomorphism.IsomorphismLogic.java
private static boolean visit(BidiMap<State, State> partialIsomorphism, Queue<Pair<State, State>> unhandled, State state1, State state2) { if (state1 == null && state2 == null) // Nothing to do return true; if (state1 == null || state2 == null) // Not isomorphic return false; State oldState1 = partialIsomorphism.getKey(state2); if (state1.equals(oldState1)) // This mapping was already known return true; if (oldState1 != null) // We have a conflicting mapping! return false; State oldState2 = partialIsomorphism.put(state1, state2); if (oldState2 != null) { // If this assert fails, then state1 was already mapped to state2 before. However, we already // checked for this case above. assert !state2.equals(oldState2); // We have a conflicting mapping! return false; }//from w w w. ja v a 2 s .co m unhandled.add(new Pair<State, State>(state1, state2)); return true; }