Example usage for com.google.common.collect LinkedListMultimap put

List of usage examples for com.google.common.collect LinkedListMultimap put

Introduction

In this page you can find the example usage for com.google.common.collect LinkedListMultimap put.

Prototype

@Override
public boolean put(@Nullable K key, @Nullable V value) 

Source Link

Document

Stores a key-value pair in the multimap.

Usage

From source file:net.tridentsdk.server.bench.Benchmarks.java

public static LinkedListMultimap<String, Double> parse(String lines) {
    LinkedListMultimap<String, Double> list = LinkedListMultimap.create();

    for (String s : lines.split("\n")) {
        String[] split = s.split(" ");
        list.put(split[0], Double.parseDouble(split[1]));
    }//w  ww  . j ava 2s.c o  m

    return list;
}

From source file:com.tinspx.util.net.RequestBody.java

static <K, V> LinkedListMultimap<K, V> copyOfMap(Map<? extends K, ? extends V> headers) {
    LinkedListMultimap<K, V> map = LinkedListMultimap.create(headers.size());
    for (Map.Entry<? extends K, ? extends V> entry : headers.entrySet()) {
        map.put(entry.getKey(), entry.getValue());
    }//  w  w w . j av  a 2  s  . c  o  m
    return map;
}

From source file:org.onos.yangtools.yang.data.impl.schema.transform.dom.DomUtils.java

public static LinkedListMultimap<QName, Element> mapChildElements(
        final Iterable<Element> childNodesCollection) {
    final LinkedListMultimap<QName, Element> mappedChildElements = LinkedListMultimap.create();

    for (final Element element : childNodesCollection) {
        final QName childQName = XmlDocumentUtils.qNameFromElement(element);
        mappedChildElements.put(childQName, element);
    }/*from www.j a va 2s  .  c  o m*/

    return mappedChildElements;
}

From source file:net.tridentsdk.server.bench.Benchmarks.java

public static LinkedListMultimap<String, Double> parse(Collection<RunResult> results) {
    LinkedListMultimap<String, Double> data = LinkedListMultimap.create();
    for (RunResult result : results) {
        for (BenchmarkResult result0 : result.getBenchmarkResults()) {
            System.out.println(/*  w w  w .  j a  v a2s  .  com*/
                    result0.getPrimaryResult().getLabel() + " " + result0.getPrimaryResult().getScore());
            data.put(result0.getPrimaryResult().getLabel(), result0.getPrimaryResult().getScore());
        }
    }

    return data;
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

static List<Object> getSubscriptionsAsOutlines(final Context context, final boolean retainCategories) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);

    final List<Object> outlines = new ArrayList<>(subscriptions.size());
    final LinkedListMultimap<String, Outline> outlineGroups = LinkedListMultimap.create();

    for (final String title : subscriptions.asMap().keySet()) {
        final String category = subscriptions.get(title).get(0);
        final String xmlUrl = subscriptions.get(title).get(2);

        final Outline outline = new Outline.Builder().setText(title).setTitle(title).setXmlUrl(xmlUrl).build();

        if (retainCategories) {
            outlineGroups.put(category, outline);
        } else {//from   w  w w .ja v  a2  s.c om
            outlines.add(outline);
        }
    }

    if (retainCategories) {
        for (final String category : outlineGroups.asMap().keySet()) {
            outlines.add(new OutlineGroup.Builder().setText(category).setTitle(category)
                    .addSubOutlines(outlineGroups.get(category)).build());
        }
    }

    return outlines;
}

From source file:eu.tomylobo.routes.util.Ini.java

public static Multimap<String, Multimap<String, String>> load(String fileName) {

    final LinkedListMultimap<String, Multimap<String, String>> sections = LinkedListMultimap.create();

    try {// w w  w.j  a  v a2 s .  c o m
        final BufferedReader stream = new BufferedReader(new FileReader(fileName));
        String line;
        while ((line = stream.readLine()) != null) {
            if (line.trim().isEmpty())
                continue;

            final Matcher matcher = sectionStartPattern.matcher(line);

            if (!matcher.matches()) {
                System.err.println("Malformed line in " + fileName + ".");
                continue;
            }

            final String sectionName = matcher.group(1);
            final Multimap<String, String> section = loadSection(stream);

            sections.put(sectionName, section);
        }
        stream.close();
    } catch (IOException e) {
        //e.printStackTrace();
        return null;
    }

    return sections;
}

From source file:net.joinedminds.masserr.util.RoleFormFunctions.java

public static String setRoleAttributes(Role role, JSONObject formObject, ManipulationDB manipulationDB) {
    role.setPhysical(ifNull(formObject.optInt("physical"), 0));
    role.setSocial(ifNull(formObject.optInt("social"), 0));
    role.setMental(ifNull(formObject.optInt("mental"), 0));

    LinkedListMultimap<Ability.Type, DottedNotedType<Ability>> multiMap = LinkedListMultimap.create();
    JSONArray abilities = formObject.optJSONArray("ability");
    if (abilities != null) {
        for (int i = 0; i < abilities.size(); i++) {
            JSONObject a = abilities.getJSONObject(i);
            int dots = a.optInt("dots");
            String type = a.optString("type");
            String notes = a.optString("notes");
            String id = a.optString("id");
            if (ifNull(dots, 0) > 0 && !isEmpty(type) && !isEmpty(id)) {
                DottedNotedType<Ability> ability = new DottedNotedType<>(Ability.idRef(id), dots,
                        ifNull(notes, ""));
                multiMap.put(Ability.Type.valueOf(type), ability);
            }/*www. java2  s .co  m*/
        }
    }
    role.setPhysicalAbilities(multiMap.get(Ability.Type.Physical));
    role.setSocialAbilities(multiMap.get(Ability.Type.Social));
    role.setMentalAbilities(multiMap.get(Ability.Type.Mental));

    return null;
}

