Lookup a string in the dictionary, cache result in closeMatches.

<p>If id==null, consider any match. If id is non-null, consider
only matches to strings that don't have the same id, or that have
a null id.
774022
private void doLookup(String id,StringWrapper toFind)
    {
	// retrain if necessary
	if (distance==null) {
	    distance = new MyTeacher().train( distanceLearner );
	}
	// used cached values if it's ok
	if (lastLookup==toFind) return;

	closeMatches = new HashSet();
	closestMatch = null;
	distanceToClosestMatch = -Double.MAX_VALUE;

	// lookup best match to wrapper
	MyWrapper wrapper = asMyWrapper(toFind);
	Token[] tokens = wrapper.getTokens();
	for (int i=0; i<tokens.length; i++) {
	    ArrayList stringsWithToken = (ArrayList) index.get(tokens[i]);
	    if (stringsWithToken!=null && ((double)stringsWithToken.size()/totalEntries) < maxFraction) {
		for (Iterator j=stringsWithToken.iterator(); j.hasNext(); ) {
		    MyWrapper wj = (MyWrapper)j.next(); 
		    String wjId = (String)idMap.get(wj);
		    //if (DEBUG) System.out.println("id:"+id+" wjId:"+wjId);
		    if (!closeMatches.contains(wj) && (wjId==null || !wjId.equals(id))) {
			double score = distance.score( wrapper.getDistanceWrapper(), wj.getDistanceWrapper() );
			if (DEBUG) System.out.println("score for "+wj+": "+score);
			//if (DEBUG) System.out.println(distance.explainScore(wrapper.getDistanceWrapper(),wj.getDistanceWrapper()));
			closeMatches.add( wj );
			if (score>=distanceToClosestMatch) {
			    //if (DEBUG) System.out.println("closest so far");
			    distanceToClosestMatch = score;
			    closestMatch = wj;
			}
		    }
		}
	    }
	}
	lastLookup = toFind;
    }
877662
public static boolean match(String keyword, String mappingId) {
		if (mappingId.indexOf(keyword) != -1) { // match found!
			return true;
		}
		return false;
	}
237354
private Node<V> lookup(String key) {
	if (key == null) {
	    throw new NullPointerException("key cannot be null");
	}

	int keyLength = key.length();
        // Base case: the node to start the recursive search begins at the root
        // node
	Node<V> n = rootNode;

        // For each index in the key, see how many characters match either the
        // preceding characters to a node, or the trailing characters.
	for (int curKeyIndex = 0; curKeyIndex <= keyLength; ++curKeyIndex) {	    
	    
	    CharSequence nodePrefix = n.getPrefix();

	    // Check whether the current node has a prefix (i.e. the characters
	    // in the trie that lead to it).  If so, determine whether all of
	    // the prefix matches the subsequence of the key starting at the
	    // current key index.  Note that a node will only have a prefix if
	    // it is an intermediate node in the tree.
	    if (nodePrefix.length() > 0) {
		int charOverlap = countOverlap(key, curKeyIndex, nodePrefix, 0);
		int prefixLength = nodePrefix.length();

		// If this this key did not match then entire prefix, then it
		// must not be mapped to any node.
		if (charOverlap < prefixLength) {
		    return null;
		}

		// Otherwise, if all of the characters overlapped, then lookup
		// the transition to the next node based on the next character
		// after the matching prefix
		curKeyIndex += prefixLength;
	    }

	    // If we have exhausted all the characters in the key, then the
	    // current node is associated with the key.
	    if (curKeyIndex == keyLength) {
		return n;
	    }
	    	    
	    // Otherwise, more characters exist to be matched in the key, so
	    // check to see if there is a transition from the next sequence of
	    // the key to node.  If so, we use this to keep searching for the
	    // key's node
	    else {
		Node<V> child = n.getChild(key.charAt(curKeyIndex));

		// if there was no other node to transition to, then the the key
		// must not map to any node in the trie.
		if (child == null) {
		    return null;
		}

		// otherwise, update the current node to the child and repeat
		// the search process
		else {
		    n = child;
		}
	    }	    
	}
	
	// NOTE: we should never reach this case, as the one of the conditions
	// in the for loop will determine where the key goes.
        assert false;
	return null;
    }
1314487
@Override
    public <I> MatchResult<I> matchResult(I item) {
        StringDescription mismatch = new StringDescription();
        if (matches(item, mismatch)) {
            return new MatchResultSuccess<>(item, this);
        } else {
            return new MatchResultMismatch<>(item, this, mismatch.toString());
        }
    }
94500
public static void validateId(final String id) {
    if (id == null || id.isEmpty()) {
      throw new IllegalArgumentException("The ID cannot be null or empty");
    }
    for (int i = 0; i < id.length(); i++) {
      final char c = id.charAt(i);
      if (!(Character.isLetterOrDigit(c))) {
        throw new IllegalArgumentException("Invalid id (\"" + id + 
            "\"): illegal character: " + c);
      }
    }
    if (id.length() == 1) {
      if (Character.isDigit(id.charAt(0))) {
        throw new IllegalArgumentException("The ID cannot be an integer");
      }
    }
  }
