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.zalando.logbook.httpclient.Request.java

@Override
public Multimap<String, String> getHeaders() {
    final ListMultimap<String, String> map = ArrayListMultimap.create();

    for (Header header : request.getAllHeaders()) {
        map.put(header.getName(), header.getValue());
    }/*from w ww  .j  av  a2s.c o  m*/

    return map;
}

From source file:com.ardor3d.util.scenegraph.DisplayListDelegate.java

@SuppressWarnings("unchecked")
private static Multimap<Object, Integer> gatherGCdIds(Multimap<Object, Integer> store) {
    // Pull all expired display lists from ref queue and add to an id multimap.
    SimpleContextIdReference<DisplayListDelegate> ref;
    while ((ref = (SimpleContextIdReference<DisplayListDelegate>) _refQueue.poll()) != null) {
        if (store == null) { // lazy init
            store = ArrayListMultimap.create();
        }//w w w . j a va2s . c  o m
        store.put(ref.getGlContext(), ref.getId());
        ref.clear();
    }
    return store;
}

From source file:org.jenkinsci.plugins.custom_history.CustomHistoryAction.java

/**
 * Returns all changes which contribute to a build.
 *
 * @param build//from  www . j  a  v  a2s. c  o m
 * @return
 */
public Multimap<String, AbstractBuild> getAllChanges(AbstractBuild build) {
    Set<AbstractBuild> builds = getContributingBuilds(build);
    Multimap<String, AbstractBuild> historymmap = ArrayListMultimap.create();
    for (AbstractBuild changedBuild : builds) {
        File dir = build.getArtifactsDir();
        Scanner scanner = null;
        StringBuilder text = new StringBuilder();
        try {
            String NL = System.getProperty("line.separator");
            scanner = new Scanner(
                    new FileInputStream(dir.getAbsoluteFile() + "/" + SaveHistory.unifiedHistoryFile));
            while (scanner.hasNextLine()) {
                text.append(scanner.nextLine()).append(NL);
            }
        } catch (Exception e) {
        } finally {
            if (scanner != null) {
                scanner.close();
            }
        }

        historymmap.put(text.toString(), changedBuild);
    }
    return historymmap;
}

From source file:org.yakindu.sct.ui.editor.validation.DefaultValidationIssueStore.java

public DefaultValidationIssueStore() {
    listener = Lists.newArrayList();
    visibleIssues = ArrayListMultimap.create();
}

From source file:org.franca.core.dsl.scoping.FTypeScope.java

protected FTypeScope(IScope parent, boolean ignoreCase,
        ImportUriGlobalScopeProvider importUriGlobalScopeProvider, Resource resource,
        IQualifiedNameProvider qualifiedNameProvider) {
    super(parent, ignoreCase);
    this.importUriGlobalScopeProvider = importUriGlobalScopeProvider;
    this.resource = resource;
    this.qualifiedNameProvider = qualifiedNameProvider;
    this.model = (FModel) resource.getContents().get(0);
    this.imports = new HashSet<URI>();
    this.packagePrefixMap = ArrayListMultimap.create();
    this.processImports();
}

From source file:com.facebook.presto.operator.scalar.SplitToMultimapFunction.java

@SqlType("map(varchar,array(varchar))")
public Block splitToMultimap(@TypeParameter("map(varchar,array(varchar))") Type mapType,
        @SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice entryDelimiter,
        @SqlType(StandardTypes.VARCHAR) Slice keyValueDelimiter) {
    checkCondition(entryDelimiter.length() > 0, INVALID_FUNCTION_ARGUMENT, "entryDelimiter is empty");
    checkCondition(keyValueDelimiter.length() > 0, INVALID_FUNCTION_ARGUMENT, "keyValueDelimiter is empty");
    checkCondition(!entryDelimiter.equals(keyValueDelimiter), INVALID_FUNCTION_ARGUMENT,
            "entryDelimiter and keyValueDelimiter must not be the same");

    Multimap<Slice, Slice> multimap = ArrayListMultimap.create();
    int entryStart = 0;
    while (entryStart < string.length()) {
        // Extract key-value pair based on current index
        // then add the pair if it can be split by keyValueDelimiter
        Slice keyValuePair;/*from  w ww .ja  v  a  2s.  co m*/
        int entryEnd = string.indexOf(entryDelimiter, entryStart);
        if (entryEnd >= 0) {
            keyValuePair = string.slice(entryStart, entryEnd - entryStart);
        } else {
            // The rest of the string is the last possible pair.
            keyValuePair = string.slice(entryStart, string.length() - entryStart);
        }

        int keyEnd = keyValuePair.indexOf(keyValueDelimiter);
        if (keyEnd < 0) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT,
                    "Key-value delimiter must appear exactly once in each entry. Bad input: "
                            + keyValuePair.toStringUtf8());
        }

        int valueStart = keyEnd + keyValueDelimiter.length();
        Slice key = keyValuePair.slice(0, keyEnd);
        Slice value = keyValuePair.slice(valueStart, keyValuePair.length() - valueStart);
        if (value.indexOf(keyValueDelimiter) >= 0) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT,
                    "Key-value delimiter must appear exactly once in each entry. Bad input: "
                            + keyValuePair.toStringUtf8());
        }

        multimap.put(key, value);

        if (entryEnd < 0) {
            // No more pairs to add
            break;
        }
        // Next possible pair is placed next to the current entryDelimiter
        entryStart = entryEnd + entryDelimiter.length();
    }

    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }

    pageBuilder.declarePosition();
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder singleMapBlockBuilder = blockBuilder.beginBlockEntry();
    for (Map.Entry<Slice, Collection<Slice>> entry : multimap.asMap().entrySet()) {
        VARCHAR.writeSlice(singleMapBlockBuilder, entry.getKey());
        Collection<Slice> values = entry.getValue();
        BlockBuilder valueBlockBuilder = singleMapBlockBuilder.beginBlockEntry();
        for (Slice value : values) {
            VARCHAR.writeSlice(valueBlockBuilder, value);
        }
        singleMapBlockBuilder.closeEntry();
    }
    blockBuilder.closeEntry();

    return (Block) mapType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1);
}

