Example usage for com.google.common.collect ListMultimap get

List of usage examples for com.google.common.collect ListMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect ListMultimap get.

Prototype

@Override
List<V> get(@Nullable K key);

Source Link

Document

Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a List , instead of the java.util.Collection specified in the Multimap interface.

Usage

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

/**
 * Parse the Type=Integer Number=[n, A, R, G] attribute value for the specified key into an immutable list of integers
 * of size equal to the specified number.
 *
 * @param key key, must not be null//from   w  ww.j  a va2 s. c om
 * @param number number, must be greater than zero
 * @param attributes, must not be null
 * @return the Type=Integer Number=[n, A, R, G] attribute value for the specified key parsed into an immutable list of integers
 *    of size equal to the specified number
 */
static List<Integer> parseIntegers(final String key, final int number,
        final ListMultimap<String, String> attributes) {
    checkNotNull(key);
    checkNotNull(attributes);
    checkArgument(number > 0, "number must be at least one");

    List<String> values = attributes.get(key);
    if (values.size() != number) {
        throw new IllegalArgumentException(
                "expected " + number + " Type=Integer values, found " + values.size());
    }
    return parseIntegers(values);
}

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

/**
 * Return the Type=String Number=[n, A, R, G] attribute value for the specified key as an immutable list of strings
 * of size equal to the specified number.
 *
 * @param key key, must not be null//from  w w w  . j  ava2 s .c  o  m
 * @param number number, must be greater than zero
 * @param attributes, must not be null
 * @return the Type=String Number=[n, A, R, G] attribute value for the specified key as an immutable list of strings
 *    of size equal to the specified number
 */
static List<String> parseStrings(final String key, final int number,
        final ListMultimap<String, String> attributes) {
    checkNotNull(key);
    checkNotNull(attributes);
    checkArgument(number > 0, "number must be at least one");

    List<String> values = attributes.get(key);
    if (values.size() != number) {
        throw new IllegalArgumentException(
                "expected " + number + " Type=String values, found " + values.size());
    }
    return parseStrings(values);
}

From source file:org.icgc.dcc.portal.manifest.writer.GNOSManifestWriter.java

@SneakyThrows
public static void write(OutputStream buffer, ListMultimap<String, ManifestFile> bundles, long timestamp) {
    int rowCount = 0;
    // If this is thread-safe, perhaps we can make this static???
    val factory = XMLOutputFactory.newInstance();
    @Cleanup/* w w  w .j ava  2s . co  m*/
    val writer = new IndentingXMLStreamWriter(factory.createXMLStreamWriter(buffer, FILE_ENCODING));

    startXmlDocument(writer, timestamp);

    for (val url : bundles.keySet()) {
        val bundle = bundles.get(url);

        if (isEmpty(bundle)) {
            continue;
        }

        val bundleId = bundle.get(0).getDataBundleId();

        writeXmlEntry(writer, bundleId, url, bundle, ++rowCount);
    }

    endXmlDocument(writer);
}

From source file:org.opennms.core.wsman.utils.ResponseHandlingUtils.java

public static boolean matchesFilter(String spelFilter, ListMultimap<String, String> valuesByName) {
    // Compile the expression
    final ExpressionParser parser = new SpelExpressionParser();
    final Expression exp = parser.parseExpression(spelFilter);

    // Build the context with the first values for all of the attributes
    final StandardEvaluationContext context = new StandardEvaluationContext();
    for (String name : valuesByName.keySet()) {
        final List<String> values = valuesByName.get(name);
        if (values.size() > 0) {
            context.setVariable(name, values.get(0));
        }//from   ww  w  . j av a2  s.co m
    }

    // Evaluate our expression
    try {
        return exp.getValue(context, Boolean.class);
    } catch (Exception e) {
        LOG.error("Failed to evaluate expression {}. Assuming match is negative. Msg: {}",
                exp.getExpressionString(), e.getMessage());
        throw Throwables.propagate(e);
    }
}

From source file:com.streamsets.pipeline.stage.processor.lookup.ForceLookupProcessor.java

private static void sendChunkToError(String[] ids, ListMultimap<String, Record> recordsToRetrieve,
        ToErrorContext context, ApiFault e) {
    for (String id : ids) {
        for (Record record : recordsToRetrieve.get(id)) {
            context.toError(record, e);//from   w  ww. jav a2s .  co m
        }
    }
}

From source file:de.bund.bfr.knime.gis.views.canvas.RegionCanvasUtils.java

public static void paintRegions(Graphics2D g, Collection<RegionNode> nodes, Set<RegionNode> selectedNodes,
        HighlightConditionList nodeHighlightConditions) {
    Paint currentPaint = g.getPaint();

    g.setPaint(Color.BLUE);/*  ww  w.j ava2 s .co  m*/
    selectedNodes.forEach(n -> g.fill(n.getTransformedPolygon()));

    List<Color> nodeColors = new ArrayList<>();
    ListMultimap<RegionNode, Double> nodeAlphas = ArrayListMultimap.create();
    boolean prioritize = nodeHighlightConditions.isPrioritizeColors();

    for (HighlightCondition condition : nodeHighlightConditions.getConditions()) {
        Map<RegionNode, Double> values = condition.getValues(nodes);

        if (condition.getColor() != null) {
            nodeColors.add(condition.getColor());

            for (RegionNode node : nodes) {
                List<Double> alphas = nodeAlphas.get(node);

                if (!prioritize || alphas.isEmpty() || Collections.max(alphas) == 0.0) {
                    alphas.add(values.get(node));
                } else {
                    alphas.add(0.0);
                }
            }
        }
    }

    for (RegionNode node : nodes) {
        Paint color = CanvasUtils.mixColors(Color.WHITE, nodeColors, nodeAlphas.get(node), false);

        if (!color.equals(Color.WHITE) && !selectedNodes.contains(node)) {
            g.setPaint(color);
            g.fill(node.getTransformedPolygon());
        }
    }

    g.setPaint(currentPaint);
}

