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.cst.functions.geometric.interiorpoint.InteriorPoint.java

@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, PropertyValue> variables, String resultName,
        PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log)
        throws TransformationException, NoResultException {
    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();

    GeometryProperty<?> result = calculateInteriorPoint(inputValue);

    // try to yield a result compatible to the target
    TypeDefinition targetType = resultProperty.getDefinition().getPropertyType();
    // TODO check element type?
    Class<?> binding = targetType.getConstraint(Binding.class).getBinding();
    if (Geometry.class.isAssignableFrom(binding) && binding.isAssignableFrom(result.getClass())) {
        return result.getGeometry();
    }//from   ww  w .  j  ava  2 s  .  c o  m
    return result;
}

From source file:eu.esdihumboldt.cst.functions.geometric.Centroid.java

@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, PropertyValue> variables, String resultName,
        PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log)
        throws TransformationException, NoResultException {
    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();

    GeometryProperty<?> result = calculateCentroid(inputValue);

    // try to yield a result compatible to the target
    TypeDefinition targetType = resultProperty.getDefinition().getPropertyType();
    // TODO check element type?
    Class<?> binding = targetType.getConstraint(Binding.class).getBinding();
    if (Geometry.class.isAssignableFrom(binding) && binding.isAssignableFrom(result.getClass())) {
        return result.getGeometry();
    }//  w w w . j  av  a  2 s  .c om
    return result;
}

From source file:eu.esdihumboldt.cst.functions.geometric.CalculateLength.java

/**
 * @see eu.esdihumboldt.hale.common.align.transformation.function.impl.AbstractSingleTargetPropertyTransformation#evaluate(java.lang.String,
 *      eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
 *      com.google.common.collect.ListMultimap, java.lang.String,
 *      eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition,
 *      java.util.Map,/*w w  w  . j  a  v a  2  s.  com*/
 *      eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
 */
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, PropertyValue> variables, String resultName,
        PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log)
        throws TransformationException, NoResultException {

    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();

    // depth first traverser that on cancel continues traversal but w/o the
    // children of the current object
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);

    GeometryFinder geoFind = new GeometryFinder(null);

    traverser.traverse(inputValue, geoFind);

    List<GeometryProperty<?>> geoms = geoFind.getGeometries();

    Geometry geom = null;

    if (geoms.size() > 1) {

        int length = 0;

        for (GeometryProperty<?> geoProp : geoms) {
            length += geoProp.getGeometry().getLength();
        }

        // TODO: warn ?!

        return length;

    } else {
        geom = geoms.get(0).getGeometry();
    }

    if (geom != null) {
        return geom.getLength();
    } else {
        throw new TransformationException("Geometry for calculate length could not be retrieved.");
    }

}

From source file:eu.esdihumboldt.cst.functions.geometric.CalculateArea.java

/**
 * @see eu.esdihumboldt.hale.common.align.transformation.function.impl.AbstractSingleTargetPropertyTransformation#evaluate(java.lang.String,
 *      eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
 *      com.google.common.collect.ListMultimap, java.lang.String,
 *      eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition,
 *      java.util.Map,//from   w w  w .  j  a  v  a  2  s.co m
 *      eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
 */
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, PropertyValue> variables, String resultName,
        PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log)
        throws TransformationException, NoResultException {

    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();

    // depth first traverser that on cancel continues traversal but w/o the
    // children of the current object
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);

    GeometryFinder geoFind = new GeometryFinder(null);

    traverser.traverse(inputValue, geoFind);

    List<GeometryProperty<?>> geoms = geoFind.getGeometries();

    Geometry geom = null;

    if (geoms.size() > 1) {

        int area = 0;

        for (GeometryProperty<?> geoProp : geoms) {
            area += geoProp.getGeometry().getArea();
        }

        // TODO: warn ?!

        return area;

    } else {
        geom = geoms.get(0).getGeometry();
    }

    if (geom != null) {
        return geom.getArea();
    } else {
        throw new TransformationException("Geometry for calculate area could not be retrieved.");
    }

}

From source file:org.sonar.server.qualityprofile.RegisterQualityProfiles.java

