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

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

Introduction

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

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:com.proofpoint.jmx.JmxInspector.java

@Inject
public JmxInspector(Injector injector) throws Exception {
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectInstance> instances = mBeanServer.queryMBeans(null, null);
    Multimap<String, String> nameMap = ArrayListMultimap.create();
    for (ObjectInstance i : instances) {
        nameMap.put(i.getClassName(), i.getObjectName().getCanonicalName());
    }// w w w.java2s. c om

    ImmutableSortedSet.Builder<InspectorRecord> builder = ImmutableSortedSet.naturalOrder();
    GuiceInjectorIterator injectorIterator = new GuiceInjectorIterator(injector);
    for (Class<?> clazz : injectorIterator) {
        addConfig(nameMap, clazz, builder);
    }

    inspectorRecords = builder.build();
}

From source file:org.jclouds.sts.options.AssumeRoleOptions.java

@Override
public Multimap<String, String> buildFormParameters() {
    Multimap<String, String> params = super.buildFormParameters();
    if (externalId != null)
        params.put("ExternalId", externalId.toString());
    if (durationSeconds != null)
        params.put("DurationSeconds", durationSeconds.toString());
    if (policy != null)
        params.put("Policy", policy);
    return params;
}

From source file:com.elytradev.thermionics.block.BlockPotStill.java

@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
    Multimap<String, AttributeModifier> modifiers = HashMultimap.create();
    if (slot == EntityEquipmentSlot.HEAD) {
        modifiers.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(
                UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150"), "Armor modifier", 3D, 0));

    }/*from  w w  w  .j av a2  s . c  o  m*/

    return modifiers;
}

From source file:org.jclouds.aws.s3.options.PutBucketOptions.java

@Override
public Multimap<String, String> buildRequestHeaders() {
    checkState(headerTag != null, "headerTag should have been injected!");
    Multimap<String, String> returnVal = LinkedHashMultimap.create();
    for (Entry<String, String> entry : headers.entries()) {
        returnVal.put(entry.getKey().replace("aws", headerTag), entry.getValue());
    }/*from www .  ja  va  2s .c o  m*/
    return returnVal;
}

From source file:org.opennms.features.topology.plugins.topo.linkd.internal.CdpLinkStatusProvider.java

@Override
protected List<EdgeAlarmStatusSummary> getEdgeAlarmSummaries(List<Integer> linkIds) {

    List<CdpTopologyLink> cdpLinks = getCdpLinkDao().findLinksForTopologyByIds(linkIds.toArray(new Integer[0]));
    Multimap<String, EdgeAlarmStatusSummary> summaryMap = HashMultimap.create();
    for (CdpTopologyLink link : cdpLinks) {
        summaryMap.put(link.getSrcNodeId() + ":" + link.getSrcIfIndex(),
                new EdgeAlarmStatusSummary(link.getSourceId(), link.getTargetId(), null));
    }//from   w  ww .j a  v a  2  s.co m

    List<OnmsAlarm> alarms = getLinkDownAlarms();
    for (OnmsAlarm alarm : alarms) {
        String key = alarm.getNodeId() + ":" + alarm.getIfIndex();
        if (summaryMap.containsKey(key)) {
            Collection<EdgeAlarmStatusSummary> summaries = summaryMap.get(key);
            for (EdgeAlarmStatusSummary summary : summaries) {
                summary.setEventUEI(alarm.getUei());
            }
        }
    }

    return new ArrayList<>(summaryMap.values());
}

From source file:com.spotify.heroic.cluster.NodeRegistry.java

private Multimap<Map<String, String>, ClusterNode> buildShards(List<ClusterNode> entries) {
    final Multimap<Map<String, String>, ClusterNode> shards = LinkedListMultimap.create();

    for (final ClusterNode e : entries) {
        shards.put(e.metadata().getTags(), e);
    }/* w  ww.jav a 2  s . c  om*/

    return shards;
}

From source file:com.google.gapid.views.Formatter.java

/**
 * @return empty list if not a constant, single value for constants, more values, for bitfileds.
 *///ww w  .  ja v a 2s .  c o  m
