Example usage for com.google.common.collect Multimaps newListMultimap

List of usage examples for com.google.common.collect Multimaps newListMultimap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps newListMultimap.

Prototype

public static <K, V> ListMultimap<K, V> newListMultimap(Map<K, Collection<V>> map,
        final Supplier<? extends List<V>> factory) 

Source Link

Document

Creates a new ListMultimap that uses the provided map and factory.

Usage

From source file:org.eclipse.osee.orcs.core.internal.search.ArtifactMatchDataHandler.java

private static <K, V> ListMultimap<K, V> newLinkedHashListMultimap() {
    Map<K, Collection<V>> map = new LinkedHashMap<K, Collection<V>>();
    return Multimaps.newListMultimap(map, new Supplier<List<V>>() {
        @Override//from  ww  w.j  av  a  2  s .c  o  m
        public List<V> get() {
            return Lists.newArrayList();
        }
    });
}

From source file:io.janusproject.kernel.services.jdk.distributeddata.StandardDistributedDataStructureService.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from w w  w  . j av  a  2s .  co m*/
public <K, V> DMultiMap<K, V> getMultiMap(String name, Comparator<? super K> comparator) {
    Map map;
    if (comparator == null) {
        map = Maps.newTreeMap();
    } else {
        map = Maps.newTreeMap(comparator);
    }
    Multimap<K, V> multimap = Multimaps.newListMultimap(map, new ArrayListSupplier<V>());
    return new DMultiMapView<>(name, multimap);
}

From source file:org.jenkinsci.plugins.tokenmacro.Tokenizer.java

boolean find() {
    if (tokenMatcher.find()) {
        tokenName = tokenMatcher.group(2);
        if (tokenName == null) {
            tokenName = tokenMatcher.group(4);
        }/*from   ww w.  j  a v  a  2 s  .  c om*/
        args = Multimaps.newListMultimap(new TreeMap<String, Collection<String>>(),
                new Supplier<List<String>>() {
                    public List<String> get() {
                        return new ArrayList<String>();
                    }
                });
        if (tokenMatcher.group(5) != null) {
            parseArgs(tokenMatcher.group(5), args);
        }
        return true;
    } else {
        return false;
    }
}

From source file:com.android.tools.idea.editors.theme.attributes.AttributesGrouper.java

@NotNull
private static List<TableLabel> generateLabelsForGroup(final List<EditedStyleItem> source,
        final List<EditedStyleItem> sink) {
    // A TreeMap is used to ensure the keys are sorted in alphabetical order
    // ArrayLists are used for values to ensure that they stay in the same order they came in
    Multimap<String, EditedStyleItem> classes = Multimaps.newListMultimap(
            new TreeMap<String, Collection<EditedStyleItem>>(), new Supplier<List<EditedStyleItem>>() {
                @Override//from  w  w  w.j a v a2s  .  c  o m
                public List<EditedStyleItem> get() {
                    return new ArrayList<EditedStyleItem>();
                }
            });
    for (EditedStyleItem item : source) {
        String group = item.getAttrGroup();
        classes.put(group, item);
    }

    final List<TableLabel> labels = new ArrayList<TableLabel>();
    int offset = 0;
    sink.clear();
    for (String group : classes.keySet()) {
        final int size = classes.get(group).size();
        sink.addAll(classes.get(group));
        if (size != 0) {
            labels.add(new TableLabel(group, offset));
        }
        offset += size;
    }
    return labels;
}

From source file:net.bobah.mail.Dupes.java

@Override
public void run() {
    final Multimap<HashCode, File> dupes = Multimaps.newListMultimap(new HashMap<HashCode, Collection<File>>(),
            new Supplier<List<File>>() {
                @Override/*from w  ww . ja  v  a  2s  . c  om*/
                public List<File> get() {
                    return new LinkedList<File>();
                }
            });

    for (final File dir : dirs) {
        if (!dir.isDirectory()) {
            log.warn("{} does not exist or is not a directory, ignored", dir);
        }

        final Collection<File> files = findFiles(dir, "");
        log.info("found {} files in {}, submitting to analyzer", files.size(), dir.getAbsolutePath());

        for (final File file : files) {
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    final ExecutionContext cxt = Dupes.this.cxt.get();

                    ReadableByteChannel ch = null;
                    try {
                        cxt.sw.start();
                        // map file, take just 1 meg of data to cxt.hash and calc the function
                        // final HashCode code = Files.hash(file, hashfunc);
                        ch = Channels.newChannel(new FileInputStream(file));
                        ByteBuffer buf = ByteBuffer.wrap(cxt.buf);
                        final int len = ch.read(buf);
                        if (len == 0)
                            return;

                        final HashCode code = hashfunc.hashBytes(cxt.buf, 0, Ints.checkedCast(len));
                        synchronized (dupes) {
                            dupes.put(code, file);
                        }

                        cxt.sw.stop();
                        log.debug("{} -> {} ({}) - {} us", file, code,
                                DateFormat.getInstance().format(file.lastModified()),
                                cxt.sw.elapsed(TimeUnit.MILLISECONDS));
                    } catch (Exception e) {
                        log.debug("exception", e);
                    } finally {
                        cxt.recycle();
                        if (ch != null)
                            try {
                                ch.close();
                            } catch (IOException unused) {
                            }
                        ;
                    }
                }
            });
        }
        log.info("done submitting {} to analyzer", dir.getAbsolutePath());
    }

    try {
        shutdownExecutor(executor, log);
    } catch (InterruptedException e) {
        log.debug("exception", e);
    }

    for (Collection<File> filez : dupes.asMap().values()) {
        if (filez.size() == 1)
            continue;
        log.info("dupes found: {}", filez);
    }
}