From source file:org.nmdp.validation.tools.ValidateLdGlstrings.java

static ListMultimap<String, SubjectMug> read(final File file) throws IOException {
    BufferedReader reader = null;
    final ListMultimap<String, SubjectMug> subjectmugs = ArrayListMultimap.create();
    final SubjectMug.Builder builder = SubjectMug.builder();
    try {// ww  w  .  j  a  v a  2 s .c  om
        reader = reader(file);
        CharStreams.readLines(reader, new LineProcessor<Void>() {
            private int count = 0;

            @Override
            public boolean processLine(final String line) throws IOException {
                String[] tokens = line.split("\t");
                if (tokens.length < 2) {
                    throw new IOException("illegal format, expected at least 2 columns, found " + tokens.length
                            + "\nline=" + line);
                }

                String fullyQualified = GLStringUtilities.fullyQualifyGLString(tokens[1]);
                MultilocusUnphasedGenotype mug = GLStringUtilities.convertToMug(fullyQualified);
                DetectedLinkageFindings findings = LinkageDisequilibriumAnalyzer.detectLinkages(mug);
                Float minimumDifference = findings.getMinimumDifference(Locus.FIVE_LOCUS);
                minimumDifference = minimumDifference == null ? 0 : minimumDifference;
                SubjectMug subjectMug = builder.reset().withSample(tokens[0]).withGlstring(tokens[1])
                        .withMug(mug).withFindings(findings).withMinimumDifference(minimumDifference).build();

                subjectmugs.put(subjectMug.sample(), subjectMug);
                count++;
                return true;
            }

            @Override
            public Void getResult() {
                return null;
            }
        });

        return subjectmugs;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
            // ignore
        }
    }
}

From source file:eu.esdihumboldt.hale.app.bgis.ade.duplicate.DuplicateVisitor.java

@Override
protected boolean visit(PropertyEntityDefinition ped) {
    if (ADE_NS.equals(ped.getDefinition().getName().getNamespaceURI())) {
        // property is from ADE

        for (Cell exampleCell : exampleCells.get(ped.getDefinition().getName().getLocalPart())) {
            // handle each example cell

            // copy cell
            DefaultCell cell = new DefaultCell(exampleCell);
            // reset ID
            cell.setId(null);//w  w w.  j  ava2  s. c  o  m
            // assign new target
            ListMultimap<String, Entity> target = ArrayListMultimap.create();
            target.put(cell.getTarget().keys().iterator().next(), new DefaultProperty(ped));
            cell.setTarget(target);

            BGISAppUtil.appendNote(cell, cellNote);

            cells.add(cell);
        }

        return true;
    }

    return false;
}

From source file:io.datakernel.cube.api.Resolver.java

private ListMultimap<AttributeResolver, String> groupAttributesByResolvers(Set<String> attributes) {
    ListMultimap<AttributeResolver, String> resolverAttributes = ArrayListMultimap.create();
    for (String attribute : attributes) {
        resolverAttributes.put(attributeResolvers.get(attribute), attribute);
    }/*  www.  j  ava 2 s .c om*/
    return resolverAttributes;
}

From source file:eu.esdihumboldt.hale.common.scripting.transformation.AbstractScriptedPropertyTransformation.java

@Override
protected final ListMultimap<String, Object> evaluate(String transformationIdentifier, E engine,
        ListMultimap<String, PropertyValue> variables,
        ListMultimap<String, PropertyEntityDefinition> resultNames, Map<String, String> executionParameters,
        TransformationLog log) throws TransformationException {
    ListMultimap<String, ParameterValue> originalParameters = getParameters();
    ListMultimap<String, Value> transformedParameters = ArrayListMultimap.create();

    if (originalParameters != null) {
        for (Map.Entry<String, ParameterValue> entry : originalParameters.entries()) {
            if (!entry.getValue().needsProcessing()) {
                Value value = entry.getValue().intern();
                if (!value.isRepresentedAsDOM()) {
                    value = Value.simple(getExecutionContext().getVariables()
                            .replaceVariables(value.getStringRepresentation()));
                }//from   w w w  . j a v  a 2 s .  c  o  m
                transformedParameters.put(entry.getKey(), value);
            } else {
                // type is a script
                ScriptFactory factory = ScriptExtension.getInstance().getFactory(entry.getValue().getType());
                if (factory == null)
                    throw new TransformationException(
                            "Couldn't find factory for script id " + entry.getValue().getType());
                Script script;
                try {
                    script = factory.createExtensionObject();
                } catch (Exception e) {
                    throw new TransformationException("Couldn't create script from factory", e);
                }
                Object result;
                try {
                    String scriptStr = entry.getValue().as(String.class);
                    if (script.requiresReplacedTransformationVariables()) {
                        // replace transformation variables
                        scriptStr = getExecutionContext().getVariables().replaceVariables(scriptStr);
                    }
                    result = script.evaluate(scriptStr, variables.values(), getExecutionContext());
                } catch (ScriptException e) {
                    throw new TransformationException("Couldn't evaluate a transformation parameter", e);
                }
                // XXX use conversion service instead of valueOf?
                transformedParameters.put(entry.getKey(), Value.simple(result));
            }
        }
    }

    this.transformedParameters = Multimaps.unmodifiableListMultimap(transformedParameters);

    return evaluateImpl(transformationIdentifier, engine, variables, resultNames, executionParameters, log);
}