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

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

Introduction

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

Prototype

public static <K, V> LinkedListMultimap<K, V> create() 

Source Link

Document

Creates a new, empty LinkedListMultimap with the default initial capacity.

Usage

From source file:com.ansorgit.plugins.bash.lang.psi.util.BashAbstractProcessor.java

protected final void storeResult(PsiElement element, Integer rating) {
    if (results == null) {
        results = LinkedListMultimap.create();
    }/*w w w . jav  a  2  s.com*/

    results.put(rating, element);
}

From source file:org.apache.hadoop.hive.ql.exec.tez.CustomEdgeConfiguration.java

@Override
public void readFields(DataInput in) throws IOException {
    this.vertexInited = in.readBoolean();
    this.numBuckets = in.readInt();
    if (this.vertexInited == false) {
        return;/*from  ww w.  j a v a 2  s.  co  m*/
    }

    int count = in.readInt();
    bucketToTaskMap = LinkedListMultimap.create();
    for (int i = 0; i < count; i++) {
        bucketToTaskMap.put(in.readInt(), in.readInt());
    }

    if (count != bucketToTaskMap.size()) {
        throw new IOException("Was not a clean translation. Some records are missing");
    }
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.ListMultimapJsonDeserializer.java

@Override
protected ListMultimap<K, V> newMultimap() {
    return LinkedListMultimap.create();
}

From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java

public static <K, V> ListMultimap<K, V> listToListMultimap(List<Pair<K, V>> list) {
    ListMultimap<K, V> result = LinkedListMultimap.create();
    for (Pair<K, V> p : list) {
        // High cost, only check with assertions enabled
        assert !result.containsEntry(p.lhSide, p.rhSide);
        result.put(p.lhSide, p.rhSide);//from   w  ww .j  a va 2s.  co m
    }
    return result;
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchyBuilder.java

public HierarchyBuilder(Set<HierarchicalCluster> clusters, SortedSet<ClusterPair> distances) {
    this.clusters = clusters;
    this.distances = distances;

    this.distancesMap = LinkedListMultimap.create();
    for (ClusterPair distance : distances) {
        this.distancesMap.put(distance.hashCode(), distance);
    }/*from   w w  w.  ja va  2s  .c o m*/
}

From source file:org.gradle.platform.base.internal.dependents.DefaultDependentBinariesResolver.java

private DependentBinariesResolvedResult mergeResults(Collection<DependentBinariesResolvedResult> results) {
    DependentBinariesResolvedResult first = results.iterator().next();
    if (results.size() == 1) {
        return first;
    }//from   w  ww.j a  v  a  2 s  . c om
    boolean hasNotBuildables = false;
    boolean hasTestSuites = false;
    LinkedListMultimap<LibraryBinaryIdentifier, DependentBinariesResolvedResult> index = LinkedListMultimap
            .create();
    List<DependentBinariesResolvedResult> allChildren = Lists.newArrayList();
    for (DependentBinariesResolvedResult result : results) {
        if (!result.isBuildable()) {
            hasNotBuildables = true;
        }
        if (result.isTestSuite()) {
            hasTestSuites = true;
        }
        allChildren.addAll(result.getChildren());
        for (DependentBinariesResolvedResult child : result.getChildren()) {
            index.put(child.getId(), child);
        }
    }
    List<DependentBinariesResolvedResult> children = Lists.newArrayList();
    for (Collection<DependentBinariesResolvedResult> childResults : index.asMap().values()) {
        children.add(mergeResults(childResults));
    }
    return new DefaultDependentBinariesResolvedResult(first.getId(), first.getProjectScopedName(),
            !hasNotBuildables, hasTestSuites, children);
}

From source file:com.google.gerrit.acceptance.EventRecorder.java

public EventRecorder(DynamicSet<UserScopedEventListener> eventListeners, final IdentifiedUser user) {
    recordedEvents = LinkedListMultimap.create();

    eventListenerRegistration = eventListeners.add(new UserScopedEventListener() {
        @Override//w  w w  .j  a  va 2s  .c o m
        public void onEvent(Event e) {
            if (e instanceof ReviewerDeletedEvent) {
                recordedEvents.put(ReviewerDeletedEvent.TYPE, (ReviewerDeletedEvent) e);
            } else if (e instanceof RefEvent) {
                RefEvent event = (RefEvent) e;
                String key = refEventKey(event.getType(), event.getProjectNameKey().get(), event.getRefName());
                recordedEvents.put(key, event);
            }
        }

        @Override
        public CurrentUser getUser() {
            return user;
        }
    });
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchyBuilderWithMargin.java

public HierarchyBuilderWithMargin(Set<HierarchicalCluster> clusters, SortedSet<ClusterPair> distances) {
    this.clusters = clusters;
    this.distances = distances;

    this.distancesMap = LinkedListMultimap.create();
    for (ClusterPair distance : distances) {
        this.distancesMap.put(distance.hashCode(), distance);
    }/*w w w .j a  v  a2 s. com*/
}

From source file:com.eucalyptus.cluster.callback.reporting.DefaultAbsoluteMetricConverter.java

protected static List<AbsoluteMetricQueueItem> dealWithAbsoluteMetrics(
        Iterable<AbsoluteMetricQueueItem> dataBatch) {
    List<AbsoluteMetricQueueItem> regularMetrics = new ArrayList<AbsoluteMetricQueueItem>();
    // We need to do some sorting to allow fewer db lookups.  There is also logic for different metric types, so they will be sorted now.

    // Some points do not actually go in.  If a data point represents an absolute value, the first one does not go in.
    // Also, some data points are added while we go through the list (derived metrics)

    // Deal with the absolute metrics
    // CPUUtilization
    // VolumeReadOps
    // VolumeWriteOps
    // VolumeConsumedReadWriteOps
    // VolumeReadBytes
    // VolumeWriteBytes
    // VolumeTotalReadTime
    // VolumeTotalWriteTime
    // VolumeTotalReadWriteTime (used to calculate VolumeIdleTime)
    // DiskReadOps
    // DiskWriteOps
    // DiskReadBytes
    // DiskWriteBytes
    // NetworkIn/*from ww  w .j  a  va  2 s.c  om*/
    // NetworkOut

    Multimap<String, AbsoluteMetricQueueItem> instanceMetricMap = LinkedListMultimap.create();
    Multimap<String, AbsoluteMetricQueueItem> volumeMetricMap = LinkedListMultimap.create();
    for (final AbsoluteMetricQueueItem item : dataBatch) {
        String nameSpace = item.getNamespace();
        MetricDatum datum = item.getMetricDatum();
        if (AbsoluteMetricHelper.AWS_EBS_NAMESPACE.equals(nameSpace)) {
            String volumeId = null;
            if ((datum.getDimensions() != null) && (datum.getDimensions().getMember() != null)) {
                for (Dimension dimension : datum.getDimensions().getMember()) {
                    if (AbsoluteMetricHelper.VOLUME_ID_DIM_NAME.equals(dimension.getName())) {
                        volumeId = dimension.getValue();
                    }
                }
            }
            if (volumeId == null) {
                continue; // this data point doesn't count.
            } else {
                volumeMetricMap.put(volumeId, item);
            }
        } else if (AbsoluteMetricHelper.AWS_EC2_NAMESPACE.equals(nameSpace)) {
            String instanceId = null;
            if ((datum.getDimensions() != null) && (datum.getDimensions().getMember() != null)) {
                for (Dimension dimension : datum.getDimensions().getMember()) {
                    if (AbsoluteMetricHelper.INSTANCE_ID_DIM_NAME.equals(dimension.getName())) {
                        instanceId = dimension.getValue();
                    }
                }
            }
            if (instanceId == null) {
                continue; // this data point doesn't count.
            } else {
                instanceMetricMap.put(instanceId, item);
            }
        } else {
            // not really an absolute metric, just leave it alone
            regularMetrics.add(item);
        }
    }
    for (List<String> partialVolumeKeySet : Iterables.partition(volumeMetricMap.keySet(),
            AbsoluteMetricQueue.ABSOLUTE_METRIC_NUM_DB_OPERATIONS_PER_TRANSACTION)) {
        try (final TransactionResource db = Entities.transactionFor(AbsoluteMetricHistory.class)) {
            int numVolumes = 0;
            for (String volumeId : partialVolumeKeySet) {
                AbsoluteMetricCache cache = new AbsoluteMetricCache(db);
                cache.load(AbsoluteMetricHelper.AWS_EBS_NAMESPACE, AbsoluteMetricHelper.VOLUME_ID_DIM_NAME,
                        volumeId);
                for (AbsoluteMetricQueueItem item : volumeMetricMap.get(volumeId)) {
                    String accountId = item.getAccountId();
                    String nameSpace = item.getNamespace();
                    MetricDatum datum = item.getMetricDatum();
                    if (AbsoluteMetricHelper.EBS_ABSOLUTE_METRICS.containsKey(datum.getMetricName())) {
                        // we check if the point below is a 'first' point, or maybe a point in the past.  Either case reject it.
                        if (!adjustAbsoluteVolumeStatisticSet(cache, datum, datum.getMetricName(),
                                AbsoluteMetricHelper.EBS_ABSOLUTE_METRICS.get(datum.getMetricName()), volumeId))
                            continue;
                    }
                    // special cases
                    // 1) VolumeThroughputPercentage -- this is 100% for provisioned volumes, and we need to insert a
                    //                                  data point for every timestamp that a volume event occurs.
                    //                                  To make sure we don't duplicate the effort, we choose one event at random, VolumeReadOps,
                    //                                  and create this new metric arbitrarily
                    if (AbsoluteMetricHelper.VOLUME_READ_OPS_METRIC_NAME.equals(datum.getMetricName())) { // special case
                        regularMetrics.add(
                                AbsoluteMetricHelper.createVolumeThroughputMetric(accountId, nameSpace, datum));
                    }
                    // 2) VolumeIdleTime -- we piggy back off of the metric we don't need VolumeTotalReadWriteTime, and convert it to VolumeIdleTime
                    if (AbsoluteMetricHelper.VOLUME_TOTAL_READ_WRITE_TIME_METRIC_NAME
                            .equals(datum.getMetricName())) {
                        AbsoluteMetricHelper.convertVolumeTotalReadWriteTimeToVolumeIdleTime(datum);
                    }
                    // 3) VolumeQueueLength -- this one comes in essentially correct, but we don't have a time duration for it, so we piggy back off
                    //                         the absolute metric framework
                    if (AbsoluteMetricHelper.VOLUME_QUEUE_LENGTH_METRIC_NAME.equals(datum.getMetricName())) {
                        if (!adjustAbsoluteVolumeQueueLengthStatisticSet(cache, datum, volumeId))
                            continue;
                    }
                    // Once here, our item has been appropriately adjusted.  Add it
                    regularMetrics.add(item);
                }
                numVolumes++;
                if (numVolumes
                        % AbsoluteMetricQueue.ABSOLUTE_METRIC_NUM_DB_OPERATIONS_UNTIL_SESSION_FLUSH == 0) {
                    Entities.flushSession(AbsoluteMetricHistory.class);
                    Entities.clearSession(AbsoluteMetricHistory.class);
                }
            }
            db.commit();
        }
    }
    for (List<String> partialInstanceKeySet : Iterables.partition(instanceMetricMap.keySet(),
            AbsoluteMetricQueue.ABSOLUTE_METRIC_NUM_DB_OPERATIONS_PER_TRANSACTION)) {
        try (final TransactionResource db = Entities.transactionFor(AbsoluteMetricHistory.class)) {
            int numInstances = 0;
            for (String instanceId : partialInstanceKeySet) {
                AbsoluteMetricCache cache = new AbsoluteMetricCache(db);
                cache.load(AbsoluteMetricHelper.AWS_EC2_NAMESPACE, AbsoluteMetricHelper.INSTANCE_ID_DIM_NAME,
                        instanceId);
                for (AbsoluteMetricQueueItem item : instanceMetricMap.get(instanceId)) {
                    String accountId = item.getAccountId();
                    String nameSpace = item.getNamespace();
                    MetricDatum datum = item.getMetricDatum();
                    if (AbsoluteMetricHelper.EC2_ABSOLUTE_METRICS.containsKey(datum.getMetricName())) {
                        if (!adjustAbsoluteInstanceStatisticSet(cache, datum, datum.getMetricName(),
                                AbsoluteMetricHelper.EC2_ABSOLUTE_METRICS.get(datum.getMetricName()),
                                instanceId))
                            continue;
                    } else if (AbsoluteMetricHelper.CPU_UTILIZATION_MS_ABSOLUTE_METRIC_NAME
                            .equals(datum.getMetricName())) { // special case
                        // we check if the point below is a 'first' point, or maybe a point in the past.  Either case reject it.
                        if (!adjustAbsoluteInstanceCPUStatisticSet(cache, datum,
                                AbsoluteMetricHelper.CPU_UTILIZATION_MS_ABSOLUTE_METRIC_NAME,
                                AbsoluteMetricHelper.CPU_UTILIZATION_METRIC_NAME, instanceId))
                            continue;
                    }
                    // Once here, our item has been appropriately adjusted.  Add it
                    regularMetrics.add(item);
                }
                numInstances++;
                if (numInstances
                        % AbsoluteMetricQueue.ABSOLUTE_METRIC_NUM_DB_OPERATIONS_UNTIL_SESSION_FLUSH == 0) {
                    Entities.flushSession(AbsoluteMetricHistory.class);
                    Entities.clearSession(AbsoluteMetricHistory.class);
                }
            }
            db.commit();
        }
    }
    return regularMetrics;
}

From source file:eu.tomylobo.routes.infrastructure.Node.java

public void save(Multimap<String, Multimap<String, String>> sections, String nodeName) {
    final String nodeSectionName = "node " + nodeName;
    final Multimap<String, String> nodeSection = LinkedListMultimap.create();

    Ini.saveVector(nodeSection, "position.%s", position);
    nodeSection.put("tension", String.valueOf(tension));
    nodeSection.put("bias", String.valueOf(bias));
    nodeSection.put("continuity", String.valueOf(continuity));

    sections.put(nodeSectionName, nodeSection);
}