Example usage for com.google.common.collect MultimapBuilder linkedHashKeys

List of usage examples for com.google.common.collect MultimapBuilder linkedHashKeys

Introduction

In this page you can find the example usage for com.google.common.collect MultimapBuilder linkedHashKeys.

Prototype

public static MultimapBuilderWithKeys<Object> linkedHashKeys() 

Source Link

Document

Uses a LinkedHashMap to map keys to value collections.

Usage

From source file:io.github.swagger2markup.internal.utils.TagUtils.java

/**
 * Groups the operations by tag. The key of the Multimap is the tag name.
 * The value of the Multimap is a PathOperation
 *
 * @param allOperations     all operations
 * @param operationOrdering comparator for operations, for a given tag
 * @return Operations grouped by Tag/*  ww  w  .  ja  va2s.  c o  m*/
 */
public static Multimap<String, PathOperation> groupOperationsByTag(List<PathOperation> allOperations,
        Comparator<PathOperation> operationOrdering) {

    Multimap<String, PathOperation> operationsGroupedByTag;
    if (operationOrdering == null) {
        operationsGroupedByTag = LinkedHashMultimap.create();
    } else {
        operationsGroupedByTag = MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build();
    }
    for (PathOperation operation : allOperations) {
        List<String> tags = operation.getOperation().getTags();

        Validate.notEmpty(tags, "Can't GroupBy.TAGS. Operation '%s' has no tags", operation);
        for (String tag : tags) {
            if (logger.isDebugEnabled()) {
                logger.debug("Added path operation '{}' to tag '{}'", operation, tag);
            }
            operationsGroupedByTag.put(tag, operation);
        }
    }

    return operationsGroupedByTag;
}

From source file:org.gradle.internal.fingerprint.impl.NormalizedPathFingerprintCompareStrategy.java

/**
 * Determines changes by:/*from ww w. j  a va2 s. com*/
 *
 * <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.squareup.wire.java.ProfileLoader.java

/**
 * Returns a multimap whose keys are base directories and whose values are potential locations of
 * wire profile files.//  w w w . j ava2  s .co  m
 */
Multimap<Path, String> pathsToAttempt(Set<Location> protoLocations) {
    Multimap<Path, String> result = MultimapBuilder.linkedHashKeys().linkedHashSetValues().build();
    for (Location location : protoLocations) {
        pathsToAttempt(result, location);
    }
    return result;
}

From source file:com.google.template.soy.PerInputOutputFiles.java

void writeFiles(List<File> srcs, List<String> jsOuts, @Nullable String locale) {
    if (srcs.size() != jsOuts.size()) {
        throw new AssertionError(
                String.format("Expected to generate %d code chunk(s), got %d", srcs.size(), jsOuts.size()));
    }/* ww  w  .  j a  v a  2 s .  co m*/

    ListMultimap<Path, String> outputPathToJs = MultimapBuilder.linkedHashKeys().arrayListValues().build();
    for (int i = 0; i < srcs.size(); i++) {
        outputPathToJs.put(getOutputPath(srcs.get(i), locale), jsOuts.get(i));
    }
    for (Path outputPath : outputPathToJs.keySet()) {
        if (outputPath.getParent() != null) {
            outputPath.getParent().toFile().mkdirs();
        }
        try {
            // Having multiple input files map to the same output file is only possible with the
            // --outputPathFormat flag
            MoreFiles.asCharSink(outputPath, UTF_8).write(fileJoiner.join(outputPathToJs.get(outputPath)));
        } catch (IOException ioe) {
            throw new CommandLineError("Failed to write: " + outputPath + ": " + ioe.getMessage(), ioe);
        }
    }
}

From source file:org.sosy_lab.cpachecker.cpa.predicate.PredicateAbstractionGlobalRefinementStrategy.java

@Override
public void initializeGlobalRefinement() {
    checkState(newPredicates == null);/*from  w  w  w  . j a  va 2 s  . co  m*/
    // needs to be a fully deterministic data structure,
    // thus a Multimap based on a LinkedHashMap
    // (we iterate over the keys)
    newPredicates = MultimapBuilder.linkedHashKeys().arrayListValues().build();
}

From source file:com.google.errorprone.bugpatterns.FutureReturnValueIgnored.java

private static Multimap<TypeVariableSymbol, TypeInfo> getResolvedGenerics(MethodInvocationTree tree) {
    Type type = ASTHelpers.getType(tree.getMethodSelect());
    List<Type> from = new ArrayList<>();
    List<Type> to = new ArrayList<>();
    getSubst(type, from, to);//from w ww.jav  a2s  .  c o m
    Multimap<TypeVariableSymbol, TypeInfo> result = Streams
            .zip(from.stream(), to.stream(),
                    (f, t) -> new TypeInfo((TypeVariableSymbol) f.asElement(), t, tree))
            .collect(toMultimap(k -> k.sym, k -> k, MultimapBuilder.linkedHashKeys().arrayListValues()::build));
    return result;
}