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:eu.esdihumboldt.hale.common.align.model.functions.join.JoinMigrator.java

@Override
public MutableCell updateCell(Cell originalCell, AlignmentMigration migration, MigrationOptions options,
        SimpleLog log) {/* ww  w.j  a  v a  2  s . c o m*/
    MutableCell result = super.updateCell(originalCell, migration, options, log);
    SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));

    if (options.updateSource()) {
        ListMultimap<String, ParameterValue> modParams = ArrayListMultimap
                .create(result.getTransformationParameters());
        List<ParameterValue> joinParams = modParams.get(JoinFunction.PARAMETER_JOIN);
        if (!joinParams.isEmpty()) {
            JoinParameter joinParam = joinParams.get(0).as(JoinParameter.class);
            if (joinParam != null) {
                joinParams.clear();
                joinParams.add(new ParameterValue(
                        Value.complex(convertJoinParameter(joinParam, migration, options, cellLog))));
            }
        }
        result.setTransformationParameters(modParams);
    }

    return result;
}

From source file:com.google.devtools.build.docgen.RuleFamily.java

RuleFamily(ListMultimap<RuleType, RuleDocumentation> ruleTypeMap, String name) {
    this.name = name;
    this.id = normalize(name);
    this.binaryRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.BINARY));
    this.libraryRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.LIBRARY));
    this.testRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.TEST));

    final ImmutableList<RuleDocumentation> otherRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.OTHER));
    if (otherRules.size() >= 4) {
        this.otherRules1 = ImmutableList.copyOf(otherRules.subList(0, otherRules.size() / 2));
        this.otherRules2 = ImmutableList.copyOf(otherRules.subList(otherRules.size() / 2, otherRules.size()));
    } else {//w w w .  j  a va 2  s . co  m
        this.otherRules1 = otherRules;
        this.otherRules2 = ImmutableList.of();
    }

    rules = ImmutableList.<RuleDocumentation>builder().addAll(binaryRules).addAll(libraryRules)
            .addAll(testRules).addAll(otherRules1).addAll(otherRules2).build();
}

From source file:eu.esdihumboldt.hale.common.align.model.functions.FormattedStringMigrator.java

@Override
public MutableCell updateCell(Cell originalCell, AlignmentMigration migration, MigrationOptions options,
        SimpleLog log) {//w w  w .  j a  va 2s.c o  m
    MutableCell result = super.updateCell(originalCell, migration, options, log);
    log = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));

    if (options.updateSource()) {
        ListMultimap<String, ParameterValue> modParams = ArrayListMultimap
                .create(result.getTransformationParameters());
        List<ParameterValue> patternParams = modParams.get(FormattedStringFunction.PARAMETER_PATTERN);
        if (!patternParams.isEmpty()) {
            String pattern = patternParams.get(0).as(String.class);
            if (pattern != null) {
                patternParams.clear();
                patternParams.add(new ParameterValue(
                        Value.of(convertPattern(pattern, originalCell.getSource(), migration, log))));
            }
        }
        result.setTransformationParameters(modParams);
    }

    return result;
}

From source file:io.datakernel.datagraph.graph.DataGraph.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    ListMultimap<Partition, Node> map = getNodesByPartition();
    for (Partition partition : map.keySet()) {
        sb.append("--- " + partition + "\n\n");
        List<Node> nodes = map.get(partition);
        String str = serialization.gson.toJson(nodes, new TypeToken<List<Node>>() {
        }.getType());//  ww w  .ja  v a  2  s .  c  o  m
        sb.append(str).append("\n\n");
    }
    return sb.toString();
}

From source file:eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler.java

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 *//*w w w .j  a v a2 s .co  m*/
@Override
protected String getSourceExpressionAsCQL() {
    ListMultimap<String, ? extends Entity> sourceEntities = propertyCell.getSource();
    Property anchor = null;
    if (sourceEntities != null && sourceEntities.containsKey(ENTITY_ANCHOR)) {
        anchor = (Property) sourceEntities.get(ENTITY_ANCHOR).get(0);
    }

    ListMultimap<String, ParameterValue> parameters = propertyCell.getTransformationParameters();
    List<ParameterValue> valueParams = parameters.get(PARAMETER_VALUE);
    String value = valueParams.get(0).getStringRepresentation();

    String ocql = null;
    if (anchor != null) {
        // TODO: generalize this code
        String anchorAttr = anchor.getDefinition().getDefinition().getName().getLocalPart();
        ocql = "if_then_else(isNull(" + anchorAttr + "), Expression.NIL, '" + value + "')";
        ocql = getConditionalExpression(anchor.getDefinition(), ocql);
    } else {
        ocql = "'" + value + "'";
    }

    return ocql;
}