From source file:org.jetbrains.kotlin.checkers.CheckerTestUtil.java

@NotNull
private static List<DiagnosticDescriptor> getSortedDiagnosticDescriptors(
        @NotNull Collection<Diagnostic> diagnostics) {
    LinkedListMultimap<TextRange, Diagnostic> diagnosticsGroupedByRanges = LinkedListMultimap.create();
    for (Diagnostic diagnostic : diagnostics) {
        if (!diagnostic.isValid())
            continue;
        for (TextRange textRange : diagnostic.getTextRanges()) {
            diagnosticsGroupedByRanges.put(textRange, diagnostic);
        }//from  w w  w .ja v  a  2s. co  m
    }
    List<DiagnosticDescriptor> diagnosticDescriptors = Lists.newArrayList();
    for (TextRange range : diagnosticsGroupedByRanges.keySet()) {
        diagnosticDescriptors.add(new DiagnosticDescriptor(range.getStartOffset(), range.getEndOffset(),
                diagnosticsGroupedByRanges.get(range)));
    }
    Collections.sort(diagnosticDescriptors, new Comparator<DiagnosticDescriptor>() {
        @Override
        public int compare(@NotNull DiagnosticDescriptor d1, @NotNull DiagnosticDescriptor d2) {
            // Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
            return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
        }
    });
    return diagnosticDescriptors;
}

From source file:io.fd.maintainer.plugin.util.MaintainersIndex.java

public ComponentReviewInfo getReviewInfoForPath(final String path) {
    LOG.debug("Getting maintainers for path {}", path);
    final LinkedListMultimap<MatchLevel, Tuple2<ComponentPath, Maintainer>> byMatchIndex = LinkedListMultimap
            .create();/*from ww  w  .  j  ava2s. c o m*/

    pathToMaintainersIndex.forEach((key, value) -> value
            .forEach((entry -> byMatchIndex.put(key.matchAgainst(path), new Tuple2<>(key, entry)))));

    final MatchLevel maximumMatchLevel = maxMatchLevel(byMatchIndex.keys());
    LOG.debug("Maximum match level for path {} = {}", path, maximumMatchLevel);

    // out of all that have maximum match level, we need only those that are most basically longest
    // allows to get /foo/bar/* over * or /foo/*
    final int mostSpecificPathLength = mostSpecificPathLengthFromTuple(maximumMatchLevel, byMatchIndex);

    if (NONE == maximumMatchLevel) {
        return new ComponentReviewInfoBuilder().setAffectedFile(path).createComponentReviewInfo();
    } else {
        return byMatchIndex.get(maximumMatchLevel).stream()
                .filter(tuple -> getPathLength(tuple.a.getPath()) == mostSpecificPathLength)
                .peek(maintainer -> LOG.debug("Maintainer found [component={},reviewer={}]", maintainer.a,
                        maintainer.b))
                .map(tuple -> new ComponentReviewInfoBuilder().setAffectedFile(path)
                        .setComponentName(getComponentForPath(tuple.a))
                        .setComponentMaintainers(pathToMaintainersIndex.get(tuple.a))
                        .createComponentReviewInfo())
                .findAny()
                .orElse(new ComponentReviewInfoBuilder().setAffectedFile(path).createComponentReviewInfo());
    }
}

From source file:io.fd.maintainer.plugin.util.MaintainersIndex.java

public Tuple2<Set<ComponentPath>, Set<ComponentPath>> getComponentPathsForEntry(
        @Nonnull final PatchListEntry entry) {
    final LinkedListMultimap<MatchLevel, ComponentPath> byMatchIndexOld = LinkedListMultimap.create();
    final LinkedListMultimap<MatchLevel, ComponentPath> byMatchIndexNew = LinkedListMultimap.create();
    pathToMaintainersIndex/*from  w  w  w.  java  2 s . c o m*/
            .forEach((key, value) -> byMatchIndexOld.put(key.matchAgainst(entry.getOldName()), key));

    pathToMaintainersIndex
            .forEach((key, value) -> byMatchIndexNew.put(key.matchAgainst(entry.getNewName()), key));

    final MatchLevel maxMatchLevelOld = maxMatchLevel(byMatchIndexOld.keys());
    final MatchLevel maxMatchLevelNew = maxMatchLevel(byMatchIndexNew.keys());

    final int mostSpecificLengthOld = mostSpecificPathLengthFromComponent(maxMatchLevelOld, byMatchIndexOld);
    final int mostSpecificLengthNew = mostSpecificPathLengthFromComponent(maxMatchLevelOld, byMatchIndexOld);

    final Set<ComponentPath> oldComponents = NONE == maxMatchLevelOld ? Collections.emptySet()
            : new HashSet<>(byMatchIndexOld.get(maxMatchLevelOld).stream()
                    .filter(componentPath -> getPathLength(componentPath.getPath()) == mostSpecificLengthOld)
                    .collect(Collectors.toList()));

    final Set<ComponentPath> newComponents = NONE == maxMatchLevelNew ? Collections.emptySet()
            : new HashSet<>(byMatchIndexNew.get(maxMatchLevelNew).stream()
                    .filter(componentPath -> getPathLength(componentPath.getPath()) == mostSpecificLengthNew)
                    .collect(Collectors.toList()));

    return new Tuple2<>(oldComponents, newComponents);
}