List of usage examples for org.apache.commons.collections4 BidiMap getKey
K getKey(Object 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);/*ww w.j a v a 2 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.common.history.AbstractUpdateHistoryTrigger_Base.java
/** * Gets the attributes./*w w w. j a v a 2 s .com*/ * * @param _parameter the _parameter * @param _instance the _instance * @return the attributes * @throws EFapsException the eFaps exception */ protected List<AttributeValue> getAttributes(final Parameter _parameter, final Instance _instance) throws EFapsException { final List<AttributeValue> ret = new ArrayList<>(); @SuppressWarnings("unchecked") final Map<Object, Object> values = (Map<Object, Object>) _parameter.get(ParameterValues.NEW_VALUES); if (values != null) { final Collection<String> always = analyseProperty(_parameter, "AlwaysAttribute").values(); final BidiMap<Integer, String> selectAttributes = new DualHashBidiMap<>( analyseProperty(_parameter, "SelectAttribute")); final BidiMap<Integer, String> phraseAttributes = new DualHashBidiMap<>( analyseProperty(_parameter, "PhraseAttribute")); final Map<Integer, String> selects = analyseProperty(_parameter, "Select"); final Map<Integer, String> phrases = analyseProperty(_parameter, "Phrase"); // ensure that their is a value for the always Attributes for (final String attrName : always) { boolean exists = false; for (final Entry<?, ?> entry : values.entrySet()) { if (((Attribute) entry.getKey()).getName().equals(attrName)) { exists = true; break; } } if (!exists) { Object value = null; // if no select or phrase is given add the value her also if (!selectAttributes.containsValue(attrName) && !phraseAttributes.containsValue(attrName)) { final PrintQuery print = new PrintQuery(_instance); print.addAttribute(attrName); print.executeWithoutAccessCheck(); value = print.getAttribute(attrName); } values.put(_instance.getType().getAttributes().get(attrName), value); } } final Collection<String> ignore = analyseProperty(_parameter, "IgnoreAttribute").values(); for (final Entry<?, ?> entry : values.entrySet()) { final Attribute attr = (Attribute) entry.getKey(); if (!attr.getAttributeType().isAlwaysUpdate() && !attr.getAttributeType().isCreateUpdate() && !ignore.contains(attr.getName())) { final AttributeValue attrValue = new AttributeValue(); attrValue.setName(attr.getName()); if (attr.getAttributeType().getDbAttrType() instanceof PasswordType) { attrValue.setValue("****************"); } else if (attr.getAttributeType().getDbAttrType() instanceof StatusType) { final Object objArr = entry.getValue(); if (objArr instanceof Object[]) { final Object obj = ((Object[]) objArr)[0]; final Long id; if (obj instanceof String) { id = Long.valueOf((String) obj); } else { id = (Long) obj; } attrValue.setValue(Status.get(id).getKey()); } } else if (attr.getAttributeType().getDbAttrType() instanceof BitEnumType) { final Object objArr = entry.getValue(); if (objArr instanceof Object[]) { final Object val = attr.getAttributeType().getDbAttrType().readValue(attr, Arrays.asList((Object[]) objArr)); if (val == null) { attrValue.setValue(val); } else { final StringBuilder strBldr = new StringBuilder(); boolean first = true; for (final Object obj : (List<?>) val) { if (first) { first = false; } else { strBldr.append(", "); } if (obj instanceof List) { strBldr.append(((List<?>) obj).get(0)); } else { strBldr.append(obj); } } attrValue.setValue(strBldr.toString()); } } } else if (attr.getAttributeType().getDbAttrType() instanceof EnumType) { final Object objArr = entry.getValue(); if (objArr instanceof Object[]) { final Object val = attr.getAttributeType().getDbAttrType().readValue(attr, Arrays.asList((Object[]) objArr)); if (val == null) { attrValue.setValue(val); } else { attrValue.setValue(val.toString()); } } } else { // check is a select exists if (selectAttributes.containsValue(attr.getName())) { final String select = selects.get(selectAttributes.getKey(attr.getName())); final PrintQuery print = new PrintQuery(_instance); print.addSelect(select); print.executeWithoutAccessCheck(); attrValue.setValue(print.getSelect(select)); } else if (phraseAttributes.containsValue(attr.getName())) { final String phrase = phrases.get(phraseAttributes.getKey(attr.getName())); final PrintQuery print = new PrintQuery(_instance); print.addPhrase("SelectPhrase", phrase); print.executeWithoutAccessCheck(); attrValue.setValue(print.getPhrase("SelectPhrase")); } else { final Object obj = entry.getValue(); if (obj instanceof Object[]) { final Object tmpObj = ((Object[]) obj)[0]; if (tmpObj instanceof DateTime) { attrValue.setValue(((DateTime) tmpObj).toString()); } else { attrValue.setValue(tmpObj); } } else { attrValue.setValue(obj); } } } ret.add(attrValue); } } } return ret; }
From source file:org.jspresso.framework.qooxdoo.rpc.RemoteCallUtils.java
/** * Encode string./*from w ww .j a v a 2 s. c o 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 w ww . java 2 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); } }
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; }/* w w w .j a v a 2 s . c o m*/ unhandled.add(new Pair<State, State>(state1, state2)); return true; }