From source file:com.opengamma.strata.calc.runner.CalculationTasks.java

private static List<CalculationTask> createTargetTasks(CalculationTarget target, int rowIndex,
        CalculationFunction<?> function, List<Column> columns) {

    // create the cells and group them
    ListMultimap<CalculationParameters, CalculationTaskCell> grouped = ArrayListMultimap.create();
    for (int colIndex = 0; colIndex < columns.size(); colIndex++) {
        Column column = columns.get(colIndex);
        Measure measure = column.getMeasure();

        ReportingCurrency reportingCurrency = column.getReportingCurrency().orElse(ReportingCurrency.NATURAL);
        CalculationTaskCell cell = CalculationTaskCell.of(rowIndex, colIndex, measure, reportingCurrency);
        // group to find cells that can be shared, with same mappings and params (minus reporting currency)
        CalculationParameters params = column.getParameters().filter(target, measure);
        grouped.put(params, cell);/*from   w  ww.  j  av a  2 s.c  o m*/
    }

    // build tasks
    ImmutableList.Builder<CalculationTask> taskBuilder = ImmutableList.builder();
    for (CalculationParameters params : grouped.keySet()) {
        taskBuilder.add(CalculationTask.of(target, function, params, grouped.get(params)));
    }
    return taskBuilder.build();
}

From source file:eu.esdihumboldt.hale.common.align.model.functions.merge.MergeMigrator.java

private void updateProperties(ListMultimap<String, ParameterValue> modParams, AlignmentMigration migration,
        TypeDefinition sourceType, String parameterProperty, SimpleLog log) {
    List<ParameterValue> params = modParams.get(parameterProperty);

    List<ParameterValue> newParams = params.stream()
            .map(property -> convertProperty(property, migration, sourceType, log))
            .collect(Collectors.toList());
    params.clear();// w  ww.ja v a 2  s.  com
    params.addAll(newParams);
}

From source file:uk.ac.cam.cl.dtg.picky.client.binding.EntryTreeBinding.java

private CheckBoxTreeItem<String> toTree(ListMultimap<String, String> selection) {
    CheckBoxTreeItem<String> root = new CheckBoxTreeItem<String>("root");

    for (String key : selection.keySet()) {
        List<String> options = new ArrayList<>(new HashSet<>(selection.get(key)));
        Collections.sort(options);

        CheckBoxTreeItem<String> keyRoot = new CheckBoxTreeItem<String>(key);
        keyRoot.setExpanded(true);//from  w  w  w.ja va  2 s . c o  m

        List<CheckBoxTreeItem<String>> nodes = options.stream().map(o -> new CheckBoxTreeItem<String>(o))
                .collect(Collectors.toList());
        keyRoot.getChildren().addAll(nodes);
        root.getChildren().add(keyRoot);
    }

    return root;
}