From source file:com.opengamma.strata.loader.csv.RatesCurvesCsvLoader.java

/**
 * Loads one or more CSV format curve files for a specific date.
 * <p>/*  w w w. ja v a 2s.co m*/
 * Only those quotes that match the specified date will be loaded.
 * <p>
 * If the files contain a duplicate entry an exception will be thrown.
 *
 * @param marketDataDate  the curve date to load
 * @param groupsResource  the curve groups CSV resource
 * @param settingsResource  the curve settings CSV resource
 * @param curveValueResources  the CSV resources for curves
 * @return the loaded curves, mapped by an identifying key
 * @throws IllegalArgumentException if the files contain a duplicate entry
 */
public static ImmutableList<CurveGroup> load(LocalDate marketDataDate, ResourceLocator groupsResource,
        ResourceLocator settingsResource, Collection<ResourceLocator> curveValueResources) {

    Collection<CharSource> curveCharSources = curveValueResources.stream().map(r -> r.getCharSource())
            .collect(toList());
    ListMultimap<LocalDate, CurveGroup> map = parse(d -> marketDataDate.equals(d),
            groupsResource.getCharSource(), settingsResource.getCharSource(), curveCharSources);
    return ImmutableList.copyOf(map.get(marketDataDate));
}

From source file:org.rf.ide.core.testdata.model.table.RobotExecutableRowView.java

private static void collectPrettyAlignsAndAssignmentAfterToken(
        final ListMultimap<RobotToken, RobotToken> specialTokens, final RobotToken token,
        final RobotLine robotLine) {
    final Optional<Integer> elementPositionInLine = robotLine.getElementPositionInLine(token);
    if (elementPositionInLine.isPresent()) {
        int lastAssignment = -1;
        final List<IRobotLineElement> lineElements = robotLine.getLineElements();
        final int lineElementsSize = lineElements.size();
        final List<RobotToken> tokensView = specialTokens.get(token);
        for (int i = elementPositionInLine.get() + 1; i < lineElementsSize; i++) {
            final IRobotLineElement lineElement = lineElements.get(i);
            final List<IRobotTokenType> elementTypes = lineElement.getTypes();
            if (lineElement.getClass() == RobotToken.class) {
                final RobotToken currentToken = (RobotToken) lineElement;
                if (elementTypes.contains(RobotTokenType.ASSIGNMENT)
                        || elementTypes.contains(RobotTokenType.PRETTY_ALIGN_SPACE)) {
                    specialTokens.put(token, currentToken);
                    if (elementTypes.contains(RobotTokenType.ASSIGNMENT)) {
                        lastAssignment = tokensView.size();
                    }// w  w w .  j  a  v  a2 s.co  m
                } else {
                    break;
                }
            } else {
                break;
            }
        }

        if (lastAssignment == -1) {
            specialTokens.removeAll(token);
        } else if (lastAssignment != tokensView.size()) {
            while (lastAssignment != tokensView.size()) {
                tokensView.remove(lastAssignment);
            }
        }
    }
}

From source file:org.caleydo.view.domino.api.model.typed.TypedSets.java

/**
 * convert a inhomogenous set of {@link TypedID} to a collection of {@link TypedSet}s
 *
 * @param set//from  w w w  .  j  a v a  2  s .c o m
 * @return
 */
public static Collection<TypedSet> toTypedSets(Set<TypedID> set) {
    if (set instanceof SingleTypedIDSet) { // its just a wrapper
        return Collections.singleton(((SingleTypedIDSet) set).getData());
    }
    // compress to typed sets
    ListMultimap<IDType, TypedID> index = Multimaps.index(set, TypedID.TO_IDTYPE);
    Collection<TypedSet> new_ = new ArrayList<>(index.keySet().size());
    for (IDType idType : index.keySet()) {
        List<TypedID> same = index.get(idType);
        new_.add(new TypedSet(ImmutableSet.copyOf(Lists.transform(same, TypedID.TO_ID)), idType));
    }
    return new_;
}

From source file:com.android.build.gradle.internal.ProductFlavorCombo.java

private static <S extends DimensionAware & Named> void createProductFlavorCombinations(
        List<ProductFlavorCombo<S>> flavorGroups, List<S> group, int index, List<String> flavorDimensionList,
        ListMultimap<String, S> map) {
    if (index == flavorDimensionList.size()) {
        flavorGroups.add(new ProductFlavorCombo<S>(Iterables.filter(group, Predicates.notNull())));
        return;//  w w w  .j  av a 2 s  .  c  om
    }

    // fill the array at the current index.
    // get the dimension name that matches the index we are filling.
    String dimension = flavorDimensionList.get(index);

    // from our map, get all the possible flavors in that dimension.
    List<S> flavorList = map.get(dimension);

    // loop on all the flavors to add them to the current index and recursively fill the next
    // indices.
    if (flavorList.isEmpty()) {
        throw new RuntimeException(
                String.format("No flavor is associated with flavor dimension '%1$s'.", dimension));
    } else {
        for (S flavor : flavorList) {
            group.add(flavor);
            createProductFlavorCombinations(flavorGroups, group, index + 1, flavorDimensionList, map);
            group.remove(group.size() - 1);
        }
    }
}