Search in sources :

Example 26 with IdentityHashMap

use of java.util.IdentityHashMap in project sonatype-aether by sonatype.

the class NearestVersionConflictResolverTest method testNearestDirtyVersionUnderneathRemovedNode.

@Test
public void testNearestDirtyVersionUnderneathRemovedNode() throws Exception {
    // root
    // +- a
    // |  \- b:1           # will be removed in favor of b:2
    // |     \- j:1        # nearest version of j in dirty tree
    // +- c
    // |  \- d
    // |     \- e
    // |        \- j:2
    // \- b:2
    DependencyNode j1 = builder.artifactId("j").version("1").build();
    DependencyNode j2 = builder.artifactId("j").version("2").build();
    DependencyNode b1 = builder.artifactId("b").version("1").build();
    b1.getChildren().add(j1);
    DependencyNode a = builder.artifactId("a").build();
    a.getChildren().add(b1);
    DependencyNode e = builder.artifactId("e").build();
    e.getChildren().add(j2);
    DependencyNode d = builder.artifactId("d").build();
    d.getChildren().add(e);
    DependencyNode c = builder.artifactId("c").build();
    c.getChildren().add(d);
    DependencyNode b2 = builder.artifactId("b").version("2").build();
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(a);
    root.getChildren().add(c);
    root.getChildren().add(b2);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(j1, "j");
    conflictIds.put(j2, "j");
    conflictIds.put(a, "a");
    conflictIds.put(b1, "b");
    conflictIds.put(b2, "b");
    conflictIds.put(c, "c");
    conflictIds.put(d, "d");
    conflictIds.put(e, "e");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
    List<DependencyNode> trail = find(root, "j");
    assertEquals(5, trail.size());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Example 27 with IdentityHashMap

use of java.util.IdentityHashMap in project sonatype-aether by sonatype.

the class NearestVersionConflictResolverTest method testUnsolvableRangeConflictBetweenHardConstraints.

@Test(expected = UnsolvableVersionConflictException.class)
public void testUnsolvableRangeConflictBetweenHardConstraints() throws Exception {
    // root
    // +- b:1
    // |  \- a:[1]
    // \- c:1
    //    \- a:[2]
    DependencyNode a1 = builder.artifactId("a").version("1").range("[1]").build();
    DependencyNode a2 = builder.artifactId("a").version("2").range("[2]").build();
    DependencyNode b = builder.artifactId("b").version("1").build();
    DependencyNode c = builder.artifactId("c").version("1").build();
    b.getChildren().add(a1);
    c.getChildren().add(a2);
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(b);
    root.getChildren().add(c);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(a1, "a");
    conflictIds.put(a2, "a");
    conflictIds.put(b, "b");
    conflictIds.put(c, "c");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Example 28 with IdentityHashMap

use of java.util.IdentityHashMap in project sonatype-aether by sonatype.

the class NearestVersionConflictResolverTest method testSelectedVersionAtDeeperLevelThanOriginallySeen.

@Test
public void testSelectedVersionAtDeeperLevelThanOriginallySeen() throws Exception {
    // root
    // +- a
    // |  \- b:1           # will be removed in favor of b:2
    // |     \- j:1        # nearest version of j in dirty tree
    // +- c
    // |  \- d
    // |     \- e
    // |        \- j:1
    // \- b:2
    DependencyNode j = builder.artifactId("j").build();
    DependencyNode b1 = builder.artifactId("b").version("1").build();
    b1.getChildren().add(j);
    DependencyNode a = builder.artifactId("a").build();
    a.getChildren().add(b1);
    DependencyNode e = builder.artifactId("e").build();
    e.getChildren().add(j);
    DependencyNode d = builder.artifactId("d").build();
    d.getChildren().add(e);
    DependencyNode c = builder.artifactId("c").build();
    c.getChildren().add(d);
    DependencyNode b2 = builder.artifactId("b").version("2").build();
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(a);
    root.getChildren().add(c);
    root.getChildren().add(b2);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(j, "j");
    conflictIds.put(a, "a");
    conflictIds.put(b1, "b");
    conflictIds.put(b2, "b");
    conflictIds.put(c, "c");
    conflictIds.put(d, "d");
    conflictIds.put(e, "e");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
    List<DependencyNode> trail = find(root, "j");
    assertEquals(5, trail.size());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Example 29 with IdentityHashMap

use of java.util.IdentityHashMap in project antlr4 by antlr.

the class TestGraphNodes method toDOTString.

private static String toDOTString(PredictionContext context, boolean rootIsWildcard) {
    StringBuilder nodes = new StringBuilder();
    StringBuilder edges = new StringBuilder();
    Map<PredictionContext, PredictionContext> visited = new IdentityHashMap<PredictionContext, PredictionContext>();
    Map<PredictionContext, Integer> contextIds = new IdentityHashMap<PredictionContext, Integer>();
    Deque<PredictionContext> workList = new ArrayDeque<PredictionContext>();
    visited.put(context, context);
    contextIds.put(context, contextIds.size());
    workList.add(context);
    while (!workList.isEmpty()) {
        PredictionContext current = workList.pop();
        nodes.append("  s").append(contextIds.get(current)).append('[');
        if (current.size() > 1) {
            nodes.append("shape=record, ");
        }
        nodes.append("label=\"");
        if (current.isEmpty()) {
            nodes.append(rootIsWildcard ? '*' : '$');
        } else if (current.size() > 1) {
            for (int i = 0; i < current.size(); i++) {
                if (i > 0) {
                    nodes.append('|');
                }
                nodes.append("<p").append(i).append('>');
                if (current.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
                    nodes.append(rootIsWildcard ? '*' : '$');
                }
            }
        } else {
            nodes.append(contextIds.get(current));
        }
        nodes.append("\"];\n");
        if (current.isEmpty()) {
            continue;
        }
        for (int i = 0; i < current.size(); i++) {
            if (current.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
                continue;
            }
            if (visited.put(current.getParent(i), current.getParent(i)) == null) {
                contextIds.put(current.getParent(i), contextIds.size());
                workList.push(current.getParent(i));
            }
            edges.append("  s").append(contextIds.get(current));
            if (current.size() > 1) {
                edges.append(":p").append(i);
            }
            edges.append("->");
            edges.append('s').append(contextIds.get(current.getParent(i)));
            edges.append("[label=\"").append(current.getReturnState(i)).append("\"]");
            edges.append(";\n");
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.append("digraph G {\n");
    builder.append("rankdir=LR;\n");
    builder.append(nodes);
    builder.append(edges);
    builder.append("}\n");
    return builder.toString();
}
Also used : IdentityHashMap(java.util.IdentityHashMap) SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) PredictionContext(org.antlr.v4.runtime.atn.PredictionContext) ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) ArrayDeque(java.util.ArrayDeque)

Example 30 with IdentityHashMap

use of java.util.IdentityHashMap in project CoreNLP by stanfordnlp.

the class SplittingGrammarExtractor method countMergeEffects.

public void countMergeEffects(Tree tree, Map<String, double[]> totalStateMass, Map<String, double[]> deltaAnnotations) {
    IdentityHashMap<Tree, double[]> probIn = new IdentityHashMap<>();
    IdentityHashMap<Tree, double[]> probOut = new IdentityHashMap<>();
    IdentityHashMap<Tree, double[][]> unaryTransitions = new IdentityHashMap<>();
    IdentityHashMap<Tree, double[][][]> binaryTransitions = new IdentityHashMap<>();
    recountTree(tree, false, probIn, probOut, unaryTransitions, binaryTransitions);
    // no need to count the root
    for (Tree child : tree.children()) {
        countMergeEffects(child, totalStateMass, deltaAnnotations, probIn, probOut);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) Tree(edu.stanford.nlp.trees.Tree)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)131 Map (java.util.Map)43 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)19 LinkedHashMap (java.util.LinkedHashMap)17 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 Entry (java.util.Map.Entry)5