Example usage for com.google.common.collect ArrayListMultimap create

List of usage examples for com.google.common.collect ArrayListMultimap create

Introduction

In this page you can find the example usage for com.google.common.collect ArrayListMultimap create.

Prototype

public static <K, V> ArrayListMultimap<K, V> create() 

Source Link

Document

Creates a new, empty ArrayListMultimap with the default initial capacities.

Usage

From source file:org.eclipse.viatra.query.tooling.core.generator.fragments.ExtensionBasedGenerationFragmentProvider.java

protected void initializeFragments() {
    fragments = ArrayListMultimap.create();
    final IConfigurationElement[] config = Platform.getExtensionRegistry()
            .getConfigurationElementsFor(EXTENSIONID);
    for (IConfigurationElement e : config) {
        final String annotationName = e.getAttribute(ANNOTATION) != null ? e.getAttribute(ANNOTATION)
                : GENERIC_ATTRIBUTE;/*  w  w w.j a  v a  2  s  . c  om*/
        try {
            IGenerationFragment fragment = (IGenerationFragment) e.createExecutableExtension("fragment");
            fragments.put(annotationName, fragment);
        } catch (CoreException e1) {
            logger.warn("Cannot load generator fragment from " + e.getContributor().getName(), e1);
        }
    }
}

From source file:org.elasticsearch.cassandra.cluster.routing.LocalFirstSearchStrategy.java

@Override
public AbstractSearchStrategy.Result topology(String ksName, Collection<InetAddress> staredShard) {
    Keyspace.open(ksName);/*from   ww w  .j  av a2  s .co m*/

    Set<InetAddress> liveNodes = Gossiper.instance.getLiveTokenOwners();
    InetAddress localAddress = FBUtilities.getBroadcastAddress();
    Map<Range<Token>, List<InetAddress>> allRanges = StorageService.instance
            .getRangeToAddressMapInLocalDC(ksName);

    Multimap<InetAddress, Range<Token>> topo = ArrayListMultimap.create();
    boolean consistent = true;

    Collection<Range<Token>> localRanges = new ArrayList<Range<Token>>();
    for (Entry<Range<Token>, List<InetAddress>> entry : allRanges.entrySet()) {
        List<InetAddress> addrList = entry.getValue();
        if (addrList.contains(localAddress)) {
            localRanges.add(entry.getKey());
            entry.getValue().remove(localAddress);
        }
    }
    logger.debug("{} localRanges for keyspace {} on address {} = {}", localRanges.size(), ksName,
            FBUtilities.getBroadcastAddress(), localRanges);

    topo.putAll(localAddress, localRanges);

    // remove localRanges from allRanges.
    for (Range<Token> range : localRanges) {
        allRanges.remove(range);
    }

    // remove dead nodes form allRanges values.
    for (Entry<Range<Token>, List<InetAddress>> entry : allRanges.entrySet()) {
        List<InetAddress> addrList = entry.getValue();
        for (Iterator<InetAddress> i = addrList.iterator(); i.hasNext();) {
            InetAddress addr = i.next();
            if (!liveNodes.contains(addr)) {
                i.remove();
            }
        }
        if (addrList.size() == 0) {
            consistent = false;
            logger.warn("Inconsistent search for keyspace {}, no alive node for range {}", ksName,
                    entry.getKey());
        }
    }

    // pickup a random address for non-local ranges
    Random rnd = new Random();
    for (Entry<Range<Token>, List<InetAddress>> entry : allRanges.entrySet()) {
        List<InetAddress> addrList = entry.getValue();
        InetAddress addr = addrList.get(rnd.nextInt(addrList.size()));
        topo.put(addr, entry.getKey());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("topology for keyspace {} = {}", ksName, topo.asMap());
    }
    return null;
    // return new AbstractSearchStrategy.Result(topo.asMap(), consistent,
    // Gossiper.instance.getUnreachableTokenOwners().size());
}

From source file:org.tzi.use.gen.assl.statics.GInstructionCreator.java

