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

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

Introduction

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

Prototype

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

Source Link

Document

Creates a new, empty HashMultimap with the default initial capacities.

Usage

From source file:edu.buaa.satla.analysis.util.GraphUtils.java

/**
 * Project a graph to a subset of "relevant" nodes.
 * The result is a SetMultimap containing the successor relationships between all relevant nodes.
 * A pair of nodes (a, b) is in the SetMultimap,
 * if there is a path through the graph from a to b which does not pass through
 * any other relevant node.//from w  w  w. j a  v a 2s . com
 *
 * To get the predecessor relationship, you can use {@link Multimaps#invertFrom(com.google.common.collect.Multimap, com.google.common.collect.Multimap)}.
 *
 * @param root The start of the graph to project (always considered relevant).
 * @param isRelevant The predicate determining which nodes are in the resulting relationship.
 * @param successorFunction A function giving the direct successors of any node.
 * @param <N> The node type of the graph.
 */
public static <N> SetMultimap<N, N> projectARG(final N root,
        final Function<? super N, ? extends Iterable<N>> successorFunction, Predicate<? super N> isRelevant) {

    isRelevant = Predicates.or(Predicates.equalTo(root), isRelevant);

    SetMultimap<N, N> successors = HashMultimap.create();

    // Our state is a stack of pairs of todo items.
    // The first item of each pair is a relevant state,
    // for which we are looking for relevant successor states.
    // The second item is a state,
    // whose children should be handled next.
    Deque<Pair<N, N>> todo = new ArrayDeque<>();
    Set<N> visited = new HashSet<>();
    todo.push(Pair.of(root, root));

    while (!todo.isEmpty()) {
        final Pair<N, N> currentPair = todo.pop();
        final N currentPredecessor = currentPair.getFirst();
        final N currentState = currentPair.getSecond();

        if (!visited.add(currentState)) {
            continue;
        }

        for (N child : successorFunction.apply(currentState)) {
            if (isRelevant.apply(child)) {
                successors.put(currentPredecessor, child);

                todo.push(Pair.of(child, child));

            } else {
                todo.push(Pair.of(currentPredecessor, child));
            }
        }
    }

    return successors;
}

From source file:io.github.fsm.services.impl.TransitionServiceImpl.java

public TransitionServiceImpl() {
    transitionDetails = HashMultimap.create();
}

From source file:com.synflow.cx.ui.internal.views.fsm.layout.EdgeLayout.java

private void layoutDoubleEdges(List<State> states) {
    for (State state : states) {
        Multimap<State, Transition> map = HashMultimap.create();
        for (Edge edge : state.getOutgoing()) {
            map.put((State) edge.getTarget(), (Transition) edge);
        }//from   ww  w .j av a  2  s.  c om

        for (State target : map.keySet()) {
            Collection<Transition> transitions = map.get(target);
            if (transitions.size() >= 2) {
                Point l1 = state.get("location");
                Point l2 = target.get("location");

                int inc = BREADTH / (transitions.size() - 1);
                int x = (l1.x + l2.x) / 2 - BREADTH / 2 + 15;
                final int y = (l1.y + l2.y + 20) / 2;

                for (Transition transition : transitions) {
                    List<Bendpoint> bendpoints = new ArrayList<>();
                    AbsoluteBendpoint bp;
                    bp = new AbsoluteBendpoint(x, y - 5);
                    bendpoints.add(bp);

                    bp = new AbsoluteBendpoint(x, y + 5);
                    bendpoints.add(bp);

                    setBendpoints(transition, bendpoints);
                    x += inc;
                }
            }
        }
    }
}

From source file:io.crate.sql.tree.Literal.java

public static Literal fromObject(Object value) {
    Literal literal = null;//from www . j  ava2s .com
    if (value == null) {
        literal = NullLiteral.INSTANCE;
    } else if (value instanceof String) {
        literal = new StringLiteral((String) value);
    } else if (value instanceof Number) {
        if (value instanceof Float || value instanceof Double) {
            literal = new DoubleLiteral(value.toString());
        } else if (value instanceof Short || value instanceof Integer || value instanceof Long) {
            literal = new LongLiteral(value.toString());
        }
    } else if (value instanceof Boolean) {
        literal = (Boolean) value ? BooleanLiteral.TRUE_LITERAL : BooleanLiteral.FALSE_LITERAL;
    } else if (value instanceof Object[]) {
        List<Expression> expressions = new ArrayList<>();
        for (Object o : (Object[]) value) {
            expressions.add(fromObject(o));
        }
        literal = new ArrayLiteral(expressions);
    } else if (value instanceof Map) {
        Multimap<String, Expression> map = HashMultimap.create();
        @SuppressWarnings("unchecked")
        Map<String, Object> valueMap = (Map<String, Object>) value;
        for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
            map.put(entry.getKey(), fromObject(entry.getValue()));
        }
        literal = new ObjectLiteral(map);
    }
    return literal;
}

From source file:me.lucko.luckperms.common.storage.backing.utils.NodeDataHolder.java

