List of usage examples for com.google.common.collect SetMultimap containsKey
boolean containsKey(@Nullable Object key);
From source file:ome.services.blitz.repo.path.FilePathRestrictions.java
/** * Minimally adjust a set of rules to include transformations away from Unicode control characters. * @param rules a set of rules/*ww w . j a v a 2 s.com*/ * @return the given rules with full coverage for preventing control characters */ private static FilePathRestrictions includeControlTransformations(FilePathRestrictions rules) { final Set<Character> safeCharacters = new HashSet<Character>(rules.safeCharacters.size()); final Set<Integer> safeCodePoints = new HashSet<Integer>(rules.safeCharacters.size()); for (final Character safeCharacter : rules.safeCharacters) { final int safeCodePoint = FilePathRestrictionInstance.getCodePoint(safeCharacter); if (!controlCodePoints.contains(safeCodePoint)) { safeCharacters.add(safeCharacter); safeCodePoints.add(safeCodePoint); } } final SetMultimap<Integer, Integer> newTransformationMatrix = HashMultimap .create(Multimaps.filterValues(rules.transformationMatrix, isNotControlCodePoint)); for (final int controlCodePoint : controlCodePoints) { if (!newTransformationMatrix.containsKey(controlCodePoint)) { if (rules.transformationMatrix.containsKey(controlCodePoint)) { throw new IllegalArgumentException( "only control character mappings available for Unicode code point " + controlCodePoint); } newTransformationMatrix.putAll(controlCodePoint, safeCodePoints); } } return combineRules(rules, new FilePathRestrictions(newTransformationMatrix, null, null, null, safeCharacters)); }
From source file:com.wrmsr.wava.basic.BasicLoopInfo.java
public static Map<Name, Name> getLoopParents(SetMultimap<Name, Name> loopContents) { Map<Name, Name> loopParents = new HashMap<>(); Map<Name, Set<Name>> map = loopContents.keySet().stream() .collect(toHashMap(identity(), loop -> new HashSet<>())); for (Name cur : loopContents.keySet()) { map.get(cur).add(ENTRY_NAME);/*from www .j av a 2s.com*/ Set<Name> children = loopContents.get(cur); for (Name child : children) { if (!cur.equals(child) && loopContents.containsKey(child)) { map.get(child).add(cur); } } } Map<Name, Integer> loopDepths = map.entrySet().stream() .collect(toHashMap(entry -> entry.getKey(), entry -> entry.getValue().size())); loopDepths.put(ENTRY_NAME, 0); int maxDepth = loopDepths.values().stream().mapToInt(Integer::intValue).max().orElse(0); List<List<Name>> depthLoopsLists = IntStream.range(0, maxDepth + 1).boxed() .<List<Name>>map(i -> new ArrayList<>()).collect(toArrayList()); loopDepths.forEach((loop, depth) -> depthLoopsLists.get(depth).add(loop)); Set<Name> seen = new HashSet<>(); for (int depth = 1; depth < depthLoopsLists.size(); ++depth) { for (Name loop : depthLoopsLists.get(depth)) { Name parent = getOnlyElement(Sets.difference(map.get(loop), seen)); checkState(loopDepths.get(parent) == depth - 1); loopParents.put(loop, parent); } seen.addAll(depthLoopsLists.get(depth - 1)); } checkState(loopContents.keySet().equals(loopParents.keySet())); return loopParents; }
From source file:com.publictransitanalytics.scoregenerator.environment.StoredGrid.java
private static TreeMultimap<GeoLongitude, GridPoint> getLongitudeSortedPointsForLatitude( final GeoLatitude latitude, final SetMultimap<GeoLatitude, GridPoint> latitudePointMap) { final TreeMultimap<GeoLongitude, GridPoint> map = TreeMultimap.create(Comparator.naturalOrder(), (p1, p2) -> p1.getIdentifier().compareTo(p2.getIdentifier())); if (latitudePointMap.containsKey(latitude)) { for (final GridPoint point : latitudePointMap.get(latitude)) { map.put(point.getLocation().getLongitude(), point); }/*w ww . ja v a 2 s . com*/ } return map; }
From source file:com.publictransitanalytics.scoregenerator.environment.StoredGrid.java
private static TreeMultimap<GeoLatitude, GridPoint> getLatitudeSortedPointsForLongitude( final GeoLongitude longitude, final SetMultimap<GeoLongitude, GridPoint> longitudePointMap) { final TreeMultimap<GeoLatitude, GridPoint> map = TreeMultimap.create(Comparator.naturalOrder(), (p1, p2) -> p1.getIdentifier().compareTo(p2.getIdentifier())); if (longitudePointMap.containsKey(longitude)) { for (final GridPoint point : longitudePointMap.get(longitude)) { map.put(point.getLocation().getLatitude(), point); }//from ww w . java 2s. c o m } return map; }
From source file:org.alfresco.module.org_alfresco_module_rm.api.PublicAPITestUtil.java
/** * Check the consistency of the public API exposed from the given package. For each class in the package that is * annotated {@link AlfrescoPublicApi}, check that no exposed methods (or fields, constructors, etc.) use * non-public-API classes from Alfresco. * * @param basePackageName The package to check classes within. * @param knownBadReferences Any references that would cause this test to fail, but which we don't want to change. * The keys should be public API classes within our code and the values should be the non-public-API * class that is being referenced. */// w ww . j a va 2 s .c o m public static void testPublicAPIConsistency(String basePackageName, SetMultimap<Class<?>, Class<?>> knownBadReferences) { Reflections reflections = new Reflections(basePackageName); Set<Class<?>> publicAPIClasses = reflections.getTypesAnnotatedWith(AlfrescoPublicApi.class, true); SetMultimap<Class<?>, Class<?>> referencedFrom = HashMultimap.create(); Set<Class<?>> referencedClasses = new HashSet<>(); for (Class<?> publicAPIClass : publicAPIClasses) { Set<Class<?>> referencedClassesFromClass = getReferencedClassesFromClass(publicAPIClass, new HashSet<>()); referencedClassesFromClass.forEach(clazz -> referencedFrom.put(clazz, publicAPIClass)); // Remove any references in knownBadReferences and error if an expected reference wasn't found. if (knownBadReferences.containsKey(publicAPIClass)) { for (Class<?> clazz : knownBadReferences.get(publicAPIClass)) { assertTrue( "Supplied knownBadReferences expects " + clazz + " to be referenced by " + publicAPIClass + ", but no such error was found", referencedClassesFromClass.remove(clazz)); } } referencedClasses.addAll(referencedClassesFromClass); } List<String> errorMessages = new ArrayList<>(); for (Class<?> referencedClass : referencedClasses) { if (isInAlfresco(referencedClass) && !isPartOfPublicApi(referencedClass)) { Set<String> referencerNames = referencedFrom.get(referencedClass).stream().map(c -> c.getName()) .collect(Collectors.toSet()); errorMessages.add(referencedClass.getName() + " <- " + StringUtils.join(referencerNames, ", ")); } } if (!errorMessages.isEmpty()) { System.out.println("Errors found:"); System.out.println(StringUtils.join(errorMessages, "\n")); } assertEquals("Found references to non-public API classes from public API classes.", Collections.emptyList(), errorMessages); }
From source file:tiger.Utils.java
/** * Return null means the give key is not bound, which is an error. We cannot * return empty Set in this case because that means the binding exists and * depends on nothing./*ww w. j av a 2 s . com*/ */ @Nullable public static Set<NewDependencyInfo> getDependencyInfo( SetMultimap<NewBindingKey, NewDependencyInfo> dependencies, NewBindingKey key) { if (dependencies.containsKey(key)) { return dependencies.get(key); } else if (hasBuiltinBinding(key)) { return getDependencyInfo(dependencies, getElementKeyForBuiltinBinding(key)); } else if (isMap(key)) { // Handle the case that value is dagger built-in type. NewBindingKey peeledKey = peelMapWithBuiltinValue(key); if (peeledKey != null) { return getDependencyInfo(dependencies, peeledKey); } else { return null; } } else { NewDependencyInfo dependencyInfo = getDependencyInfoByGeneric(dependencies, key); if (dependencyInfo == null) { return null; } else { return Sets.newHashSet(dependencyInfo); } } }
From source file:com.builtbroken.icbm.client.ec.ECBiomeChange.java
private final void init() { if (!hasInit) { //Bellow ensure that missing textures do not exist try {//from w w w . j a v a2s. c o m Field field = FMLClientHandler.class.getDeclaredField("missingTextures"); field.setAccessible(true); SetMultimap<String, ResourceLocation> set = (SetMultimap<String, ResourceLocation>) field .get(FMLClientHandler.instance()); if (set.containsKey("icbm")) { Map<String, Collection<ResourceLocation>> map = set.asMap(); Collection<ResourceLocation> locations = map.get("icbm"); for (ResourceLocation location : locations) { String name = location.getResourcePath().replace("textures/items/ex.icon.", "") .replace(".png", ""); if (corner_icons.containsKey(name)) { corner_icons.remove(name); } name = location.getResourcePath().replace("textures/items/ex.biome.", "").replace(".png", ""); if (overlay_icons.containsKey(name)) { overlay_icons.remove(name); } } } } catch (Exception e) { e.printStackTrace(); } hasInit = true; } }
From source file:org.grouplens.grapht.InjectionContainer.java
private Map<Desire, Instantiator> makeDependencyMap(DAGNode<Component, Dependency> node, SetMultimap<DAGNode<Component, Dependency>, DAGEdge<Component, Dependency>> backEdges) { Set<DAGEdge<Component, Dependency>> edges = node.getOutgoingEdges(); if (backEdges.containsKey(node)) { ImmutableSet.Builder<DAGEdge<Component, Dependency>> bld = ImmutableSet.builder(); edges = bld.addAll(edges).addAll(backEdges.get(node)).build(); }//from w ww . j a v a 2s .c om ImmutableSet.Builder<Desire> desires = ImmutableSet.builder(); for (DAGEdge<Component, Dependency> edge : edges) { desires.add(edge.getLabel().getInitialDesire()); } return Maps.asMap(desires.build(), new DepLookup(edges, backEdges)); }
From source file:com.android.build.gradle.shrinker.IncrementalShrinker.java
/** * Decides which classes need to be updated on disk and which need to be deleted. It puts * appropriate entries in the lists passed as arguments. *///from w w w .j a v a2 s . c om private void chooseClassesToWrite(@NonNull Iterable<TransformInput> inputs, @NonNull TransformOutputProvider output, @NonNull Collection<T> classesToWrite, @NonNull Collection<File> classFilesToDelete, @NonNull SetMultimap<T, String> oldState) { for (T klass : mGraph.getReachableClasses(CounterSet.SHRINK)) { if (!oldState.containsKey(klass)) { classesToWrite.add(klass); } else { Set<String> newMembers = mGraph.getReachableMembersLocalNames(klass, CounterSet.SHRINK); Set<String> oldMembers = oldState.get(klass); // Reverse of the trick above, where we store one artificial member for empty // classes. if (oldMembers.size() == 1) { oldMembers.remove(mGraph.getClassName(klass)); } if (!newMembers.equals(oldMembers)) { classesToWrite.add(klass); } } oldState.removeAll(klass); } // All keys that remained in oldState should be deleted. for (T klass : oldState.keySet()) { File sourceFile = mGraph.getSourceFile(klass); checkState(sourceFile != null, "One of the inputs has no source file."); Optional<File> outputFile = chooseOutputFile(klass, sourceFile, inputs, output); if (!outputFile.isPresent()) { throw new IllegalStateException("Can't determine path of " + mGraph.getClassName(klass)); } classFilesToDelete.add(outputFile.get()); } }
From source file:org.dragoneronca.nlp.wol.graph_building.SimilarityBasedProcessor.java
private Map<Sense, Double> computeCorrectnessMap(SenseSet senseSet, SenseRelation senseRelation, SetMultimap<String, Tuple> senseReferenceContexts, SetMultimap<Sense, Tuple> senseContexts) { String senseReference = senseRelation.getSenseReference(); if (!senseReferenceContexts.containsKey(senseReference)) { List<TaggedEntry> taggedSenseReference = (senseReference != null) ? TAGGER.getTaggedTerms(senseReference) : new ArrayList<TaggedEntry>(); Set<Tuple> senseReferenceContext = getContextFromTaggedEntries(taggedSenseReference); senseReferenceContexts.putAll(senseReference, senseReferenceContext); }//ww w .j a va 2s.c om // compute correctness value for each sense of the given senseSet Map<Sense, Double> correctnessMap = new HashMap<>(); double correctnessSum = 0; for (Sense sense : senseSet.getSenses()) { Set<Tuple> senseContext = senseContexts.get(sense); Set<Tuple> senseReferenceContext = senseReferenceContexts.get(senseReference); double correctness = SIMILARITY.getSimilarity(senseContext, senseReferenceContext); correctnessSum += correctness; correctnessMap.put(sense, correctness); } // normalize correctness values if (correctnessSum == 0) { double uniformCorrectness = 1.0 / senseSet.getSenses().size(); for (Sense sense : correctnessMap.keySet()) { correctnessMap.put(sense, uniformCorrectness); } } else { Iterator<Map.Entry<Sense, Double>> entryIt = correctnessMap.entrySet().iterator(); while (entryIt.hasNext()) { Map.Entry<Sense, Double> entry = entryIt.next(); double correctness = entry.getValue(); if (correctness <= 0) { entryIt.remove(); } else { double normCorrectness = correctness / correctnessSum; correctnessMap.put(entry.getKey(), normCorrectness); } } } return correctnessMap; }