public void start() {
    Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register quality profiles");
    DbSession session = dbClient.openSession(false);
    try {/*ww w . j a  v  a2 s  .  c o  m*/
        List<ActiveRuleChange> changes = new ArrayList<>();
        ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage();
        for (String language : profilesByLanguage.keySet()) {
            List<RulesProfile> defs = profilesByLanguage.get(language);
            if (verifyLanguage(language, defs)) {
                changes.addAll(registerProfilesForLanguage(session, language, defs));
            }
        }
        activeRuleIndexer.index(changes);
        profiler.stopDebug();

    } finally {
        session.close();
    }
}

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

private static <E extends Element> HighlightResult<E> getResult(Collection<E> elements,
        HighlightConditionList highlightConditions) {
    List<Color> colorList = new ArrayList<>();
    ListMultimap<E, Double> alphaValues = ArrayListMultimap.create();
    Map<E, Double> thicknessValues = new LinkedHashMap<>();
    SetMultimap<E, String> labelLists = LinkedHashMultimap.create();
    Map<E, NamedShape> shapes = new LinkedHashMap<>();

    elements.forEach(e -> thicknessValues.put(e, 0.0));

    for (HighlightCondition condition : highlightConditions.getConditions()) {
        if (condition.isInvisible()) {
            continue;
        }// w ww .  j  a  v  a2  s.co  m

        Map<E, Double> values = condition.getValues(elements);

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

            for (E e : elements) {
                List<Double> alphas = alphaValues.get(e);

                if (!highlightConditions.isPrioritizeColors() || alphas.isEmpty()
                        || Collections.max(alphas) == 0.0) {
                    alphas.add(values.get(e));
                } else {
                    alphas.add(0.0);
                }
            }
        }

        if (condition.isUseThickness()) {
            elements.forEach(e -> thicknessValues.put(e, thicknessValues.get(e) + values.get(e)));
        }

        if (condition.getLabelProperty() != null) {
            String property = condition.getLabelProperty();

            for (E e : elements) {
                if (values.get(e) != 0.0 && e.getProperties().get(property) != null) {
                    labelLists.put(e, toString(e.getProperties().get(property)));
                }
            }
        }

        if (condition.getShape() != null) {
            for (E e : elements) {
                if (values.get(e) != 0.0 && !shapes.containsKey(e)) {
                    shapes.put(e, condition.getShape());
                }
            }
        }
    }

    Map<E, Paint> colors = new LinkedHashMap<>();
    Map<E, String> labels = new LinkedHashMap<>();

    Multimaps.asMap(alphaValues).forEach((e, alphas) -> colors.put(e, CanvasUtils
            .mixColors(e instanceof Edge ? Color.BLACK : Color.WHITE, colorList, alphas, e instanceof Edge)));
    Multimaps.asMap(labelLists).forEach((e, labelList) -> labels.put(e, Joiner.on("/").join(labelList)));

    HighlightResult<E> result = new HighlightResult<>();

    result.colors = colors;
    result.thicknessValues = thicknessValues;
    result.labels = labels;
    result.shapes = shapes;

    return result;
}

From source file:eu.esdihumboldt.cst.functions.core.join.JoinHandler.java

/**
 * @see eu.esdihumboldt.hale.common.align.transformation.function.InstanceHandler#partitionInstances(eu.esdihumboldt.hale.common.instance.model.InstanceCollection,
 *      java.lang.String,//  w w w.  ja v a  2 s .c om
 *      eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
 *      com.google.common.collect.ListMultimap, java.util.Map,
 *      eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
 */