public static NodeDataHolder of(String permission, boolean value, String server, String world, long expiry,
        String contexts) {/*from   ww w.j  a va 2s . c  o m*/
    Map<String, Collection<String>> deserializedContexts = GSON.fromJson(contexts, CONTEXT_TYPE);
    Multimap<String, String> map = HashMultimap.create();
    for (Map.Entry<String, Collection<String>> e : deserializedContexts.entrySet()) {
        map.putAll(e.getKey(), e.getValue());
    }

    return new NodeDataHolder(permission, value, server, world, expiry, map);
}

From source file:org.apache.samza.execution.OperatorSpecGraphAnalyzer.java

/**
 * Returns a grouping of {@link InputOperatorSpec}s by the joins, i.e. {@link JoinOperatorSpec}s and
 * {@link StreamTableJoinOperatorSpec}s, they participate in.
 *
 * The key of the returned Multimap is of type {@link OperatorSpec} due to the lack of a stricter
 * base type for {@link JoinOperatorSpec} and {@link StreamTableJoinOperatorSpec}. However, key
 * objects are guaranteed to be of either type only.
 *//*w  w  w  .  j ava  2s.  c  o  m*/
public static Multimap<OperatorSpec, InputOperatorSpec> getJoinToInputOperatorSpecs(
        Collection<InputOperatorSpec> inputOpSpecs) {

    Multimap<OperatorSpec, InputOperatorSpec> joinToInputOpSpecs = HashMultimap.create();

    // Create a getNextOpSpecs() function that emulates connections between every SendToTableOperatorSpec
    //  which are terminal OperatorSpecs  and all StreamTableJoinOperatorSpecs referencing the same table.
    //
    // This is necessary to support Stream-Table Join scenarios because it allows us to associate streams behind
    // SendToTableOperatorSpecs with streams participating in Stream-Table Joins, a connection that would not be
    // easy to make otherwise since SendToTableOperatorSpecs are terminal operator specs.
    Function<OperatorSpec, Iterable<OperatorSpec>> getNextOpSpecs = getCustomGetNextOpSpecs(inputOpSpecs);

    // Traverse graph starting from every input operator spec, observing connectivity between input operator specs
    // and join-related operator specs.
    for (InputOperatorSpec inputOpSpec : inputOpSpecs) {
        // Observe all join-related operator specs reachable from this input operator spec.
        JoinVisitor joinVisitor = new JoinVisitor();
        traverse(inputOpSpec, joinVisitor, getNextOpSpecs);

        // Associate every encountered join-related operator spec with this input operator spec.
        for (OperatorSpec joinOpSpec : joinVisitor.getJoins()) {
            joinToInputOpSpecs.put(joinOpSpec, inputOpSpec);
        }
    }

    return joinToInputOpSpecs;
}

From source file:baggage.SetBag.java

@Override
protected Multimap<K, V> makeEmptyMap() {
    return HashMultimap.create();
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.policies.ChangeBoundRequestRecorder.java

/**
 * Start to record the ChangeBoundRequests.
 */
public void startRecording() {
    recording = true;
    allRequests = HashMultimap.create();
}

From source file:com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.java

@Override
List<AnalysisResultEntry> analyze(@NonNull Configuration configuration, @NonNull Snapshot snapshot) {
    List<AnalysisResultEntry> results = new ArrayList<AnalysisResultEntry>();

    HashMultimap<String, ClassInstance> stringIndex = HashMultimap.create();
    ClassObj stringClass = snapshot.findClass("java.lang.String");
    if (stringClass == null) {
        return Collections.emptyList();
    }//from ww  w .  jav a 2 s  . c  o m

    for (Heap heap : configuration.mHeaps) {
        List<Instance> instances = stringClass.getHeapInstances(heap.getId());

        for (Instance instance : instances) {
            assert instance instanceof ClassInstance;
            ClassInstance stringInstance = (ClassInstance) instance;
            if (stringInstance.getDistanceToGcRoot() != Integer.MAX_VALUE) {
                char[] characters = stringInstance.getStringChars();
                if (characters != null) {
                    String string = new String(characters);
                    stringIndex.put(string, stringInstance);
                }
            }
        }
    }

    for (String key : stringIndex.keySet()) {
        Set<ClassInstance> classInstanceSet = stringIndex.get(key);
        if (classInstanceSet.size() > 1) {
            results.add(new DuplicatedStringsEntry(key, new ArrayList<Instance>(classInstanceSet)));
        }
    }

    return results;
}

From source file:com.github.naios.wide.framework.internal.storage.server.builder.SQLBuilderImpl.java

private static Multimap<ServerStorageStructure, SQLUpdateInfo> splitUpdateInfo(
        final Collection<SQLUpdateInfo> updates) {
    final Multimap<ServerStorageStructure, SQLUpdateInfo> map = HashMultimap.create();
    updates.forEach(update -> map.put(MappingBeans.getStructure(update.getProperty()), update));
    return map;//from w w w  .  j ava2  s .c o m
}