Changeset 1282 for trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/Trie.java
- Timestamp:
- 07/30/13 09:38:43 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/Trie.java
r1251 r1282 29 29 /** 30 30 * <p> 31 * This class implements a <it>trie</it>, i.e., a tree of sequences that the occurence of32 * subsequences up to a predefined length. This length is the trie order.31 * This class implements a <it>trie</it>, i.e., a tree of sequences that represents the occurrence 32 * of subsequences up to a predefined length. This length is the trie order. 33 33 * </p> 34 34 * … … 51 51 /** 52 52 * <p> 53 * Collection of all symbols occur ing in the trie.53 * Collection of all symbols occurring in the trie. 54 54 * </p> 55 55 */ … … 65 65 /** 66 66 * <p> 67 * Comparator to be used for comparing the symbols with each other68 * </p> 69 */ 70 private Symbol Comparator<T> comparator;71 72 /** 73 * <p> 74 * Con tructor. Creates a new Trie with a {@link DefaultSymbolComparator}.67 * Strategy for handling symbols, i.e., for comparing and storing them 68 * </p> 69 */ 70 private SymbolStrategy<T> strategy; 71 72 /** 73 * <p> 74 * Constructor. Creates a new trie with a {@link DefaultSymbolStrategy}. 75 75 * </p> 76 76 */ 77 77 public Trie() { 78 this(new DefaultSymbolComparator<T>()); 79 } 80 81 /** 82 * <p> 83 * Contructor. Creates a new Trie with that uses a specific {@link SymbolComparator}. 84 * </p> 85 */ 86 public Trie(SymbolComparator<T> comparator) { 87 this.comparator = comparator; 88 rootNode = new TrieNode<T>(comparator); 89 knownSymbols = new SymbolMap<T, T>(this.comparator); 90 } 91 92 /** 93 * <p> 94 * Copy-Constructor. Creates a new Trie as the copy of other. The other trie must not be null. 78 this(new DefaultSymbolStrategy<T>()); 79 } 80 81 /** 82 * <p> 83 * Constructor. Creates a new trie that uses a specific {@link SymbolStrategy}. 84 * </p> 85 * 86 * @param strategy 87 * strategy to be used for managing symbols 88 * 89 * @throws IllegalArgumentException 90 * if the strategy is null 91 */ 92 public Trie(SymbolStrategy<T> strategy) { 93 if (strategy == null) { 94 throw new IllegalArgumentException("strategy must not be null"); 95 } 96 this.strategy = strategy; 97 rootNode = new TrieNode<T>(strategy); 98 knownSymbols = strategy.createSymbolMap(); 99 } 100 101 /** 102 * <p> 103 * Copy-Constructor. Creates a new trie as the copy of other. The other trie must not be null. 95 104 * </p> 96 105 * 97 106 * @param other 98 * Trie that is copied 107 * trie that is copied 108 * 109 * @throws IllegalArgumentException 110 * if the other trie is null 99 111 */ 100 112 public Trie(Trie<T> other) { … … 103 115 } 104 116 rootNode = new TrieNode<T>(other.rootNode); 105 knownSymbols = new SymbolMap<T, T>(other.knownSymbols);106 comparator = other.comparator;107 } 108 109 /** 110 * <p> 111 * Returns a collection of all symbols occur ing in the trie.112 * </p> 113 * 114 * @return symbols occur ing in the trie117 strategy = other.strategy; 118 knownSymbols = strategy.copySymbolMap(other.knownSymbols); 119 } 120 121 /** 122 * <p> 123 * Returns a collection of all symbols occurring in the trie. 124 * </p> 125 * 126 * @return symbols occurring in the trie 115 127 */ 116 128 public Collection<T> getKnownSymbols() { … … 202 214 /** 203 215 * <p> 204 * Returns the number of occur ences of the given sequence.216 * Returns the number of occurrences of the given sequence. 205 217 * </p> 206 218 * 207 219 * @param sequence 208 * sequence whose number of occur ences is required209 * @return number of occur ences of the sequence220 * sequence whose number of occurrences is required 221 * @return number of occurrences of the sequence 210 222 */ 211 223 public int getCount(List<T> sequence) { … … 220 232 /** 221 233 * <p> 222 * Returns the number of occur ences of the given prefix and a symbol that follows it.<br>234 * Returns the number of occurrences of the given prefix and a symbol that follows it.<br> 223 235 * Convenience function to simplify usage of {@link #getCount(List)}. 224 236 * </p> … … 228 240 * @param follower 229 241 * suffix of the sequence 230 * @return number of occur ences of the sequence242 * @return number of occurrences of the sequence 231 243 * @see #getCount(List) 232 244 */ … … 326 338 * <p> 327 339 * used to recursively process the trie. The provided processor will be called for any path 328 * through the tr ee. The processor may abort the processing through returnsvalues of its340 * through the trie. The processor may abort the processing through return values of its 329 341 * {@link TrieProcessor#process(List, int)} method. 330 342 * </p> … … 348 360 * </p> 349 361 * 350 * @param context the context of the currently processed trie node, i.e. the prece eding362 * @param context the context of the currently processed trie node, i.e. the preceding 351 363 * symbols 352 364 * @param child the processed trie node … … 489 501 * <p> 490 502 * adds a new symbol to the collection of known symbols if this symbol is not already 491 * contained. The symbols are compared using the comparator.503 * contained. 492 504 * </p> 493 505 * … … 496 508 private void addToKnownSymbols(T symbol) { 497 509 if (!knownSymbols.containsSymbol(symbol)) { 498 knownSymbols.addSymbol(symbol, symbol);510 knownSymbols.addSymbol(symbol, null); 499 511 } 500 512 } … … 529 541 /** 530 542 * <p> 531 * Con tructor. Creates a new TrieVertex.543 * Constructor. Creates a new TrieVertex. 532 544 * </p> 533 545 * … … 635 647 */ 636 648 public void updateKnownSymbols() { 637 knownSymbols = new SymbolMap<T, T>(this.comparator);649 knownSymbols = strategy.createSymbolMap(); 638 650 for (TrieNode<T> node : rootNode.getChildren()) { 639 651 addToKnownSymbols(node.getSymbol()); … … 643 655 /** 644 656 * <p> 645 * Two Tries are defined as equal, if their {@link #rootNode}are equal.657 * Two tries are defined as equal, if their {@link #rootNode}s are equal. 646 658 * </p> 647 659 *
Note: See TracChangeset
for help on using the changeset viewer.