public static Collection<Constant> findConstant(SnippetObject obj, Primitive type) {
    final ConstantSet constants = ConstantSet.lookup(type);
    if (constants == null || constants.getEntries().length == 0) {
        return Collections.emptyList();
    }

    // first, try and find exact match
    List<Constant> byValue = constants.getByValue(obj.getObject());
    if (byValue != null && byValue.size() != 0) {
        if (byValue.size() == 1) {
            // perfect, we have just 1 match
            return byValue;
        }
        // try and find the best match
        Labels labels = Labels.fromSnippets(obj.getSnippets());
        Constant result = disambiguate(byValue, labels);
        return result == null ? Collections.emptyList() : ImmutableList.of(result);
    }

    // we can not find any exact match,
    // but for a number, maybe we can find a combination of constants that match (bit flags)
    Object value = obj.getObject();
    if (!(value instanceof Number) || value instanceof Double || value instanceof Float) {
        return Collections.emptyList();
    }

    long valueNumber = ((Number) value).longValue();
    long leftToFind = valueNumber;
    Multimap<Number, Constant> resultMap = ArrayListMultimap.create();

    for (Constant constant : constants.getEntries()) {
        long constantValue = ((Number) constant.getValue()).longValue();
        if (Long.bitCount(constantValue) == 1 && (valueNumber & constantValue) != 0) {
            resultMap.put(constantValue, constant);
            leftToFind &= ~constantValue; // remove bit
        }
    }

    // we did not find enough flags to cover this constant
    if (leftToFind != 0) {
        return Collections.emptyList();
    }

    // we found exactly 1 of each constant to cover the whole value
    if (resultMap.keySet().size() == resultMap.size()) {
        return resultMap.values();
    }

    // we have more than 1 matching constant per flag to we need to disambiguate
    Labels labels = Labels.fromSnippets(obj.getSnippets());
    for (Number key : resultMap.keySet()) {
        Collection<Constant> flagConstants = resultMap.get(key);
        if (flagConstants.size() == 1) {
            // perfect, we only have 1 value for this
            continue;
        }

        Constant con = disambiguate(flagConstants, labels);
        if (con != null) {
            // we have several values, but we found 1 to use
            resultMap.replaceValues(key, ImmutableList.of(con));
        } else {
            // we have several values and we don't know what one to use
            return Collections.emptyList();
        }
    }
    // assert all constants are disambiguated now
    assert resultMap.keySet().size() == resultMap.size();
    return resultMap.values();
}

From source file:it.sayservice.platform.smartplanner.otp.schedule.TransitTimes.java

public void buildStopIds() {
    BucketSet mergedBs = new BucketSet();
    Multimap<String, TripTimes> map = ArrayListMultimap.create();
    for (TripTimes tt : times) {
        map.put(tt.getRecurrence(), tt);
    }/*from  ww  w  . j a v  a2 s . c o  m*/

    List<BucketSet> bss = new ArrayList<BucketSet>();
    BucketSet bs;
    for (String key : map.keySet()) {
        bs = new BucketSet();
        List<TripTimes> ttl = (List<TripTimes>) map.get(key);

        Collections.sort(ttl, new Comparator<TripTimes>() {
            @Override
            public int compare(TripTimes o1, TripTimes o2) {
                return o2.getTripTimes().size() - o1.getTripTimes().size();
            }
        });

        for (TripTimes tt : ttl) {
            List<Bucket> buckets = new ArrayList<Bucket>();
            for (TripTimeEntry sch : tt.getTripTimes()) {
                Bucket b = sch.toBucket();
                buckets.add(b);
            }
            bs.merge(buckets);
        }
        bss.add(bs);
    }

    for (BucketSet bs0 : bss) {
        mergedBs.merge(bs0.getBuckets());
    }

    stopIds = mergedBs.getIds();
}

From source file:com.ardor3d.util.TextureManager.java

@SuppressWarnings("unchecked")
private static Multimap<Object, Integer> gatherGCdIds() {
    Multimap<Object, Integer> idMap = null;
    // Pull all expired textures from ref queue and add to an id multimap.
    ContextIdReference<TextureKey> ref;
    Integer id;/*from   w ww . ja  v a2 s. c  o m*/
    while ((ref = (ContextIdReference<TextureKey>) _textureRefQueue.poll()) != null) {
        // lazy init
        if (idMap == null) {
            idMap = ArrayListMultimap.create();
        }
        if (Constants.useMultipleContexts) {
            final Set<Object> contextObjects = ref.getContextObjects();
            for (final Object o : contextObjects) {
                id = ref.getValue(o);
                if (id != null && id.intValue() != 0) {
                    // Add id to map
                    idMap.put(o, id);
                }
            }
        } else {
            id = ref.getValue(null);
            if (id != null && id.intValue() != 0) {
                idMap.put(ContextManager.getCurrentContext().getGlContextRep(), id);
            }
        }
        ref.clear();
    }
    return idMap;
}

From source file:org.jclouds.elb.options.ListLoadBalancersOptions.java

@Override
public Multimap<String, String> buildFormParameters() {
    Multimap<String, String> params = super.buildFormParameters();
    if (marker != null)
        params.put("Marker", marker.toString());
    if (names.size() > 0) {
        int nameIndex = 1;
        for (String name : names) {
            params.put("LoadBalancerNames.member." + nameIndex, name);
            nameIndex++;//from ww  w. ja  va  2 s. c  om
        }
    }
    return params;
}