List of usage examples for com.google.common.collect BiMap containsKey
boolean containsKey(Object key);
From source file:org.onosproject.provider.of.device.impl.OpenFlowDeviceValueMapper.java
/** * Looks up the specified input value to the corresponding value with the specified map. * * @param map bidirectional mapping//from w w w . jav a2s.c o m * @param input input value * @param cls class of output value * @param <I> type of input value * @param <O> type of output value * @return the corresponding value stored in the specified map */ private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) { if (!map.containsKey(input)) { throw new RuntimeException( String.format("No mapping found for %s when converting to %s", input, cls.getName())); } return map.get(input); }
From source file:org.onosproject.provider.of.message.impl.OpenFlowControlMessageMapper.java
/** * Looks up the specified input value to the corresponding value with the specified map. * * @param map bidirectional mapping//from ww w . j av a2 s .c o m * @param input input type * @param cls class of output value * @param <I> type of input value * @param <O> type of output value * @return the corresponding value stored in the specified map */ private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) { if (!map.containsKey(input)) { throw new RuntimeException( String.format("No mapping found for %s when converting to %s", input, cls.getName())); } return map.get(input); }
From source file:eu.netide.core.globalfib.flow.OpenFlowValueMapper.java
/** * Looks up the specified input value to the corresponding value with the specified map. * * @param map bidirectional mapping/*from ww w. j a va 2 s . co m*/ * @param input input value * @param cls class of output value * @param <I> type of input value * @param <O> type of output value * @return the corresponding value stored in the specified map * @throws NoMappingFoundException if no corresponding value is found */ private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) { if (!map.containsKey(input)) { throw new NoMappingFoundException(input, cls); } return map.get(input); }
From source file:gr.forth.ics.swkm.model2.diff.DiffUtils.java
static RdfNode mapNodeToAnotherModel(Resource node, Model m, BiMap<String, String> namespaceMap) { RdfNode mappedNode = null;/*from w w w. j a v a2 s .c om*/ if (namespaceMap.containsKey(node.getUri().getNamespace())) { Uri u = new Uri(namespaceMap.get(node.getUri().getNamespace()), node.getUri().getLocalName()); if (m.mapResource(u).hasTriples()) { mappedNode = m.mapResource(u); } } else if (namespaceMap.containsValue(node.getUri().getNamespace())) { Uri u = new Uri(namespaceMap.inverse().get(node.getUri().getNamespace()), node.getUri().getLocalName()); if (m.mapResource(u).hasTriples()) { mappedNode = m.mapResource(u); } } else { if (m.mapResource(node.getIdentifier()).hasTriples()) { mappedNode = m.mapResource(node.getIdentifier()); } } return mappedNode; }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.aiml.elements.root.Aiml.java
/** * Vytvo koenov prvek.// ww w. j av a 2 s . c o m * * @param content * obsah prvn rovn * @param namespacesToPrefixes * zobrazen prostor jmen na prefixy XML * @param schemaLocation * URI schmatu pro AIML * @return prvek */ public static Aiml create(final List<? extends Toplevel> content, final Map<? extends URI, ? extends String> namespacesToPrefixes, final URI schemaLocation) { Preconditions.checkNotNull(content); Preconditions.checkNotNull(namespacesToPrefixes); Preconditions.checkNotNull(schemaLocation); final List<Toplevel> contentCopy = ImmutableList.copyOf(content); final BiMap<URI, String> namespacesToPrefixesCopy = ImmutableBiMap.copyOf(namespacesToPrefixes); Preconditions.checkArgument(namespacesToPrefixesCopy.containsKey(AIML_NAMESPACE_URI)); Preconditions.checkArgument(namespacesToPrefixesCopy.containsKey(SCHEMA_NAMESPACE_URI)); return new Aiml(contentCopy, namespacesToPrefixesCopy, schemaLocation); }
From source file:de.unisb.cs.st.javalanche.mutation.results.MutationCoverageFile.java
private static BiMap<String, Integer> getAllTests(Collection<Set<String>> values) { int key = 0;/*w w w. ja va 2 s.c o m*/ BiMap<String, Integer> result = HashBiMap.create(); for (Set<String> tests : values) { for (String test : tests) { if (!result.containsKey(test)) { result.put(test, key++); } } } return result; }
From source file:de.ovgu.featureide.fm.core.constraint.analysis.Translator.java
/** * Extends the given bijective mapping by all features present in the * passed model which are not yet in the mapping. * //from www .j a va 2s . com * @param map 1-to-1 mapping of natural numbers to features. * @param fm The feature model. * @param idGen */ public static void extendFeatureNameMap(BiMap<String, Integer> m, FeatureModel fm, UniqueId idGen) { for (String f : fm.getFeatureNames()) { if (!m.containsKey(f)) { m.put(f, idGen.getNext()); } } }
From source file:com.github.jsdossier.jscomp.NodeLibrary.java
private static ExternCollection loadCollection(Iterable<Path> paths) throws IOException { Set<String> externIds = new HashSet<>(); Map<String, SourceFile> modulesByPath = new HashMap<>(); BiMap<String, String> modulePathsById = HashBiMap.create(); for (Path path : paths) { String id = toSafeName(getNameWithoutExtension(path.getFileName().toString())); if (modulePathsById.containsKey(id)) { throw new IllegalArgumentException("Duplicate extern module ID <" + id + "> (" + path + "); originally defined by " + modulePathsById.get(id)); }/* w w w .ja v a2 s.co m*/ modulePathsById.put(id, path.toString()); externIds.add(id); SourceFile source = loadSource(path, false); modulesByPath.put(source.getName(), source); modulePathsById.put(id, source.getName()); } return new ExternCollection(ImmutableSet.copyOf(externIds), ImmutableList.<SourceFile>of(), ImmutableMap.copyOf(modulesByPath), ImmutableMap.copyOf(modulePathsById.inverse())); }
From source file:com.android.tools.idea.structure.KeyValuePane.java
@NotNull private static String getMappedValue(@NotNull BiMap<String, String> map, @NotNull String value) { if (map.containsKey(value)) { value = map.get(value);//from ww w . j a v a 2 s . co m } return value; }
From source file:org.apache.druid.indexing.firehose.IngestSegmentFirehoseFactory.java
@VisibleForTesting static List<String> getUniqueMetrics(List<TimelineObjectHolder<String, DataSegment>> timelineSegments) { final BiMap<String, Integer> uniqueMetrics = HashBiMap.create(); // Here, we try to retain the order of metrics as they were specified. Metrics are extracted from the recent // segments to olders. // timelineSegments are sorted in order of interval int index = 0; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String metric : chunk.getObject().getMetrics()) { if (!uniqueMetrics.containsKey(metric)) { uniqueMetrics.put(metric, index++); }/*from ww w .j av a2 s .c o m*/ } } } final BiMap<Integer, String> orderedMetrics = uniqueMetrics.inverse(); return IntStream.range(0, orderedMetrics.size()).mapToObj(orderedMetrics::get).collect(Collectors.toList()); }