From source file:org.eclipse.viatra.query.tooling.ui.queryexplorer.util.QueryExplorerPatternRegistry.java

protected QueryExplorerPatternRegistry() {
    registeredPatterModels = Multimaps.newListMultimap(
            Maps.<IFile, Collection<IQuerySpecification<?>>>newHashMap(),
            new Supplier<List<IQuerySpecification<?>>>() {

                @Override/*from ww w.  j av  a 2s.c  o  m*/
                public List<IQuerySpecification<?>> get() {
                    return Lists.newArrayList();
                }
            });
    patternNameMap = new HashMap<String, IQuerySpecification<?>>();
    activePatterns = new ArrayList<IQuerySpecification<?>>();
    builder = new SpecificationBuilder();
}

From source file:com.ansorgit.plugins.bash.lang.psi.impl.command.BashIncludeCommandImpl.java

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state,
        PsiElement lastParent, @NotNull PsiElement place) {
    boolean result = PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    if (!result) {
        //processing is done here
        return false;
    }//from www  . ja v  a  2  s  .  c  o m

    PsiFile containingFile = getContainingFile();
    PsiFile includedFile = BashPsiUtils.findIncludedFile(this);

    Multimap<VirtualFile, PsiElement> visitedFiles = state.get(visitedIncludeFiles);
    if (visitedFiles == null) {
        visitedFiles = Multimaps.newListMultimap(Maps.<VirtualFile, Collection<PsiElement>>newHashMap(),
                new Supplier<List<PsiElement>>() {
                    public List<PsiElement> get() {
                        return Lists.newLinkedList();
                    }
                });
    }

    visitedFiles.put(containingFile.getVirtualFile(), null);

    if (includedFile != null && !visitedFiles.containsKey(includedFile.getVirtualFile())) {
        //mark the file as visited before the actual visit, otherwise we'll get a stack overflow
        visitedFiles.put(includedFile.getVirtualFile(), this);

        state = state.put(visitedIncludeFiles, visitedFiles);

        return includedFile.processDeclarations(processor, state, lastParent, place);
    }

    return true;
}

From source file:org.prebake.service.tools.JarProcess.java

static byte extractJar(Path cwd, String... argv) throws IOException {
    int pos = 0;//from w ww. j a v  a 2s . com
    int last = argv.length - 1;

    Path root = cwd.getRoot();

    String jarFile = argv[++pos];

    MutableGlobSet globs = new MutableGlobSet();
    Multimap<Glob, Path> outRoots = Multimaps.newListMultimap(Maps.<Glob, Collection<Path>>newHashMap(),
            new Supplier<List<Path>>() {
                public List<Path> get() {
                    return Lists.newArrayList();
                }
            });
    while (pos < last) {
        String globStr = argv[++pos];
        Glob g = Glob.fromString(globStr);
        String treeRoot = g.getTreeRoot();
        if (!"".equals(treeRoot)) {
            globStr = globStr.substring(treeRoot.length());
            if (globStr.startsWith("///")) {
                globStr = globStr.substring(3);
            }
            g = Glob.fromString(globStr);
        }
        if (outRoots.get(g).isEmpty()) {
            globs.add(g);
        }
        outRoots.put(g, cwd.resolve(FsUtil.denormalizePath(root, treeRoot)));
    }

    ZipInputStream in = new ZipInputStream(cwd.resolve(jarFile).newInputStream());
    try {
        Set<Path> dests = Sets.newLinkedHashSet();
        for (ZipEntry e; (e = in.getNextEntry()) != null;) {
            Path path = root.getFileSystem().getPath(FsUtil.denormalizePath(root, e.getName()));
            dests.clear();
            for (Glob g : globs.matching(path)) {
                dests.addAll(outRoots.get(g));
            }
            if (e.isDirectory()) {
                for (Path dest : dests) {
                    mkdirs(dest.resolve(path));
                }
            } else {
                if (!dests.isEmpty()) {
                    OutputStream[] outs = new OutputStream[dests.size()];
                    try {
                        Iterator<Path> it = dests.iterator();
                        for (int i = 0; i < outs.length; ++i) {
                            Path outFile = it.next().resolve(path);
                            mkdirs(outFile.getParent());
                            outs[i] = outFile.newOutputStream(StandardOpenOption.CREATE_NEW,
                                    StandardOpenOption.TRUNCATE_EXISTING);
                        }
                        byte[] buf = new byte[4096];
                        for (int nRead; (nRead = in.read(buf)) > 0;) {
                            for (OutputStream os : outs) {
                                os.write(buf, 0, nRead);
                            }
                        }
                    } finally {
                        for (OutputStream os : outs) {
                            if (os != null) {
                                Closeables.closeQuietly(os);
                            }
                        }
                    }
                }
                in.closeEntry();
            }
        }
    } finally {
        in.close();
    }
    return 0;
}