@Override
public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances,
        String transformationIdentifier, TransformationEngine engine,
        ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters,
        TransformationLog log) throws TransformationException {
    if (transformationParameters == null || !transformationParameters.containsKey(PARAMETER_JOIN)
            || transformationParameters.get(PARAMETER_JOIN).isEmpty()) {
        throw new TransformationException("No join parameter defined");
    }

    JoinParameter joinParameter = transformationParameters.get(PARAMETER_JOIN).get(0).as(JoinParameter.class);

    String validation = joinParameter.validate();
    if (validation != null)
        throw new TransformationException("Join parameter invalid: " + validation);

    List<TypeEntityDefinition> types = joinParameter.getTypes();

    JoinDefinition joinDefinition = JoinUtil.getJoinDefinition(joinParameter);

    // JoinProperty -> (Value -> Collection<Reference>)
    Map<PropertyEntityDefinition, Multimap<Object, InstanceReference>> index = new HashMap<>();
    for (PropertyEntityDefinition property : joinDefinition.properties.values())
        index.put(property, ArrayListMultimap.<Object, InstanceReference>create());

    // remember instances of first type to start join afterwards
    Collection<InstanceReference> startInstances = new LinkedList<InstanceReference>();

    // iterate once over all instances
    ResourceIterator<Instance> iterator = instances.iterator();
    try {
        while (iterator.hasNext()) {
            Instance next = iterator.next();

            // remember instances of first type
            if (next.getDefinition().equals(types.get(0).getDefinition())) {
                startInstances.add(instances.getReference(next));
            }

            // fill index over needed properties
            for (PropertyEntityDefinition property : joinDefinition.properties.get(next.getDefinition())) {
                // XXX what about null? for now ignore null values
                // XXX how to treat multiple values? must all be equal (in
                // order?) or only one?
                Collection<Object> values = AlignmentUtil.getValues(next, property, true);
                if (values != null && !values.isEmpty()) {
                    // XXX take only first value for now
                    index.get(property).put(valueProcessor.processValue(values.iterator().next(), property),
                            instances.getReference(next));
                }
            }
        }
    } finally {
        iterator.close();
    }

    return new JoinIterator(instances, startInstances, joinDefinition.directParent, index,
            joinDefinition.joinTable, valueProcessor);
}

From source file:org.eclipse.xtext.xbase.typesystem.override.RawResolvedFeatures.java

@Override
public List<JvmFeature> getAllFeatures() {
    if (!allFeaturesComputed) {
        ListMultimap<String, JvmFeature> featureIndex = computeAllFeatures();
        for (String simpleName : featureIndex.keySet()) {
            this.featureIndex.put(simpleName, Lists.newArrayList(featureIndex.get(simpleName)));
        }/*from   w w w .  ja  v a  2s.c o m*/
        allFeaturesComputed = true;
    }
    List<JvmFeature> result = Lists.newArrayList();
    for (List<JvmFeature> list : featureIndex.values()) {
        result.addAll(list);
    }
    return result;
}

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

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    PrintWriter writer = null;/*from   w  w w.j  a  v a2s.c  om*/
    try {
        ListMultimap<String, SubjectMug> validationResults = read(inputHmlFile);
        writer = writer(outputFile);
        for (String sample : validationResults.keySet()) {
            for (SubjectMug subjectResults : validationResults.get(sample)) {
                writer.println(sample + "\t" + subjectResults.minimumDifference());
            }
        }
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
            // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
            // ignore
        }
    }
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.CassandraCluster.java

@NotNull
static List<String> hasResources(@NotNull final Protos.Offer offer, @NotNull final TaskResources taskResources,
        @NotNull final Map<String, Long> portMapping, @NotNull final String mesosRole) {
    final List<String> errors = newArrayList();
    final ListMultimap<String, Protos.Resource> availableResources = resourcesForRoleAndOffer(mesosRole, offer);

    final double availableCpus = maxResourceValueDouble(availableResources.get("cpus")).or(0d);
    final long availableMem = maxResourceValueLong(availableResources.get("mem")).or(0l);
    final long availableDisk = maxResourceValueLong(availableResources.get("disk")).or(0l);

    if (availableCpus < taskResources.getCpuCores()) {
        errors.add(String.format("Not enough cpu resources for role %s. Required %s only %s available",
                mesosRole, String.valueOf(taskResources.getCpuCores()), String.valueOf(availableCpus)));
    }/*from w  w  w. j  a  v a2s .co  m*/
    if (availableMem < taskResources.getMemMb()) {
        errors.add(String.format("Not enough mem resources for role %s. Required %d only %d available",
                mesosRole, taskResources.getMemMb(), availableMem));
    }
    if (availableDisk < taskResources.getDiskMb()) {
        errors.add(String.format("Not enough disk resources for role %s. Required %d only %d available",
                mesosRole, taskResources.getDiskMb(), availableDisk));
    }

    ImmutableSet<Long> ports = from(availableResources.get("ports")).transformAndConcat(resourceToPortSet())
            .toSet();

    for (final Map.Entry<String, Long> entry : portMapping.entrySet()) {
        final String key = entry.getKey();
        final Long value = entry.getValue();
        if (!ports.contains(value)) {
            errors.add(String.format("Unavailable port %d(%s) for role %s. %d other ports available", value,
                    key, mesosRole, ports.size()));
        }
    }
    return errors;
}