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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:org.summer.ss.ide.builder.SourceRelativeFileSystemAccess.java

/**
 * Since sourceTraces are relative the URI has to be computed with the currentSource as context
 *///from  w  w  w.j  ava 2  s . c o  m
@Override
public void flushSourceTraces(String generatorName) throws CoreException {
    Multimap<URI, IPath> sourceTraces = getSourceTraces();
    if (sourceTraces != null) {
        Set<URI> keys = sourceTraces.keySet();
        for (URI uri : keys) {
            if (uri != null && currentSource != null) {
                Collection<IPath> paths = sourceTraces.get(uri);
                IFile sourceFile = currentSource.getFile(uri.toFileString());
                if (sourceFile.exists()) {
                    IPath[] tracePathArray = paths.toArray(new IPath[paths.size()]);
                    getTraceMarkers().installMarker(sourceFile, generatorName, tracePathArray);
                }
            }
        }
    }
    resetSourceTraces();
}

From source file:org.jclouds.joyent.sdc.v6_5.compute.SDCComputeService.java

@Override
protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
    Multimap<String, String> zoneToZoneAndGroupNames = orphanedGroupsByDatacenterId.apply(deadNodes);
    for (String datacenterId : zoneToZoneAndGroupNames.keySet()) {
        cleanupOrphanedKeysInZone(ImmutableSet.copyOf(zoneToZoneAndGroupNames.get(datacenterId)), datacenterId);
    }//from   w  ww  .  j  a v  a 2s.  c o m
}

From source file:springfox.documentation.spring.web.plugins.DefaultRequestHandlerCombiner.java

public List<RequestHandler> combine(List<RequestHandler> source) {
    List<RequestHandler> combined = new ArrayList<RequestHandler>();
    Multimap<String, RequestHandler> byPath = LinkedListMultimap.create();
    for (RequestHandler each : nullToEmptyList(source)) {
        byPath.put(patternsCondition(each).toString(), each);
    }/*from w  ww  .  ja  v a 2 s . c o  m*/
    for (String key : byPath.keySet()) {
        combined.addAll(combined(byPath.get(key)));
    }
    return byPatternsCondition().sortedCopy(combined);
}

From source file:org.apache.apex.malhar.lib.window.accumulation.PojoFullOuterJoin.java

@Override
public void addNonMatchingRightStream(Multimap<List<Object>, Object> rightStream,
        Map<String, PojoUtils.Getter> rightGettersStream, List<Object> result) {
    for (Object key : rightStream.keySet()) {
        if (outputToInputMap == null) {
            addNonMatchingResult(rightStream.get((List) key), rightGettersStream, result);
        } else {//  www . j a va2  s .c  o m
            for (Object obj : rightStream.get((List) key)) {
                Object o;
                try {
                    o = outClass.newInstance();
                } catch (Throwable e) {
                    throw Throwables.propagate(e);
                }
                for (Map.Entry<String, KeyValPair<STREAM, String>> entry : outputToInputMap.entrySet()) {
                    if (entry.getValue().getKey() == STREAM.RIGHT) {
                        setters.get(entry.getKey()).set(o,
                                rightGettersStream.get(entry.getValue().getValue()).get(obj));
                    }
                }
                result.add(o);
            }
        }
    }
}

From source file:org.terasology.utilities.gson.MultimapHandler.java

@Override
public JsonElement serialize(Multimap<String, V> src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject result = new JsonObject();
    List<String> keys = Lists.newArrayList(src.keys());
    Collections.sort(keys);/*  w  w w.ja  va 2s. com*/
    for (String key : keys) {
        Collection<V> values = src.get(key);
        if (values.size() > 1) {
            JsonArray array = new JsonArray();
            for (V value : values) {
                array.add(context.serialize(value));
            }
            result.add(key, array);
        } else if (values.size() == 1) {
            result.add(key, context.serialize(values.iterator().next()));
        } else {
            result.add(key, context.serialize(""));
        }
    }
    return result;
}

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

