List of usage examples for com.google.common.collect BiMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.opennaas.extensions.genericnetwork.actionsets.internal.portstatistics.actions.GetPortStatisticsAction.java
protected static SwitchPortStatistics generateSwitchPortStatistics( Map<String, SwitchPortStatistics> switchesStatistics, BiMap<String, DevicePortId> networkDevicePortIdsMap) throws Exception { Map<String, PortStatistics> stats = new HashMap<String, PortStatistics>(); // extract own network port IDs and associate obtained PortStatistics for (Entry<String, DevicePortId> entry : networkDevicePortIdsMap.entrySet()) { // get underlying network element and port IDs String networkElementId = entry.getValue().getDeviceId(); String networkElementPortId = entry.getValue().getDevicePortId(); // check existence of statistics for element and port if (!switchesStatistics.containsKey(networkElementId) || switchesStatistics.get(networkElementId).getStatistics() == null || !switchesStatistics.get(networkElementId).getStatistics().containsKey(entry.getKey())) { throw new Exception("Could not find statistics for network element with ID = " + networkElementId + " and port ID = " + networkElementPortId + "!"); }// w w w. j ava 2s. c o m // get PortStatistics and associate it to own network port ID PortStatistics portStatistics = switchesStatistics.get(networkElementId).getStatistics() .get(entry.getKey()); stats.put(entry.getKey(), portStatistics); } // generate SwitchPortStatistics from stats SwitchPortStatistics switchPortStatistics = new SwitchPortStatistics(); switchPortStatistics.setStatistics(stats); return switchPortStatistics; }
From source file:uk.ac.ebi.mdk.tool.domain.TransportReactionUtil.java
private static <T> Classification getClassification( BiMap<CompartmentalisedParticipant<T, ?, Compartment>, CompartmentalisedParticipant<T, ?, Compartment>> mappings) { int total = 0; Set<Integer> movement = new HashSet<Integer>(); for (Entry<CompartmentalisedParticipant<T, ?, Compartment>, CompartmentalisedParticipant<T, ?, Compartment>> entry : mappings .entrySet()) {/*from w w w . j a v a 2 s.c o m*/ CompartmentalisedParticipant<?, ?, Compartment> p1 = entry.getKey(); CompartmentalisedParticipant<?, ?, Compartment> p2 = entry.getValue(); Compartment c1 = (Compartment) p1.getCompartment(); Compartment c2 = (Compartment) p2.getCompartment(); int value = c1.getRanking() > c2.getRanking() ? -1 : c1.getRanking() < c2.getRanking() ? +1 : 0; if (value != 0) { movement.add(value); total++; } } if (total == 1) { return Classification.UNIPORTER; } if (total > 1 && movement.size() > 1) { return Classification.ANTIPORTER; } if (total > 1 && movement.size() == 1) { return Classification.SYMPORTER; } return Classification.UNKNOWN; }
From source file:de.unijena.bioinf.FragmentationTreeConstruction.computation.tree.ilp.AbstractSolver.java
/** * Check, whether or not the given tree 'tree' is the optimal solution for the optimal colorful * subtree problem of the given graph 'graph' * @param tree/*from w w w .j a v a 2 s .c om*/ * @param graph * @return */ protected static boolean isComputationCorrect(FTree tree, FGraph graph, double score) { final BiMap<Fragment, Fragment> fragmentMap = FTree.createFragmentMapping(tree, graph); final Fragment pseudoRoot = graph.getRoot(); for (Map.Entry<Fragment, Fragment> e : fragmentMap.entrySet()) { final Fragment t = e.getKey(); final Fragment g = e.getValue(); if (g.getParent() == pseudoRoot) { score -= g.getIncomingEdge().getWeight(); } else { final Loss in = e.getKey().getIncomingEdge(); for (int k = 0; k < g.getInDegree(); ++k) if (in.getSource().getFormula().equals(g.getIncomingEdge(k).getSource().getFormula())) { score -= g.getIncomingEdge(k).getWeight(); } } } return Math.abs(score) < 1e-9d; }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
public static GraphMatching createBasicNodeMatching(final Graph g1, final Graph g2, BiMap<Integer, Integer> nodeMatch) { final BiMap<Integer, Integer> copyNodeMatch = ImmutableBiMap.copyOf(nodeMatch); // transform Map.Entry to Pair instances final ImmutableSet<Pair<Integer>> matchedNode = ImmutableSet.copyOf(copyNodeMatch.entrySet().stream() .map((arg) -> Pair.makePair(arg.getKey(), arg.getValue())).collect(toSet())); return new GraphMatching() { @Override//from w w w.j a va2 s .c om public Graph getGraph1() { return g1; } @Override public Graph getGraph2() { return g2; } @Override public int getMatchedNodeInGraph2(int g1NodeID) { if (copyNodeMatch.containsKey(g1NodeID)) return copyNodeMatch.get(g1NodeID); return -1; } @Override public int getMatchedNodeInGraph1(int g2NodeID) { if (copyNodeMatch.inverse().containsKey(g2NodeID)) return copyNodeMatch.inverse().get(g2NodeID); return -1; } @Override public Set<Pair<Integer>> getAllNodeMatches() { return matchedNode; } @Override public int getMatchedEdgeInGraph2(int g1NodeID) { return -1; } @Override public int getMatchedEdgeInGraph1(int g2NodeID) { return -1; } @Override public Set<Pair<Integer>> getAllEdgeMatches() { return Sets.newHashSet(); } }; }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
public static GraphMatching includeEdgeMatching(final GraphMatching nodeMatching, BiMap<Integer, Integer> edgeMatch) { final BiMap<Integer, Integer> copyEdgeMatch = ImmutableBiMap.copyOf(edgeMatch); // transform Map.Entry to Pair instances final ImmutableSet<Pair<Integer>> matchedEdges = ImmutableSet.copyOf(edgeMatch.entrySet().stream() .map((arg) -> Pair.makePair(arg.getKey(), arg.getValue())).collect(toSet())); return new GraphMatching() { @Override// w w w .j a v a 2 s. com public Graph getGraph1() { return nodeMatching.getGraph1(); } @Override public Graph getGraph2() { return nodeMatching.getGraph2(); } @Override public int getMatchedNodeInGraph2(int g1NodeID) { return nodeMatching.getMatchedNodeInGraph2(g1NodeID); } @Override public int getMatchedNodeInGraph1(int g2NodeID) { return nodeMatching.getMatchedNodeInGraph1(g2NodeID); } @Override public Set<Pair<Integer>> getAllNodeMatches() { return nodeMatching.getAllNodeMatches(); } @Override public int getMatchedEdgeInGraph2(int g1NodeID) { if (copyEdgeMatch.containsKey(g1NodeID)) return copyEdgeMatch.get(g1NodeID); return -1; } @Override public int getMatchedEdgeInGraph1(int g2NodeID) { if (copyEdgeMatch.inverse().containsKey(g2NodeID)) return copyEdgeMatch.inverse().get(g2NodeID); return -1; } @Override public Set<Pair<Integer>> getAllEdgeMatches() { return matchedEdges; } }; }
From source file:com.torodb.torod.db.postgresql.query.QueryStructureFilter.java
public static Multimap<Integer, QueryCriteria> filterStructures(StructuresCache cache, QueryCriteria queryCriteria) throws UndecidableCaseException { Processor.Result processorResult = PROCESSOR.process(queryCriteria); List<ProcessedQueryCriteria> processedQueryCriterias = processorResult.getProcessedQueryCriterias(); ExistRelation existRelation = processorResult.getExistRelation(); BiMap<Integer, DocStructure> allStructures = cache.getAllStructures(); Multimap<Integer, QueryCriteria> result = HashMultimap.create(allStructures.size(), processedQueryCriterias.size()); StructureQueryEvaluator structureQueryEvaluator = new StructureQueryEvaluator(); for (ProcessedQueryCriteria processedQueryCriteria : processedQueryCriterias) { for (Map.Entry<Integer, DocStructure> entry : allStructures.entrySet()) { if (structureConforms(structureQueryEvaluator, entry.getValue(), processedQueryCriteria.getStructureQuery())) { QueryCriteria dataQuery = getDataQuery(processedQueryCriteria, structureQueryEvaluator.getCandidateProvider(), existRelation); result.put(entry.getKey(), dataQuery); LOGGER.debug("Structure {} fulfil structure query {}. Data query: {}", entry.getKey(), processedQueryCriteria.getStructureQuery(), dataQuery); }//w w w.j a v a2 s. c o m } } return result; }
From source file:cuchaz.enigma.convert.MappingsConverter.java
public static void convertMappings(Mappings mappings, BiMap<ClassEntry, ClassEntry> changes) { // sort the changes so classes are renamed in the correct order // ie. if we have the mappings a->b, b->c, we have to apply b->c before a->b LinkedHashMap<ClassEntry, ClassEntry> sortedChanges = Maps.newLinkedHashMap(); int numChangesLeft = changes.size(); while (!changes.isEmpty()) { Iterator<Map.Entry<ClassEntry, ClassEntry>> iter = changes.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<ClassEntry, ClassEntry> change = iter.next(); if (changes.containsKey(change.getValue())) { sortedChanges.put(change.getKey(), change.getValue()); iter.remove();//from w ww . jav a2 s .co m } } // did we remove any changes? if (numChangesLeft - changes.size() > 0) { // keep going numChangesLeft = changes.size(); } else { // can't sort anymore. There must be a loop break; } } if (!changes.isEmpty()) { throw new Error("Unable to sort class changes! There must be a cycle."); } // convert the mappings in the correct class order for (Map.Entry<ClassEntry, ClassEntry> entry : sortedChanges.entrySet()) { mappings.renameObfClass(entry.getKey().getName(), entry.getValue().getName()); } }
From source file:org.joda.beans.ser.GuavaSerIteratorFactory.java
/** * Gets an iterator wrapper for {@code BiMap}. * // www. ja v a 2s . co m * @param map the collection, not null * @param declaredType the declared type, not null * @param keyType the value type, not null * @param valueType the value type, not null * @param valueTypeTypes the generic parameters of the value type * @return the iterator, not null */ @SuppressWarnings("rawtypes") public static final SerIterator biMap(final BiMap<?, ?> map, final Class<?> declaredType, final Class<?> keyType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) { return new SerIterator() { private final Iterator it = map.entrySet().iterator(); private Entry current; @Override public String metaTypeName() { return "BiMap"; } @Override public boolean metaTypeRequired() { // hack around Guava annoyance by assuming that size 0 and 1 ImmutableBiMap // was actually meant to be an ImmutableMap if ((declaredType == Map.class || declaredType == ImmutableMap.class) && map.size() < 2) { return false; } return BiMap.class.isAssignableFrom(declaredType) == false; } @Override public SerCategory category() { return SerCategory.MAP; } @Override public int size() { return map.size(); } @Override public boolean hasNext() { return it.hasNext(); } @Override public void next() { current = (Entry) it.next(); } @Override public Class<?> keyType() { return keyType; } @Override public Object key() { return current.getKey(); } @Override public Class<?> valueType() { return valueType; } @Override public List<Class<?>> valueTypeTypes() { return valueTypeTypes; } @Override public Object value() { return current.getValue(); } }; }
From source file:com.jxt.web.scatter.ScatterAgentMetaData.java
public Set<Map.Entry<Integer, DotAgentInfo>> entrySet() { BiMap<Integer, DotAgentInfo> inverse = metaData.inverse(); return inverse.entrySet(); }
From source file:buildcraft.transport.network.PacketGateExpansionMap.java
@Override public void writeData(ByteBuf data) { BiMap<Byte, String> map = GateExpansions.getServerMap(); data.writeByte(map.size());//from ww w. j a v a2 s . com for (Map.Entry<Byte, String> entry : map.entrySet()) { data.writeByte(entry.getKey()); Utils.writeUTF(data, entry.getValue()); } }