public boolean hasPrefix( String key ) { return ( this.get( key ) != null ); }
public V get( String key ) { return get( new StringBuffer( key ), 0 ); }
V get( StringBuffer key, int level ) { if( key.length() <= 0 ) return entry.value; Trie<V> trie = children.get( key.charAt( 0 ) ); if( trie != null ) return trie.get( key.deleteCharAt( 0 ), ++level ); else return ( level > 0 ) ? entry.value : null; }
protected Child findMatchingTap( FlowProcess<? extends Config> flowProcess ) { // todo: in Cascading4, this value can be pulled from the FlowProcessContext String identifier = flowProcess.getStringProperty( "cascading.source.path" ); // we cannot determine the actual file being processed -- this was the default until 3.3 if( identifier == null ) return taps[ 0 ]; Trie<Child> prefixMap = getTapPrefixMap( flowProcess ); int index = identifier.indexOf( getTapsCommonPrefix( flowProcess ) ); // the child taps represent relative paths that cannot be resolved -- eg. globs if( index == -1 ) return taps[ 0 ]; Child child = prefixMap.get( identifier.substring( index ) ); if( child == null ) throw new IllegalStateException( "unable to find child having a prefix that matches: " + identifier ); return child; }
@Test public void testGetPrefix() { Trie<String> trie = new Trie<>(); trie.put( "a", "a" ); trie.put( "aa", "aa" ); trie.put( "aaa", "aaa" ); trie.put( "ab", "ab" ); trie.put( "abb", "abb" ); trie.put( "aabb", "aabb" ); assertEquals( null, trie.get( "" ) ); assertEquals( "a", trie.get( "a" ) ); assertEquals( "a", trie.get( "azzz" ) ); assertEquals( "aa", trie.get( "aa" ) ); assertEquals( "aaa", trie.get( "aaa" ) ); assertEquals( "ab", trie.get( "ab" ) ); assertEquals( "abb", trie.get( "abb" ) ); assertEquals( "aabb", trie.get( "aabb" ) ); assertEquals( "aabb", trie.get( "aabbcdef" ) ); assertNull( trie.get( "zzz" ) ); assertNull( trie.get( "" ) ); }