private GInstructionCreator() {
    IGInstructionMatcher matcherlist[] = { new GMatcherCreate_C(), new GMatcherAny_Seq(), new GMatcherSub_Seq(),
            new GMatcherTry_Seq(), new GMatcherCreateN_C_Integer(), new GMatcherDelete_Object(), //disabled, because references
            //    to deleted objects would not be updated.
            new GMatcherInsert_Assoc_Linkends(), new GMatcherDelete_Assoc_Linkends(),
            new GMatcherTry_Attribute(), new GMatcherTry_Assoc_LinkendSeqs(),
            new GMatcherTry_AssocClass_LinkendSeqs(), new GMatcherSub_Seq_Integer(), new GMatcherCreate_AC() };
    matchermap = ArrayListMultimap.create();
    for (int i = 0; i < matcherlist.length; i++)
        matchermap.put(matcherlist[i].name(), matcherlist[i]);
}

From source file:org.n52.movingcode.runtime.coderepository.PackageInventory.java

/**
 * No argument constructor.//from  w ww .j  av  a  2s  . c om
 */
PackageInventory() {
    packagesByIdMap = new ConcurrentHashMap<PID, MovingCodePackage>();

    // multimap for packageName -> packageId LUT
    Multimap<String, MovingCodePackage> delegate1 = ArrayListMultimap.create();
    packagesByNameMap = Multimaps.synchronizedMultimap(delegate1);

    // multimap for functionId -> packageId LUT
    Multimap<String, MovingCodePackage> delegate2 = ArrayListMultimap.create();
    packagesByFunctionIdMap = Multimaps.synchronizedMultimap(delegate2);
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.MaxRunningAppsEnforcer.java

public MaxRunningAppsEnforcer(FairScheduler scheduler) {
    this.scheduler = scheduler;
    this.usersNumRunnableApps = new HashMap<String, Integer>();
    this.usersNonRunnableApps = ArrayListMultimap.create();
}

From source file:org.eclipse.viatra.addon.viewers.runtime.specifications.ItemQuerySpecificationDescriptor.java

private static Multimap<PParameter, PParameter> getTraceSource(IQuerySpecification<?> specification,
        PAnnotation annotation) {/*from  w  ww  .  j  a  va2  s  . c o m*/
    Multimap<PParameter, PParameter> traces = ArrayListMultimap.create();
    ParameterReference parameterSource = annotation
            .getFirstValue(SOURCE_PARAMETER_NAME, ParameterReference.class)
            .orElseThrow(() -> new QueryProcessingException("Invalid source value", specification));

    SpecificationDescriptorUtilities.insertToTraces(specification, traces, parameterSource.getName());

    return traces;
}

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

@NotNull
private static List<TableLabel> generateLabelsForType(@NotNull final List<EditedStyleItem> source,
        @NotNull final List<EditedStyleItem> sink) {
    // ArrayListMultimap is used to ensure the elements stay sorted
    final Multimap<Group, EditedStyleItem> classes = ArrayListMultimap.create();

    for (final EditedStyleItem item : source) {
        final String name = item.getName();
        classes.put(Group.getGroupFromName(name), item);
    }/*w ww.ja  va 2  s.  c o  m*/

    final List<TableLabel> labels = new ArrayList<TableLabel>();
    int offset = 0;
    for (Group group : Group.values()) {
        Collection<EditedStyleItem> elements = classes.get(group);

        boolean addHeader = !elements.isEmpty();
        if (addHeader && group == Group.OTHER) {
            // Adding "Everything else" label only in case when there are at least one other label,
            // because having "Everything else" as the only label present looks quite silly
            addHeader = offset != 0;
        }
        if (addHeader) {
            labels.add(new TableLabel(group.name, offset));
        }

        sink.addAll(elements);

        offset += elements.size();
    }

    return labels;
}

From source file:ezbake.publisher.service.PublisherBroadcaster.java

@Override
protected void prepare(Properties props, String groupId) {
    isBroadcasting = true;
    broadcasted = ArrayListMultimap.create();
}

From source file:de.cubicvoxel.openspacebox.ingame.controller.Chunk.java

public Chunk() {
    objectsInChunk = ArrayListMultimap.create();
    lastUpdateTime = System.nanoTime();
}

From source file:org.dishevelled.bio.variant.vcf.StreamingVcfParser.java

/**
 * Stream the specified readable.//w  ww .  ja  va  2s .  c o m
 *
 * @param readable readable, must not be null
 * @param listener event based reader callback, must not be null
 * @throws IOException if an I/O error occurs
 */
public static void stream(final Readable readable, final VcfStreamListener listener) throws IOException {
    checkNotNull(readable);
    checkNotNull(listener);

    VcfParser.parse(readable, new VcfParseAdapter() {
        /** VCF record builder. */
        private final VcfRecord.Builder builder = VcfRecord.builder();

        /** File format, e.g. <code>VCFv4.2</code>, the only required header field. */
        private String fileFormat;

        /** List of meta-information header lines. */
        private List<String> meta = new ArrayList<String>();

        /** VCF samples keyed by name. */
        private Map<String, VcfSample> samples = new HashMap<String, VcfSample>();

        @Override
        public void lineNumber(final long lineNumber) throws IOException {
            builder.withLineNumber(lineNumber);
        }

        @Override
        public void meta(final String meta) throws IOException {
            this.meta.add(meta.trim());
            if (meta.startsWith("##fileformat=")) {
                fileFormat = meta.substring(13).trim();
            } else if (meta.startsWith("##SAMPLE=")) {
                ListMultimap<String, String> values = ArrayListMultimap.create();
                String[] tokens = meta.substring(10).split(",");
                for (String token : tokens) {
                    String[] metaTokens = token.split("=");
                    String key = metaTokens[0];
                    String[] valueTokens = metaTokens[1].split(";");
                    for (String valueToken : valueTokens) {
                        values.put(key, valueToken.replace("\"", "").replace(">", ""));
                    }
                }

                String id = values.get("ID").get(0);
                List<String> genomeIds = values.get("Genomes");
                List<String> mixtures = values.get("Mixture");
                List<String> descriptions = values.get("Description");

                List<VcfGenome> genomes = new ArrayList<VcfGenome>(genomeIds.size());
                for (int i = 0, size = genomeIds.size(); i < size; i++) {
                    genomes.add(new VcfGenome(genomeIds.get(i), Double.parseDouble(mixtures.get(i)),
                            descriptions.get(i)));
                }
                samples.put(id, new VcfSample(id, genomes.toArray(new VcfGenome[genomes.size()])));
            }
        }

        @Override
        public void samples(final String... samples) throws IOException {
            for (String sample : samples) {
                // add if missing in meta lines
                if (!this.samples.containsKey(sample)) {
                    this.samples.put(sample, new VcfSample(sample));
                }
            }

            // at end of header lines, notify listener of header
            listener.header(new VcfHeader(fileFormat, meta));
            // ...and samples
            for (VcfSample sample : this.samples.values()) {
                listener.sample(sample);
            }
        }

        @Override
        public void chrom(final String chrom) throws IOException {
            builder.withChrom(chrom);
        }

        @Override
        public void pos(final long pos) throws IOException {
            builder.withPos(pos);
        }

        @Override
        public void id(final String... id) throws IOException {
            builder.withId(id);
        }

        @Override
        public void ref(final String ref) throws IOException {
            builder.withRef(ref);
        }

        @Override
        public void alt(final String... alt) throws IOException {
            builder.withAlt(alt);
        }

        @Override
        public void qual(final Double qual) throws IOException {
            builder.withQual(qual);
        }

        @Override
        public void filter(final String... filter) throws IOException {
            builder.withFilter(filter);
        }

        @Override
        public void info(final String infoId, final String... values) throws IOException {
            builder.withInfo(infoId, values);
        }

        @Override
        public void format(final String... format) throws IOException {
            builder.withFormat(format);
        }

        @Override
        public void genotype(final String sampleId, final String formatId, final String... values)
                throws IOException {
            builder.withGenotype(sampleId, formatId, values);
        }

        @Override
        public boolean complete() throws IOException {
            listener.record(builder.build());

            builder.reset();
            fileFormat = null;
            meta = null;
            samples = null;

            return true;
        }
    });
}