List of usage examples for com.google.common.collect MultimapBuilder hashKeys
public static MultimapBuilderWithKeys<Object> hashKeys(final int expectedKeys)
From source file:com.torodb.torod.db.postgresql.meta.routines.DeleteDocuments.java
public static int execute(Configuration configuration, CollectionSchema colSchema, Multimap<DocStructure, Integer> didsByStructure, boolean justOne) { Multimap<DocStructure, Integer> didsByStructureToDelete; if (didsByStructure.isEmpty()) { return 0; }/*w w w . j a va 2s . co m*/ if (justOne) { didsByStructureToDelete = MultimapBuilder.hashKeys(1).arrayListValues(1).build(); Map.Entry<DocStructure, Integer> aEntry = didsByStructure.entries().iterator().next(); didsByStructureToDelete.put(aEntry.getKey(), aEntry.getValue()); } else { didsByStructureToDelete = didsByStructure; } try { return execute(configuration, colSchema, didsByStructureToDelete); } catch (SQLException ex) { throw new RuntimeException(ex); } }
From source file:com.torodb.torod.db.backends.meta.routines.DeleteDocuments.java
public static int execute(Configuration configuration, CollectionSchema colSchema, Multimap<DocStructure, Integer> didsByStructure, boolean justOne, @Nonnull DatabaseInterface databaseInterface) throws RetryTransactionException { Multimap<DocStructure, Integer> didsByStructureToDelete; if (didsByStructure.isEmpty()) { return 0; }//from w w w . j a v a 2 s . c om if (justOne) { didsByStructureToDelete = MultimapBuilder.hashKeys(1).arrayListValues(1).build(); Map.Entry<DocStructure, Integer> aEntry = didsByStructure.entries().iterator().next(); didsByStructureToDelete.put(aEntry.getKey(), aEntry.getValue()); } else { didsByStructureToDelete = didsByStructure; } try { return execute(configuration, colSchema, didsByStructureToDelete, databaseInterface); } catch (SQLException ex) { throw new RuntimeException(ex); } }
From source file:com.jcwhatever.nucleus.collections.observer.subscriber.SubscriberSetMultimap.java
/** * Constructor.//from w w w. j a va 2 s . c o m * * @param keySize The initial key set capacity. * @param valueSize The initial capacity of value collections. */ public SubscriberSetMultimap(int keySize, int valueSize) { _multimap = MultimapBuilder.hashKeys(keySize).hashSetValues(valueSize).build(); }
From source file:com.jcwhatever.nucleus.collections.observer.agent.AgentSetMultimap.java
/** * Constructor.//from ww w . j ava 2 s. com * * @param keySize The initial key set capacity. * @param valueSize The initial value collection capacity. */ public AgentSetMultimap(int keySize, int valueSize) { _map = MultimapBuilder.hashKeys(keySize).hashSetValues(valueSize).build(); }
From source file:com.jcwhatever.nucleus.collections.players.PlayerSetMultimap.java
/** * Constructor./* w w w . j av a 2s .c o m*/ * * @param plugin The owning plugin. */ public PlayerSetMultimap(Plugin plugin, int keySize, int valueSize) { super(plugin); _map = MultimapBuilder.hashKeys(keySize).hashSetValues(valueSize).build(); }
From source file:org.gradle.internal.fingerprint.impl.IgnoredPathCompareStrategy.java
/** * Determines changes by:/* w w w. j a v a2 s . c om*/ * * <ul> * <li>Determining which content fingerprints are only in the previous or current fingerprint collection.</li> * <li>Those only in the previous fingerprint collection are reported as removed.</li> * <li>If {@code includeAdded} is {@code true}, the files with content fingerprints which are only in the current collection are reported as added.</li> * </ul> */ @Override public boolean visitChangesSince(TaskStateChangeVisitor visitor, Map<String, FileSystemLocationFingerprint> current, Map<String, FileSystemLocationFingerprint> previous, String propertyTitle, boolean includeAdded) { ListMultimap<HashCode, FilePathWithType> unaccountedForPreviousFiles = MultimapBuilder .hashKeys(previous.size()).linkedListValues().build(); for (Map.Entry<String, FileSystemLocationFingerprint> entry : previous.entrySet()) { String absolutePath = entry.getKey(); FileSystemLocationFingerprint previousFingerprint = entry.getValue(); unaccountedForPreviousFiles.put(previousFingerprint.getNormalizedContentHash(), new FilePathWithType(absolutePath, previousFingerprint.getType())); } for (Map.Entry<String, FileSystemLocationFingerprint> entry : current.entrySet()) { String currentAbsolutePath = entry.getKey(); FileSystemLocationFingerprint currentFingerprint = entry.getValue(); HashCode normalizedContentHash = currentFingerprint.getNormalizedContentHash(); List<FilePathWithType> previousFilesForContent = unaccountedForPreviousFiles.get(normalizedContentHash); if (previousFilesForContent.isEmpty()) { if (includeAdded) { if (!visitor.visitChange( FileChange.added(currentAbsolutePath, propertyTitle, currentFingerprint.getType()))) { return false; } } } else { previousFilesForContent.remove(0); } } List<Map.Entry<HashCode, FilePathWithType>> unaccountedForPreviousEntries = Lists .newArrayList(unaccountedForPreviousFiles.entries()); Collections.sort(unaccountedForPreviousEntries, ENTRY_COMPARATOR); for (Map.Entry<HashCode, FilePathWithType> unaccountedForPreviousEntry : unaccountedForPreviousEntries) { FilePathWithType removedFile = unaccountedForPreviousEntry.getValue(); if (!visitor.visitChange( FileChange.removed(removedFile.getAbsolutePath(), propertyTitle, removedFile.getFileType()))) { return false; } } return true; }
From source file:org.gradle.internal.fingerprint.impl.NormalizedPathFingerprintCompareStrategy.java
/** * Determines changes by:// w w w. j ava 2 s . c o m * * <ul> * <li>Determining which {@link FileSystemLocationFingerprint}s are only in the previous or current fingerprint collection.</li> * <li> * For those only in the previous fingerprint collection it checks if some entry with the same normalized path is in the current collection. * If it is, file is reported as modified, if not as removed. * </li> * <li>Finally, if {@code includeAdded} is {@code true}, the remaining fingerprints which are only in the current collection are reported as added.</li> * </ul> */ @Override public boolean visitChangesSince(TaskStateChangeVisitor visitor, Map<String, FileSystemLocationFingerprint> currentFingerprints, Map<String, FileSystemLocationFingerprint> previousFingerprints, String propertyTitle, boolean includeAdded) { ListMultimap<FileSystemLocationFingerprint, FilePathWithType> unaccountedForPreviousFiles = MultimapBuilder .hashKeys(previousFingerprints.size()).linkedListValues().build(); ListMultimap<String, FilePathWithType> addedFilesByNormalizedPath = MultimapBuilder.linkedHashKeys() .linkedListValues().build(); for (Map.Entry<String, FileSystemLocationFingerprint> entry : previousFingerprints.entrySet()) { String absolutePath = entry.getKey(); FileSystemLocationFingerprint previousFingerprint = entry.getValue(); unaccountedForPreviousFiles.put(previousFingerprint, new FilePathWithType(absolutePath, previousFingerprint.getType())); } for (Map.Entry<String, FileSystemLocationFingerprint> entry : currentFingerprints.entrySet()) { String currentAbsolutePath = entry.getKey(); FileSystemLocationFingerprint currentFingerprint = entry.getValue(); List<FilePathWithType> previousFilesForFingerprint = unaccountedForPreviousFiles .get(currentFingerprint); if (previousFilesForFingerprint.isEmpty()) { addedFilesByNormalizedPath.put(currentFingerprint.getNormalizedPath(), new FilePathWithType(currentAbsolutePath, currentFingerprint.getType())); } else { previousFilesForFingerprint.remove(0); } } List<Map.Entry<FileSystemLocationFingerprint, FilePathWithType>> unaccountedForPreviousEntries = Lists .newArrayList(unaccountedForPreviousFiles.entries()); Collections.sort(unaccountedForPreviousEntries, ENTRY_COMPARATOR); for (Map.Entry<FileSystemLocationFingerprint, FilePathWithType> unaccountedForPreviousFingerprintEntry : unaccountedForPreviousEntries) { FileSystemLocationFingerprint previousFingerprint = unaccountedForPreviousFingerprintEntry.getKey(); String normalizedPath = previousFingerprint.getNormalizedPath(); List<FilePathWithType> addedFilesForNormalizedPath = addedFilesByNormalizedPath.get(normalizedPath); if (!addedFilesForNormalizedPath.isEmpty()) { // There might be multiple files with the same normalized path, here we choose one of them FilePathWithType addedFile = addedFilesForNormalizedPath.remove(0); if (!visitor.visitChange(FileChange.modified(addedFile.getAbsolutePath(), propertyTitle, previousFingerprint.getType(), addedFile.getFileType()))) { return false; } } else { FilePathWithType removedFile = unaccountedForPreviousFingerprintEntry.getValue(); if (!visitor.visitChange(FileChange.removed(removedFile.getAbsolutePath(), propertyTitle, removedFile.getFileType()))) { return false; } } } if (includeAdded) { for (FilePathWithType addedFile : addedFilesByNormalizedPath.values()) { if (!visitor.visitChange( FileChange.added(addedFile.getAbsolutePath(), propertyTitle, addedFile.getFileType()))) { return false; } } } return true; }
From source file:com.google.gerrit.server.change.RelatedChangesSorter.java
public List<PatchSetData> sort(List<ChangeData> in, PatchSet startPs) throws OrmException, IOException { checkArgument(!in.isEmpty(), "Input may not be empty"); // Map of all patch sets, keyed by commit SHA-1. Map<String, PatchSetData> byId = collectById(in); PatchSetData start = byId.get(startPs.getRevision().get()); checkArgument(start != null, "%s not found in %s", startPs, in); ProjectControl ctl = start.data().changeControl().getProjectControl(); // Map of patch set -> immediate parent. ListMultimap<PatchSetData, PatchSetData> parents = MultimapBuilder.hashKeys(in.size()).arrayListValues(3) .build();/*from w w w . jav a 2s. c om*/ // Map of patch set -> immediate children. ListMultimap<PatchSetData, PatchSetData> children = MultimapBuilder.hashKeys(in.size()).arrayListValues(3) .build(); // All other patch sets of the same change as startPs. List<PatchSetData> otherPatchSetsOfStart = new ArrayList<>(); for (ChangeData cd : in) { for (PatchSet ps : cd.patchSets()) { PatchSetData thisPsd = checkNotNull(byId.get(ps.getRevision().get())); if (cd.getId().equals(start.id()) && !ps.getId().equals(start.psId())) { otherPatchSetsOfStart.add(thisPsd); } for (RevCommit p : thisPsd.commit().getParents()) { PatchSetData parentPsd = byId.get(p.name()); if (parentPsd != null) { parents.put(thisPsd, parentPsd); children.put(parentPsd, thisPsd); } } } } Collection<PatchSetData> ancestors = walkAncestors(ctl, parents, start); List<PatchSetData> descendants = walkDescendants(ctl, children, start, otherPatchSetsOfStart, ancestors); List<PatchSetData> result = new ArrayList<>(ancestors.size() + descendants.size() - 1); result.addAll(Lists.reverse(descendants)); result.addAll(ancestors); return result; }
From source file:com.jcwhatever.nucleus.collections.MultiBiMap.java
/** * Constructor.// w w w. j a va2 s.com * * @param size The initial capacity of the map. * @param entrySize The initial capacity of the internal collections for each key. */ public MultiBiMap(int size, int entrySize) { PreCon.positiveNumber(size); PreCon.positiveNumber(entrySize); _keyToValue = MultimapBuilder.hashKeys(size).linkedHashSetValues(entrySize).build(); _valueToKey = HashMultimap.create(size, entrySize); }
From source file:com.google.gerrit.server.notedb.ChangeNotesCommit.java
public List<String> getFooterLineValues(FooterKey key) { if (footerLines == null) { List<FooterLine> src = getFooterLines(); footerLines = MultimapBuilder.hashKeys(src.size()).arrayListValues(1).build(); for (FooterLine fl : src) { footerLines.put(fl.getKey().toLowerCase(), fl.getValue()); }/*from w ww . j a v a2 s. c o m*/ } return footerLines.get(key.getName().toLowerCase()); }