public Map<String, String> match(UriTemplate candidate) { Map<String, String> result = new HashMap<>(); // Should not happen but for safety if (candidate.getSegmentCount() != getSegmentCount()) { return null; } Iterator<Segment> candidateSegments = candidate.getSegments().iterator(); Iterator<Segment> targetSegments = segments.iterator(); while (candidateSegments.hasNext()) { Segment candidateSegment = candidateSegments.next(); Segment targetSegment = targetSegments.next(); if (targetSegment.getParameterIndex() == -1) { // Not a parameter - values must match if (!targetSegment.getValue().equals(candidateSegment.getValue())) { // Not a match. Stop here return null; } } else { // Parameter result.put(targetSegment.getValue(), candidateSegment.getValue()); } } return result; }
@VisibleForTesting String getReturnType(String className, Segment entry) { for (AutocompleteEntry entryObj : autocompleteEntryHolder.getEntriesForTypeName(className)) { if (entryObj.getEntryName().equals(entry.getValue())) { return parseReturnType(entryObj.getReturnType(), entry.isArrayElement()); } } return ""; }
/** * Handling the first segment in an expression. This gets the type of the segment which is first * in an expression and accounts for cases in which this segment is an array. */ private String getFirstReturnType(Segment first, int maxRecursionDepth) { if (maxRecursionDepth <= 0) { return ""; } if (first.isRawArray()) { return ARRAY_TYPE; } String str = first.getValue(); if (isTopLevelClass(str)) { return str; } else if (variableTypes.containsKey(str)) { return parseReturnType( getPossibleClass(variableTypes.get(str), maxRecursionDepth - 1), first.isArrayElement()); } else { return ""; } }
public boolean next() throws IOException { if (size() == 0) return false; if (minSegment != null) { // minSegment is non-null for all invocations of next except the first // one. For the first invocation, the priority queue is ready for use // but for the subsequent invocations, first adjust the queue adjustPriorityQueue(minSegment); if (size() == 0) { minSegment = null; return false; } } minSegment = top(); key = minSegment.getKey(); value = minSegment.getValue(); return true; }