List of usage examples for com.google.common.collect Multimaps invertFrom
public static <K, V, M extends Multimap<K, V>> M invertFrom(Multimap<? extends V, ? extends K> source, M dest)
From source file:sorcer.boot.util.ClassPathVerifier.java
public void verifyClassPaths(ClassLoader cl) { Multimap<ClassLoader, String> classPaths = HashMultimap.create(); for (ClassLoader classLoader : getClassLoaderTree(cl)) { classPaths.get(classLoader).addAll(getClassPath(classLoader)); }/* w ww . j a v a2 s . co m*/ HashMultimap<String, ClassLoader> dest = HashMultimap.create(); Multimap<String, ClassLoader> classLoaders = Multimaps.invertFrom(classPaths, dest); for (String key : classLoaders.keySet()) { // don't check bootstrap classpath if (SorcerEnv.getRepoDir() == null || !key.contains(SorcerEnv.getRepoDir())) continue; if (classLoaders.get(key).size() > 1) { StringBuilder msg = new StringBuilder(key).append(" is loaded by multiple class loaders:\n"); for (ClassLoader kcl : classLoaders.get(key)) { msg.append("\t").append(kcl).append("\n"); } log.info("{}", msg); } } }
From source file:org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersState.java
public void configure(List<String> containers, Multimap<String, URI> container2Uris) { this.containers = containers; this.container2URIs = HashMultimap.create(container2Uris); this.uri2container = Multimaps.invertFrom(HashMultimap.create(container2Uris), HashMultimap.<URI, String>create()); }
From source file:org.eclipse.osee.define.report.internal.TraceAccumulator.java
public void extractTraces(File root) throws IOException { if (root == null || root.getParentFile() == null) { throw new OseeArgumentException("The path [%s] is invalid.", root); }//from w w w .ja va2 s .c om checkDirectory(root); if (root.isFile()) { for (String path : Lib.readListFromFile(root, true)) { traceFile(new File(path)); } } else if (root.isDirectory()) { traceFile(root); } else { throw new OseeArgumentException("Invalid directory path [%s]", root.getCanonicalPath()); } fileToTraceMarks = Multimaps.invertFrom(traceMarkToFiles, HashMultimap.<String, CaseInsensitiveString>create()); }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericOverallPositionData.java
@Override protected LinkedListMultimap<Integer, Pilot> calculateOverallPositionsWithOrder() { // Invert race points with ordered lists of pilots Comparator<Pilot> racePlacings = new PilotRacePlacingComparator<T>(scores, placingMethod); Comparator<Pilot> fallbackOrdering = new PilotRaceNumberComparator(); TreeMultimap<Integer, Pilot> invOverallPoints = TreeMultimap.create(Ordering.natural(), Ordering.from(racePlacings).compound(fallbackOrdering)); Multimaps.invertFrom(Multimaps.forMap(scores.getOverallPoints()), invOverallPoints); // Calculate overall positions LinkedListMultimap<Integer, Pilot> overallPositions = LinkedListMultimap.create(); List<Pilot> collectedPilots = new ArrayList<Pilot>(scores.getPilots().size()); LinkedList<SortedSet<Pilot>> pilotPointsOrdering = new LinkedList<SortedSet<Pilot>>(); int position = 1; if (allSimulatedToEnd) { final Map<Pilot, ? extends Set<Race>> simulatedPilotPoints = scores.getSimulatedPilotPoints(); Predicate<Pilot> allSimulatedPilot = new Predicate<Pilot>() { private final int raceCount = scores.getRaces().size(); @Override//from w ww .j av a2s . c o m public boolean apply(Pilot input) { return simulatedPilotPoints.get(input).size() == raceCount; } }; for (Integer points : invOverallPoints.keySet()) { SortedSet<Pilot> pilots = Sets.filter(invOverallPoints.get(points), Predicates.not(allSimulatedPilot)); if (!pilots.isEmpty()) { pilotPointsOrdering.add(pilots); } } for (Integer points : invOverallPoints.keySet()) { SortedSet<Pilot> pilots = Sets.filter(invOverallPoints.get(points), allSimulatedPilot); if (!pilots.isEmpty()) { pilotPointsOrdering.add(pilots); } } } else { for (Integer points : invOverallPoints.keySet()) { pilotPointsOrdering.add(invOverallPoints.get(points)); } } for (SortedSet<Pilot> pilots : pilotPointsOrdering) { switch (equalPositioning) { case ALWAYS: // Always put pilots with the same points in the same position overallPositions.putAll(position, pilots); position += pilots.size(); break; case IF_REQUIRED: // Try to put pilots with the same points in separate positions PeekingIterator<Pilot> it = Iterators.peekingIterator(pilots.iterator()); while (it.hasNext()) { Pilot pilot = it.next(); collectedPilots.add(pilot); // If this pilot compares equally with the next pilot, add them too while (it.hasNext() && racePlacings.compare(it.peek(), pilot) == 0) { collectedPilots.add(it.next()); } // Sort them by an arbitrary order Collections.sort(collectedPilots, fallbackOrdering); // Add them all to this position overallPositions.putAll(position, collectedPilots); position += collectedPilots.size(); collectedPilots.clear(); } break; } } return overallPositions; }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericRacePositionsData.java
@Override protected LinkedListMultimap<Integer, Pilot> calculateRacePositionsWithOrder(Race race) { // Create a lap order list containing all pilots List<Pilot> lapOrder = new ArrayList<Pilot>(scores.getPilots().size()); lapOrder.addAll(scores.getLapOrder(race)); Set<Pilot> pilotsWithLaps = ImmutableSet.copyOf(lapOrder); SortedSet<Pilot> pilotsWithoutLaps = new TreeSet<Pilot>(new PilotRaceNumberComparator()); pilotsWithoutLaps.addAll(Sets.difference(scores.getPilots(), pilotsWithLaps)); lapOrder.addAll(pilotsWithoutLaps);/*w w w . j a v a 2s . c o m*/ // Add penalties to race points Map<Pilot, Integer> racePoints = scores.getRacePoints(race); Map<Pilot, Integer> racePenalties = scores.getRacePenalties(race); Map<Pilot, Integer> racePointsWithPenalties = new HashMap<Pilot, Integer>(scores.getPilots().size() * 2); for (Pilot pilot : scores.getPilots()) { racePointsWithPenalties.put(pilot, racePoints.get(pilot) + racePenalties.get(pilot)); } // Invert race points with ordered lists of pilots TreeMultimap<Integer, Pilot> invRacePoints = TreeMultimap.create(Ordering.natural(), Ordering.explicit(lapOrder)); Multimaps.invertFrom(Multimaps.forMap(racePointsWithPenalties), invRacePoints); // Calculate race positions LinkedListMultimap<Integer, Pilot> racePositions = LinkedListMultimap.create(); LinkedList<SortedSet<Pilot>> pilotPointsOrdering = new LinkedList<SortedSet<Pilot>>(); int position = 1; if (simulatedToEnd) { Set<Pilot> simulatedRacePoints = scores.getSimulatedRacePoints(race); for (Integer points : invRacePoints.keySet()) { SortedSet<Pilot> pilots = Sets.filter(invRacePoints.get(points), Predicates.not(Predicates.in(simulatedRacePoints))); if (!pilots.isEmpty()) { pilotPointsOrdering.add(pilots); } } for (Integer points : invRacePoints.keySet()) { SortedSet<Pilot> pilots = Sets.filter(invRacePoints.get(points), Predicates.in(simulatedRacePoints)); if (!pilots.isEmpty()) { pilotPointsOrdering.add(pilots); } } } else { for (Integer points : invRacePoints.keySet()) { pilotPointsOrdering.add(invRacePoints.get(points)); } } for (SortedSet<Pilot> pilots : pilotPointsOrdering) { switch (equalPositioning) { case ALWAYS: // Always put pilots with the same points in the same position racePositions.putAll(position, pilots); position += pilots.size(); break; case WITHOUT_LAPS: // Add everyone with laps (by removing pilots without laps from the set) in separate positions for (Pilot pilot : Sets.difference(pilots, pilotsWithoutLaps)) { racePositions.put(position, pilot); position++; } // Add everyone without laps (by removing pilots with laps from the set) in the same position Set<Pilot> pilots2 = Sets.difference(pilots, pilotsWithLaps); racePositions.putAll(position, pilots2); position += pilots2.size(); break; case NEVER: // Always put pilots with the same points in separate positions for (Pilot pilot : pilots) { racePositions.put(position, pilot); position++; } break; } } return racePositions; }
From source file:com.google.devrel.gmscore.tools.apk.arsc.ArscBlamer.java
/** Generates blame mappings. */ public void blame() { Multimap<ResourceEntry, TypeChunk.Entry> entries = getResourceEntries(); for (Entry<ResourceEntry, Collection<TypeChunk.Entry>> entry : entries.asMap().entrySet()) { ResourceEntry resourceEntry = entry.getKey(); PackageChunk packageChunk = Preconditions .checkNotNull(resourceTable.getPackage(resourceEntry.packageName())); int keyCount = packageChunk.getKeyStringPool().getStringCount(); int typeCount = packageChunk.getTypeStringPool().getStringCount(); for (TypeChunk.Entry chunkEntry : entry.getValue()) { blameKeyOrType(keyToBlame, packageChunk, chunkEntry.keyIndex(), resourceEntry, keyCount); blameKeyOrType(typeToBlame, packageChunk, chunkEntry.parent().getId() - 1, resourceEntry, typeCount);/* w w w. j av a 2s . c o m*/ blameFromTypeChunkEntry(chunkEntry); } blamePackage(packageChunk, resourceEntry); } Multimaps.invertFrom(entries, typeEntryToBlame); for (TypeChunk.Entry entry : typeEntryToBlame.keySet()) { blameFromTypeChunkEntry(entry); } }
From source file:org.apache.storm.streams.Node.java
Set<Node> getParents(String stream) { Multimap<String, Node> rev = Multimaps.invertFrom(parentStreams, ArrayListMultimap.<String, Node>create()); return new HashSet<>(rev.get(stream)); }
From source file:de.fau.osr.core.db.DataSource.java
/** * get requirement id by commit id// w w w . ja va 2 s .c o m * @param commitId commit id to search for * @return all requirements that are related to the {@code commitId} * @throws IOException */ public Set<String> getReqRelationByCommit(String commitId) throws IOException { SetMultimap<String, String> relations = getAllReqCommitRelations(); SetMultimap<String, String> relationsComReq = HashMultimap.create(); Multimaps.invertFrom(relations, relationsComReq); return relationsComReq.get(commitId); }
From source file:org.apache.isis.core.runtime.services.publish.PublishedObjectsDefault.java
private static <T, S> Map<T, Collection<S>> invert(final Map<S, T> valueByKey) { return new TreeMap<>( Multimaps.invertFrom(Multimaps.forMap(valueByKey), ArrayListMultimap.<T, S>create()).asMap()); }
From source file:google.registry.tools.GetSchemaTreeCommand.java
@Override public void run() throws Exception { // Get the @Parent type for each class. Map<Class<?>, Class<?>> entityToParentType = new HashMap<>(); for (Class<?> clazz : ALL_CLASSES) { entityToParentType.put(clazz, getParentType(clazz)); }//from w w w .j av a 2 s . c o m // Find super types like EppResource that are used as parents in place of actual entity types. Set<Class<?>> superclasses = new HashSet<>(); for (Class<?> clazz : ALL_CLASSES) { Class<?> parentType = entityToParentType.get(clazz); if (!ALL_CLASSES.contains(parentType) && !Object.class.equals(parentType)) { superclasses.add(parentType); } } // Find the subclasses for each superclass we just found, and map them to their superclasses. Map<Class<?>, Class<?>> subclassToSuperclass = new HashMap<>(); for (Class<?> clazz : ALL_CLASSES) { for (Class<?> superclass : superclasses) { if (superclass.isAssignableFrom(clazz)) { subclassToSuperclass.put(clazz, superclass); break; } } } // Map @EntitySubclass classes to their superclasses. for (Class<?> clazz : ALL_CLASSES) { if (clazz.isAnnotationPresent(EntitySubclass.class)) { Class<?> entityClass = clazz; while (!entityClass.isAnnotationPresent(Entity.class)) { entityClass = entityClass.getSuperclass(); } if (subclassToSuperclass.containsKey(clazz)) { subclassToSuperclass.put(entityClass, subclassToSuperclass.get(clazz)); } subclassToSuperclass.put(clazz, entityClass); } } // Build the parentage hierarchy, replacing subclasses with superclasses wherever possible. for (Class<?> clazz : ALL_CLASSES) { Class<?> superclass = clazz; while (subclassToSuperclass.containsKey(superclass)) { superclass = subclassToSuperclass.get(superclass); } hierarchy.put(entityToParentType.get(clazz), superclass == null ? clazz : superclass); } // Build up the superclass to subclass mapping. superclassToSubclasses = Multimaps.invertFrom(Multimaps.forMap(subclassToSuperclass), TreeMultimap.<Class<?>, Class<?>>create(arbitrary(), new PrintableNameOrdering())); printTree(Object.class, 0); }