/** * Finds type by exact FQN name. * * @param fqn * Fully qualified class name. * @return Returns type or <code>null</code> if it can not be found. */ public E lookup(String fqn) { int index = findRetrieveIndexFor(fqn); return getAt(index); }
/** * {@inheritDoc} */ @Override public String toString() { StringBuilder sb = new StringBuilder(); int size = size(); for (int i = 0; i < size; i++) { sb.append("[" + i + "] = " + getAt(i).getFQN() + "\n"); } return sb.toString(); }
/** * Finds all {@link NonPrimitiveType}s that start with given string. * * @param fqnWildCard * String that class should start with. * @return All types starting with the given string. */ public Collection<E> findStartsWith(String fqnWildCard) { long minMaxIndex = findStartsWithMinMaxIndexes(fqnWildCard); int min = getLowerInt(minMaxIndex); int max = getUpperInt(minMaxIndex); if (min < 0) { return Collections.emptyList(); } int size = size(); List<E> results = new ArrayList<>((max - min) + 1); for (int i = min; (i <= max) && (max < size); i++) { results.add(getAt(i)); } return results; }
/** * Finds index for a FQN to retrieve. * * @param fqn * String representing the FQN. * @return Index where element should be retrieved from or negative value if one can not be * located. */ private int findRetrieveIndexFor(String fqn) { int size = size(); int min = 0; int max = size - 1; while (max >= min) { int mid = midpoint(min, max); int compare = getAt(mid).getFQN().compareTo(fqn); // if no difference then we have it if (0 == compare) { return mid; } // otherwise adapt min and max min = (compare < 0) ? mid + 1 : min; max = (compare > 0) ? mid - 1 : max; } return -1; }