From source file:eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler.java

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 *//*ww w . j av a 2 s .  c o  m*/
@Override
protected String getSourceExpressionAsCQL() {
    ListMultimap<String, ParameterValue> parameters = propertyCell.getTransformationParameters();
    String pattern = parameters.get(PARAMETER_PATTERN).get(0).as(String.class);

    List<int[]> startEndList = new ArrayList<int[]>();
    List<String> varList = new ArrayList<String>();
    Matcher m = VARIABLE_PATTERN.matcher(pattern);
    while (m.find()) {
        int[] startEnd = new int[2];
        startEnd[0] = m.start(); // index of '{' character
        startEnd[1] = m.end(); // index of '}' character
        startEndList.add(startEnd);
        varList.add(m.group(1)); // the variable name, without curly braces
    }

    // list of string to be concatenated, either string constants or
    // variable names
    String[] partsToConcat = new String[varList.size() * 2 + 1];
    int lastPos = 0;
    for (int i = 0; i < varList.size(); i++) {
        int[] startEnd = startEndList.get(i);
        String var = varList.get(i);

        String textBeforeVar = pattern.substring(lastPos, startEnd[0]);
        if (textBeforeVar != null && textBeforeVar.length() == 0) {
            textBeforeVar = null;
        }
        partsToConcat[i * 2] = (textBeforeVar != null) ? "'" + textBeforeVar + "'" : null;
        partsToConcat[i * 2 + 1] = var;

        lastPos = startEnd[1];
    }
    // add text after last variable
    String textAfterLastVar = pattern.substring(lastPos, pattern.length());
    if (textAfterLastVar != null && textAfterLastVar.length() == 0) {
        textAfterLastVar = null;
    }
    partsToConcat[partsToConcat.length - 1] = (textAfterLastVar != null) ? "'" + textAfterLastVar + "'" : null;

    String strConcatExpr = "";
    int lastPartIdx = 0;
    while (lastPartIdx < partsToConcat.length) {
        if (lastPartIdx == 0) {
            // initialize strConcatExpr
            for (int notNullIdx = lastPartIdx; notNullIdx < partsToConcat.length; notNullIdx++) {
                if (partsToConcat[notNullIdx] != null) {
                    strConcatExpr = partsToConcat[notNullIdx];
                    lastPartIdx = notNullIdx;
                    break;
                }
            }
        }

        String secondArgument = null;
        for (int notNullIdx = lastPartIdx + 1; notNullIdx < partsToConcat.length; notNullIdx++) {
            if (partsToConcat[notNullIdx] != null) {
                secondArgument = partsToConcat[notNullIdx];
                lastPartIdx = notNullIdx;
                break;
            }
        }

        if (secondArgument != null) {
            strConcatExpr = "strConcat(" + strConcatExpr + ", " + secondArgument + ")";
        } else {
            // no second argument could be found: should stop here
            break;
        }
    }

    // if properties used in the expression have conditions defined on them,
    // expression should be evaluated only if all conditions are met
    if (propertyCell.getSource() != null) {
        List<? extends Entity> sourceEntities = propertyCell.getSource()
                .get(FormattedStringFunction.ENTITY_VARIABLE);

        if (sourceEntities != null) {
            for (Entity source : sourceEntities) {
                PropertyEntityDefinition propEntityDef = (PropertyEntityDefinition) source.getDefinition();
                strConcatExpr = getConditionalExpression(propEntityDef, strConcatExpr);
            }
        }
    }

    return strConcatExpr;
}

From source file:org.opennms.netmgt.collectd.WsManCollector.java

/**
 * Used to build a {@link CollectionSet} from the enumeration results.
 *//*  w  w  w .j a v a 2  s. c  om*/
public static void processEnumerationResults(Group group, CollectionSetBuilder builder, Resource resource,
        List<Node> nodes) {
    for (Node node : nodes) {
        final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node);
        LOG.debug("Element values: {}", elementValues);

        // Associate the values with the configured attributes
        for (Attrib attrib : group.getAttrib()) {
            AttributeType type = AttributeType.getByName(attrib.getType());
            if (type == null) {
                LOG.error(
                        "Unsupported attribute type: {} for attribute: {} in group: {}. Value will be skipped.",
                        attrib.getType(), attrib.getName(), group.getName());
                continue;
            }

            if (attrib.getFilter() != null
                    && !ResponseHandlingUtils.matchesFilter(attrib.getFilter(), elementValues)) {
                continue;
            }

            String valueAsString = null;
            final List<String> attributeValues = elementValues.get(attrib.getName());
            if (attributeValues.size() > 1 && attrib.getIndexOf() != null) {
                try {
                    int index = ResponseHandlingUtils.getMatchingIndex(attrib.getIndexOf(), elementValues);
                    valueAsString = attributeValues.get(index);
                } catch (NoSuchElementException e) {
                    LOG.warn("No index was matched by index-of rule '{}' for attribute {} with values: {}.",
                            attrib.getIndexOf(), attrib.getName(), elementValues);
                }
            } else {
                // Grab the first value, defaulting to null is there are no values
                valueAsString = Iterables.getFirst(elementValues.get(attrib.getName()), null);
            }

            if (valueAsString == null) {
                LOG.warn("No value found for attribute: {} in group: {}", attrib.getName(), group.getName());
                continue;
            }

            if (type.isNumeric()) {
                Double value;
                try {
                    value = Double.parseDouble(valueAsString);
                } catch (NumberFormatException e) {
                    LOG.warn(
                            "Value '{}' for attribute: {} in group: {} could not be parsed into a number. Value will be skipped.",
                            valueAsString, attrib.getName(), group.getName());
                    value = Double.NaN;
                }
                builder.withNumericAttribute(resource, group.getName(), attrib.getAlias(), value, type);
            } else {
                builder.withStringAttribute(resource, group.getName(), attrib.getAlias(), valueAsString);
            }
        }
    }
}