private Bucket findBestBucket(Bucket nb, Multimap<String, Bucket> newMap, Multimap<String, Bucket> oldMap,
        int lastIndex) {
    if (oldMap.containsKey(nb.getId()) && newMap.get(nb.getId()).size() == oldMap.get(nb.getId()).size()) {
        for (Bucket ob : oldMap.get(nb.getId())) {
            if (ob.getDup() == nb.getDup()) {
                return ob;
            }/*w ww . jav  a  2 s.c o  m*/
        }
    }
    List<Bucket> sameId = new ArrayList<Bucket>();
    for (Bucket ob : buckets) {
        if (ob.getId().equals(nb.getId())) {
            sameId.add(ob);
        }
    }
    Bucket best = null;
    int bestValue = Integer.MAX_VALUE;

    for (Bucket ob : sameId) {
        if (nb.getOrder() == null) {
            continue;
        }
        int d = Math.abs(buckets.indexOf(ob) - lastIndex);
        if (d < bestValue) {
            bestValue = d;
            best = ob;
        }
    }

    return best;

}

From source file:org.terasology.config.InputConfig.java

/**
 * @param uri A uri for the bind to get inputs for
 * @return All the inputs associated with the given bind
 *//*from  ww  w  .  j  a  v a2 s. c  o m*/
public Collection<Input> getInputs(String uri) {
    String[] parts = uri.split(":", 2);
    if (parts.length == 2) {
        Multimap<String, Input> packageMap = getPackageMap(parts[0]);
        if (packageMap != null) {
            return packageMap.get(parts[1]);
        }
    }
    return Lists.newArrayList();
}

From source file:co.cask.cdap.cli.command.CallServiceCommand.java

/**
 * Format multiple header values as a comma separated list of the values.
 * This is a valid formatting: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
 *//* w w w  .  j  av a 2 s. c  o  m*/
private String formatHeaders(HttpResponse response) {
    Multimap<String, String> headers = response.getHeaders();
    ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
    for (String key : headers.keySet()) {
        Collection<String> value = headers.get(key);
        builder.put(key, StringUtils.arrayToString(value.toArray(new String[value.size()])));
    }
    return formatHeader(builder.build());
}

From source file:neon.core.GameSaver.java

private Element saveEvents() {
    Element events = new Element("events");

    // alle gewone tasks (voorlopig enkel script tasks)
    Multimap<String, Action> tasks = queue.getTasks();
    for (String key : tasks.keySet()) {
        for (Action action : tasks.get(key)) {
            Element event = new Element("task");
            event.setAttribute("desc", key);
            if (action instanceof ScriptAction) {
                ScriptAction task = (ScriptAction) action;
                event.setAttribute("script", task.getScript());
            }//from   www  .  ja  va 2  s  .c om
            events.addContent(event);
        }
    }

    // alle timer tasks
    Multimap<Integer, TaskQueue.RepeatEntry> repeats = queue.getTimerTasks();
    for (Integer key : repeats.keySet()) {
        for (TaskQueue.RepeatEntry entry : repeats.get(key)) {
            Element event = new Element("timer");
            event.setAttribute("tick", key + ":" + entry.getPeriod() + ":" + entry.getStop());
            if (entry.getScript() != null) {
                event.setAttribute("task", "script");
                event.setAttribute("script", entry.getScript());
            } else if (entry.getTask() instanceof MagicTask) {
                event.setAttribute("task", "magic");
                Spell spell = ((MagicTask) entry.getTask()).getSpell();
                event.setAttribute("effect", spell.getEffect().name());
                if (spell.getTarget() != null) {
                    event.setAttribute("target", Long.toString(spell.getTarget().getUID()));
                }
                if (spell.getCaster() != null) {
                    event.setAttribute("caster", Long.toString(spell.getCaster().getUID()));
                }
                if (spell.getScript() != null) {
                    event.setAttribute("script", spell.getScript());
                }
                event.setAttribute("stype", spell.getType().name());
                event.setAttribute("mag", Float.toString(spell.getMagnitude()));
            }
            events.addContent(event);
        }
    }

    return events;
}

From source file:org.apache.brooklyn.entity.group.zoneaware.BalancingNodePlacementStrategy.java

protected Map<Location, Integer> toMutableLocationSizes(Multimap<Location, Entity> currentMembers,
        Iterable<? extends Location> otherLocs) {
    Map<Location, Integer> result = Maps.newLinkedHashMap();
    for (Location key : currentMembers.keySet()) {
        result.put(key, currentMembers.get(key).size());
    }//from   w  w  w. j a  v  a2s  . c om
    for (Location otherLoc : otherLocs) {
        if (!result.containsKey(otherLoc)) {
            result.put(otherLoc, 0);
        }
    }
    return result;
}