class PrefixFinder {


    /**
     * Extracts prefixes of a given string from a SortedSet.  If an element
     * of the given set is a prefix of the given string, then that element
     * is added to the result list.
     * 
     * <p>Put another way, for every element in the result list, the following 
     * expression will be true: <tt>string.startsWith(element.getKey())</tt>.
     * 
     * @param set     the sorted set containing potential prefixes
     * @param input   the string whose prefixes to find 
     * @return   the list of prefixes 
     */
    public static List<String> find(SortedSet<String> set, String input) {<FILL_FUNCTION_BODY>}

    
    protected static SortedSet<String> headSetInclusive(SortedSet<String> set, String input) {
        // use NavigableSet inclusive version if available
        if(set instanceof NavigableSet) {
            return ((NavigableSet<String>)set).headSet(input, true);
        }
        // use Stored*Set inclusive version if available
        if(set instanceof StoredSortedKeySet) {
            return ((StoredSortedKeySet<String>)set).headSet(input, true);
        }
        if(set instanceof StoredSortedValueSet) {
            return ((StoredSortedValueSet<String>)set).headSet(input, true);
        }
        // Use synthetic "one above" trick
        // NOTE: because '\0' sorts in the middle in "java modified UTF-8",
        // used in the Stored* class StringBindings, this trick won't work
        // there
        return set.headSet(input+'\0');
    }


    private static String last(SortedSet<String> set) {
        return set.isEmpty() ? null : set.last();
    }


    public static List<String> findKeys(SortedMap<String,?> map, String input) {
        LinkedList<String> result = new LinkedList<String>();
        map = headMapInclusive(map, input);
        for (String last = last(map); last != null; last = last(map)) {
            if (input.startsWith(last)) {
                result.push(last);
                map = map.headMap(last); 
            } else {
                // Find the longest common prefix.
                int p = StringUtils.indexOfDifference(input, last);
                if (p <= 0) {
                    return result;
                }
                last = input.substring(0, p);
                map = headMapInclusive(map, last);
            }
        }
        return result;
    }


    private static SortedMap<String, ?> headMapInclusive(SortedMap<String, ?> map, String input) {
        // use NavigableMap inclusive version if available
        if(map instanceof NavigableMap) {
            return ((NavigableMap<String, ?>)map).headMap(input, true);
        }
        // use StoredSortedMap inclusive version if available
        if(map instanceof StoredSortedMap) {
            return ((StoredSortedMap<String, ?>)map).headMap(input, true);
        }
        // Use synthetic "one above" trick
        // NOTE: because '\0' sorts in the middle in "java modified UTF-8",
        // used in the Stored* class StringBindings, this trick won't work
        // there
        return map.headMap(input+'\0');
    }


    private static String last(SortedMap<String,?> map) {
        // TODO Auto-generated method stub
        return map.isEmpty() ? null : map.lastKey();
    }
}

        LinkedList<String> result = new LinkedList<String>();
        set = headSetInclusive(set, input);
        for (String last = last(set); last != null; last = last(set)) {
            if (input.startsWith(last)) {
                result.push(last);
                set = set.headSet(last); 
            } else {
                // Find the longest common prefix.
                int p = StringUtils.indexOfDifference(input, last);
                if (p <= 0) {
                    return result;
                }
                last = input.substring(0, p);
                set = headSetInclusive(set, last);
            }
        }
        return result;
    
<no_super_class>