251664
private boolean isValidUuid(final String id) {

		if (id != null) {

			if (id.length() != 32) {
				return false;
			}

			return UUID_PATTERN.matcher(id).matches();
		}

		return false;
	}
689111
public List<Object> match() {
        final IntMatchResults result = new IntMatchResults();
        if (matches(result)) {
            return result.getIntResultList();
        } else {
            return null;
        }
    }
943412
public boolean keyMatch(String lookupKey) {
		if (key.isEmpty()) {
			return technicalName.contains(lookupKey);
		}
		else {
			return key.contains(lookupKey);
		}
	}
71197
@Override
    public Optional<UriMatchInfo> match(String uri) {
        if (uri == null) {
            throw new IllegalArgumentException("Argument 'uri' cannot be null");
        }
        if (uri.length() > 1 && uri.charAt(uri.length() - 1) == '/') {
            uri = uri.substring(0, uri.length() - 1);
        }

        int len = uri.length();
        if (isRoot && (len == 0 || (len == 1 && uri.charAt(0) == '/'))) {
            return Optional.of(new DefaultUriMatchInfo(uri, Collections.emptyMap(), variables));
        }
        //Remove any url parameters before matching
        int parameterIndex = uri.indexOf('?');
        if (parameterIndex > -1) {
            uri = uri.substring(0, parameterIndex);
        }
        Matcher matcher = matchPattern.matcher(uri);
        if (matcher.matches()) {
            if (variables.isEmpty()) {
                return Optional.of(new DefaultUriMatchInfo(uri, Collections.emptyMap(), variables));
            } else {
                Map<String, Object> variableMap = new LinkedHashMap<>();
                int count = matcher.groupCount();
                for (int j = 0; j < variables.size(); j++) {
                    int index = (j * 2) + 2;
                    if (index > count) {
                        break;
                    }
                    UriMatchVariable variable = variables.get(j);
                    String value = matcher.group(index);
                    variableMap.put(variable.getName(), value);
                }
                return Optional.of(new DefaultUriMatchInfo(uri, variableMap, variables));
            }
        }
        return Optional.empty();
    }
200806
String getStringByID(long stringID) {
        Long stringIDObj = new Long(stringID);
        String string = (String) stringCache.get(stringIDObj);
        if (string == null) {
            string = createStringByID(stringID);
            stringCache.put(stringIDObj,string);
        }
        return string;
    }
474920
private String stringId() throws RecognitionException {
        if ( input.LA( 1 ) == DRL5Lexer.ID ) {
            Token id = match( input,
                              DRL5Lexer.ID,
                              null,
                              null,
                              DroolsEditorType.IDENTIFIER );
            if ( state.failed ) return null;
            return id.getText();
        } else if ( input.LA( 1 ) == DRL5Lexer.STRING ) {
            Token id = match( input,
                              DRL5Lexer.STRING,
                              null,
                              null,
                              DroolsEditorType.IDENTIFIER );
            if ( state.failed ) return null;
            return StringUtils.unescapeJava( safeStripStringDelimiters( id.getText() ) );
        } else {
            throw new MismatchedTokenException( DRL5Lexer.ID,
                                                input );
        }
    }
329616
private static void validateId(String id) {

        if (id == null) {
            return;
        }
        int n = id.length();
        if (n < 1) {
            throw new IllegalArgumentException("Empty id attribute is not allowed");
        }
        for (int i = 0; i < n; i++) {
            char c = id.charAt(i);
            if (i == 0) {
                if (!Character.isLetter(c) && (c != '_')) {
                    throw new IllegalArgumentException(id);
                }
            } else {
                if (!Character.isLetter(c) &&
                        !Character.isDigit(c) &&
                        (c != '-') && (c != '_')) {
                    throw new IllegalArgumentException(id);
                }
            }
        }

    }
737909
protected boolean check(String id, List<String> includes) {
		if (null != includes) {
			for (String check : includes) {
				if (check(id, check)) {
					return true;
				}
			}
		}
		return false;
	}
140895
public static boolean match(String keyword, String query) {
		if (query.indexOf(keyword) != -1) { // match found!
			return true;
		}
		return false;
	}
232840
private @CheckForNull HashedToken searchMatch(@Nonnull String plainSecret) {
        byte[] hashedBytes = plainSecretToHashBytes(plainSecret);
        for (HashedToken token : tokenList) {
            if (token.match(hashedBytes)) {
                return token;
            }
        }
        
        return null;
    }
572781
public synchronized boolean contains(int id)
   {
      if (tc.isEntryEnabled()) SibTr.entry(this, tc, "contains", ""+id);
      mutableKey.setValue(id);
      boolean returnValue = idToConvTable.containsKey(mutableKey); 
      if (tc.isEntryEnabled()) SibTr.exit(this, tc, "contains", ""+returnValue);
      return returnValue;
   }
345125
private Boolean isMainId(String id, String resource, String lastElement) {
		Boolean isMainId = false;
		if (id == null) {
			if (!utils.singularize(utils.cleanURL(lastElement)).equals(resource) && resource == null) {
				isMainId = true;
			}
		}
		return isMainId;
	}