Example usage for com.google.common.collect SetMultimap keys

List of usage examples for com.google.common.collect SetMultimap keys

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap keys.

Prototype

Multiset<K> keys();

Source Link

Document

Returns a view collection containing the key from each key-value pair in this multimap, without collapsing duplicates.

Usage

From source file:es.usc.citius.composit.core.composition.search.CompositSearch.java

private static <E> SetMultimap<Set<E>, Operation<E>> group(SetMultimap<Operation<E>, E> conceptMap) {
    // Generate groups
    SetMultimap<Set<E>, Operation<E>> matchMap = HashMultimap.create();
    for (Operation<E> op : conceptMap.keys()) {
        matchMap.get(conceptMap.get(op)).add(op);
    }/*from   w  w  w . j  a va 2  s.  co m*/
    return matchMap;
}

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

@Override
public JsonElement serialize(SetMultimap<String, V> src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject result = new JsonObject();
    List<String> keys = Lists.newArrayList(src.keys());
    Collections.sort(keys);/*from  w w w.j  ava  2s . c  om*/
    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:io.tilt.minka.business.leader.distributor.SpillOverBalancer.java

private void registerMigrations(final Reallocation realloc, final boolean loadStrat,
        final Map<Shard, AtomicLong> spaceByReceptor, final List<ShardDuty> unfitting,
        final SetMultimap<Shard, ShardDuty> trans, final long maxValue) {

    for (final Shard emisor : trans.keys()) {
        final Set<ShardDuty> emitting = trans.get(emisor);
        for (final ShardDuty emitted : emitting) {
            final Shard receptor = makeSpaceIntoReceptors(loadStrat, emitted, spaceByReceptor);
            if (receptor == null) {
                emitted.registerEvent(DutyEvent.ASSIGN, State.STUCK);
                emitted.setStuckCause(StuckCause.UNSUITABLE);
                realloc.getProblems().put(null, emitted);
                unfitting.add(emitted);/*  w ww .j  av  a  2 s. c  o  m*/
            } else {
                final ShardDuty copy = addMigrationChange(realloc, receptor, emisor, emitted);
                logger.info("{}: Migrating from: {} to {}: Duty: {}", getClass().getSimpleName(), emisor,
                        receptor, copy);
            }
        }
    }
}

From source file:org.eclipse.gef4.mvc.examples.logo.parts.FXHoverHandleRootPart.java

@Override
protected void doRefreshVisual(VBox visual) {
    // check if we have a host
    SetMultimap<IVisualPart<Node, ? extends Node>, String> anchorages = getAnchorages();
    if (anchorages.isEmpty()) {
        return;/* w w w.  j ava 2 s .c  o  m*/
    }

    // determine center location of host visual
    IVisualPart<Node, ? extends Node> anchorage = anchorages.keys().iterator().next();
    refreshHandleLocation(anchorage.getVisual());
}

From source file:org.eclipse.gef4.mvc.examples.logo.rcp.parts.FXHoverHandleRootPart.java

@Override
protected void doRefreshVisual(VBox visual) {
    // check if we have a host
    SetMultimap<IVisualPart<Node, ? extends Node>, String> anchorages = getAnchoragesUnmodifiable();
    if (anchorages.isEmpty()) {
        return;//from   ww  w  .j  a  v a 2 s .co m
    }

    // determine center location of host visual
    IVisualPart<Node, ? extends Node> anchorage = anchorages.keys().iterator().next();
    refreshHandleLocation(anchorage.getVisual());
}

From source file:org.onosproject.net.intent.impl.LinkCollectionIntentInstaller.java

private List<FlowRuleBatchOperation> generateBatchOperations(LinkCollectionIntent intent,
        FlowRuleOperation operation) {/* w w w.  jav  a 2  s . c om*/

    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        outputPorts.put(link.src().deviceId(), link.src().port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    FlowRuleBatchOperation batchOperation = new FlowRuleBatchOperation(outputPorts.keys().stream()
            .map(deviceId -> createBatchEntry(operation, intent, deviceId, outputPorts.get(deviceId)))
            .collect(Collectors.toList()));

    return Collections.singletonList(batchOperation);
}

From source file:org.onosproject.net.intent.impl.compiler.LinkCollectionIntentCompiler.java

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable,
        Set<LinkResourceAllocations> resources) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        inputPorts.put(link.dst().deviceId(), link.dst().port());
        outputPorts.put(link.src().deviceId(), link.src().port());
    }//w  ww .j a  va2  s  .  c o  m

    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    List<FlowRule> rules = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keys()) {
        rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId)));
    }
    return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
}

From source file:org.onosproject.net.intent.impl.compiler.LinkCollectionIntentFlowObjectiveCompiler.java

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {

    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
    Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of();

    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);

    computePorts(intent, inputPorts, outputPorts);

    if (encapConstraint.isPresent()) {
        labels = labelAllocator.assignLabelToPorts(intent.links(), intent.id(),
                encapConstraint.get().encapType());
    }/*from w  ww .  j  a  v  a 2s . com*/

    List<Objective> objectives = new ArrayList<>();
    List<DeviceId> devices = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keys()) {
        List<Objective> deviceObjectives = createRules(intent, deviceId, inputPorts.get(deviceId),
                outputPorts.get(deviceId), labels);
        deviceObjectives.forEach(objective -> {
            objectives.add(objective);
            devices.add(deviceId);
        });
    }
    return Collections.singletonList(
            new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources()));
}

From source file:org.onosproject.net.intent.impl.installer.LinkCollectionIntentInstaller.java

private List<Collection<FlowRuleOperation>> generateBatchOperations(LinkCollectionIntent intent,
        FlowRuleOperation.Type operation) {

    //TODO do we need a set here?
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        inputPorts.put(link.dst().deviceId(), link.dst().port());
        outputPorts.put(link.src().deviceId(), link.src().port());
    }//www.  ja v  a  2s .  c o m

    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    List<FlowRuleOperation> rules = Lists.newArrayList();
    outputPorts.keys().stream().map(deviceId -> createBatchEntries(operation, intent, deviceId,
            inputPorts.get(deviceId), outputPorts.get(deviceId))).forEach(rules::addAll);

    return Lists.newArrayList(ImmutableSet.of(rules));
}

From source file:org.onosproject.net.intent.impl.compiler.LinkCollectionIntentFlowObjectivesCompiler.java

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        inputPorts.put(link.dst().deviceId(), link.dst().port());
        outputPorts.put(link.src().deviceId(), link.src().port());
    }//w  ww .  j  a va2 s  .  c om

    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    List<Objective> objectives = new ArrayList<>();
    List<DeviceId> devices = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keys()) {
        List<Objective> deviceObjectives = createRules(intent, deviceId, inputPorts.get(deviceId),
                outputPorts.get(deviceId));
        deviceObjectives.forEach(objective -> {
            objectives.add(objective);
            devices.add(deviceId);
        });
    }
    return Collections.singletonList(new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
}