From source file:org.jboss.weld.introspector.jlr.WeldConstructorImpl.java

/**
 * Constructor//from   w  ww  .  ja  va 2 s  .  c  o  m
 * 
 * Initializes the superclass with the build annotations map
 * 
 * @param constructor The constructor method
 * @param declaringClass The declaring class
 */
private WeldConstructorImpl(Constructor<T> constructor, final Class<T> rawType, final Type type,
        AnnotatedConstructor<T> annotatedConstructor, Set<Type> typeClosure,
        Map<Class<? extends Annotation>, Annotation> annotationMap,
        Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, WeldClass<T> declaringClass,
        ClassTransformer classTransformer) {
    super(annotationMap, declaredAnnotationMap, classTransformer, constructor, rawType, type, typeClosure,
            declaringClass);
    this.constructor = constructor;

    this.parameters = new ArrayList<WeldParameter<?, T>>();
    annotatedParameters = Multimaps.newListMultimap(
            new HashMap<Class<? extends Annotation>, Collection<WeldParameter<?, T>>>(),
            new Supplier<List<WeldParameter<?, T>>>() {

                public List<WeldParameter<?, T>> get() {
                    return new ArrayList<WeldParameter<?, T>>();
                }

            });

    Map<Integer, AnnotatedParameter<?>> annotatedTypeParameters = new HashMap<Integer, AnnotatedParameter<?>>();

    if (annotatedConstructor != null) {
        for (AnnotatedParameter<?> annotated : annotatedConstructor.getParameters()) {
            annotatedTypeParameters.put(annotated.getPosition(), annotated);
        }
    }

    // If the class is a (non-static) member class, its constructors
    // parameterTypes array will prefix the
    // outer class instance, whilst the genericParameterTypes array isn't
    // prefix'd
    int nesting = Reflections.getNesting(declaringClass.getJavaClass());
    if (annotatedConstructor == null) {
        for (int i = 0; i < constructor.getParameterTypes().length; i++) {
            int gi = i - nesting;
            if (constructor.getParameterAnnotations()[i].length > 0) {
                Class<? extends Object> clazz = constructor.getParameterTypes()[i];
                Type parameterType;
                if (constructor.getGenericParameterTypes().length > gi && gi >= 0) {
                    parameterType = constructor.getGenericParameterTypes()[gi];
                } else {
                    parameterType = clazz;
                }
                WeldParameter<?, T> parameter = WeldParameterImpl.of(constructor.getParameterAnnotations()[i],
                        clazz, parameterType, this, i, classTransformer);
                this.parameters.add(parameter);
                for (Annotation annotation : parameter.getAnnotations()) {
                    if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType())) {
                        annotatedParameters.put(annotation.annotationType(), parameter);
                    }
                }
            } else {
                Class<? extends Object> clazz = constructor.getParameterTypes()[i];
                Type parameterType;
                if (constructor.getGenericParameterTypes().length > gi && gi >= 0) {
                    parameterType = constructor.getGenericParameterTypes()[gi];
                } else {
                    parameterType = clazz;
                }
                WeldParameter<?, T> parameter = WeldParameterImpl.of(new Annotation[0], clazz, parameterType,
                        this, i, classTransformer);
                this.parameters.add(parameter);
            }
        }
    } else {
        if (annotatedConstructor.getParameters().size() != constructor.getParameterTypes().length) {
            throw new DefinitionException(ReflectionMessage.INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD,
                    annotatedConstructor.getParameters().size(), annotatedConstructor,
                    annotatedConstructor.getParameters(), Arrays.asList(constructor.getParameterTypes()));
        } else {
            for (AnnotatedParameter<T> annotatedParameter : annotatedConstructor.getParameters()) {
                WeldParameter<?, T> parameter = WeldParameterImpl.of(annotatedParameter.getAnnotations(),
                        constructor.getParameterTypes()[annotatedParameter.getPosition()],
                        annotatedParameter.getBaseType(), this, annotatedParameter.getPosition(),
                        classTransformer);
                this.parameters.add(parameter);
                for (Annotation annotation : parameter.getAnnotations()) {
                    if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType())) {
                        annotatedParameters.put(annotation.annotationType(), parameter);
                    }
                }
            }
        }

    }
    this.signature = new ConstructorSignatureImpl(this);
}

From source file:org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo.java

private ListMultimap<DataFlowValue, JetType> copyTypeInfo() {
    ListMultimap<DataFlowValue, JetType> newTypeInfo = Multimaps.newListMultimap(
            Maps.<DataFlowValue, Collection<JetType>>newHashMap(),
            CommonSuppliers.<JetType>getArrayListSupplier());
    newTypeInfo.putAll(typeInfo);/*from w w  w .j  ava  2  s.c o  m*/
    return newTypeInfo;
}