MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / Trie

Class Trie

src/main/java/wycc/util/Trie.java:44–382  ·  view source on GitHub ↗

Provides a standard implementation of the Path.ID and Path.Filter interfaces. It employs the flyweight pattern to ensure every ID can only ever correspond to a single instanceof of Trie. That, it ensures that any two instances which represent the same Path.ID are, in fact, the same instan

Source from the content-addressed store, hash-verified

42 *
43 */
44public final class Trie implements Iterable<String>, Comparable<Trie> {
45
46 // =========================================================
47 // Private Constants
48 // =========================================================
49
50 private static final Trie[] ONE_CHILD = new Trie[1];
51
52 // =========================================================
53 // Public Constants
54 // =========================================================
55
56 public static final Trie ROOT = new Trie(null,"");
57 public static final Trie STAR = fromString("*");
58 public static final Trie STARSTAR = fromString("**");
59 /**
60 * A default filter which recursively matches everything
61 */
62 public static final Trie EVERYTHING = Trie.fromString("**/*");
63
64 // =========================================================
65 // Private State
66 // =========================================================
67
68 private final Trie parent;
69 private final String component;
70 private final int depth;
71 private final boolean isConcrete;
72 private Trie[] children;
73 private int nchildren;
74
75 // =========================================================
76 // Public Methods
77 // =========================================================
78
79
80 Trie(final Trie parent, final String component) {
81 this.parent = parent;
82 this.component = component;
83 if(parent != null) {
84 this.depth = parent.depth + 1;
85 } else {
86 this.depth = -1;
87 }
88 this.children = ONE_CHILD;
89 this.nchildren = 0;
90 this.isConcrete = (parent == null || parent.isConcrete)
91 && !component.contains("*");
92 }
93
94 public int size() {
95 return depth + 1;
96 }
97
98 public boolean isConcrete() {
99 return isConcrete;
100 }
101

Callers

nothing calls this directly

Calls 1

fromStringMethod · 0.95

Tested by

no test coverage detected