/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Ruslan Sakevych
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package ua.yandex.shad.autocomplete;

import ua.yandex.shad.utils.LimitDecorator;
import ua.yandex.shad.tries.RWayTrie;
import ua.yandex.shad.collections.Tuple;
import ua.yandex.shad.tries.Trie;

public class PrefixMatches {

    private static final int MIN_WORD_LENGTH = 3;
    private static final int DEFAULT_K = 3;
    private Trie trie = new RWayTrie();

    public int load(String... strings) {
        for (String string : strings) {
            for (String str : string.split("\\s+")) {
                if (str.length() >= MIN_WORD_LENGTH) {
                    trie.add(new Tuple(str, str.length()));
                }
            }
        }
        return size();
    }

    public boolean contains(String word) {
        return trie.contains(word);
    }

    public boolean delete(String word) {
        return trie.delete(word);
    }

    public Iterable<String> wordsWithPrefix(String pref) {
        return wordsWithPrefix(pref, DEFAULT_K);
    }

    public Iterable<String> wordsWithPrefix(String pref, int k) {
        if (pref.length() < MIN_WORD_LENGTH) {
            throw new IllegalArgumentException();
        }
        return new LimitDecorator(trie.wordsWithPrefix(pref), k);
    }

    public int size() {
        return trie.size();
    }
}

@@ -1376,743 +1376,1950 @@
     
-private static final int MIN_WORD_LENGTH = 3;%0A    private static final int DEFAULT_K = 3;%0A    private Trie trie = new RWayTrie();%0A%0A    public int load(String... strings) %7B%0A        for (String string : strings) %7B%0A            for (String str : string.split(%22%5C%5Cs+%22)) %7B%0A                if (str.length() %3E= MIN_WORD_LENGTH) %7B%0A                    trie.add(new Tuple(str, str.length()));%0A                %7D%0A            %7D%0A        %7D%0A        return size();%0A    %7D%0A%0A    public boolean contains(String word) %7B%0A        return trie.contains(word);%0A    %7D%0A%0A    public boolean delete(String word) %7B%0A        return trie.delete(word);%0A    %7D%0A%0A    public Iterable%3CString%3E wordsWithPrefix(String pref) %7B%0A        return wordsWithPrefix(pref, DEFAULT_K);%0A    %7D%0A
+/**%0A     * Lower bound of word length.%0A     */%0A    private static final int MIN_WORD_LENGTH = 3;%0A%0A    /**%0A     * Default value for parameter K in wordsWithPrefix method.%0A     */%0A    private static final int DEFAULT_K = 3;%0A%0A    /**%0A     * Actual Trie to store data.%0A     */%0A    private Trie trie = new RWayTrie();%0A%0A    /**%0A     * Loads words from %7B@code strings%7D to Trie.%0A     * If string form %7B@code strings%7D contains more than on word then%0A     * it will be split by whitespaces.%0A     * @param strings input strings%0A     * @return amount of words added%0A     */%0A    public int load(String... strings) %7B%0A        for (String string : strings) %7B%0A            for (String str : string.split(%22%5C%5Cs+%22)) %7B%0A                if (str.length() %3E= MIN_WORD_LENGTH) %7B%0A                    trie.add(new Tuple(str, str.length()));%0A                %7D%0A            %7D%0A        %7D%0A        return size();%0A    %7D%0A%0A    /**%0A     * Checks if %7B@code word%7D is in memory.%0A     * @param word actual word to check%0A     * @return true,  if word is in memory%0A     *         false, otherwise%0A     */%0A    public boolean contains(String word) %7B%0A        return trie.contains(word);%0A    %7D%0A%0A    /**%0A     * Deletes %7B@code word%7D form memory.%0A     * @param word actual word to delete%0A     * @return true,  if success%0A     *         false, otherwise%0A     */%0A    public boolean delete(String word) %7B%0A        return trie.delete(word);%0A    %7D%0A%0A    /**%0A     * Gets words that matches %7B@code pref%7D.%0A     * @param pref actual prefix ot match.%0A     * @return instance of Iterable class with words%0A     * @see Iterable%0A     */%0A    public Iterable%3CString%3E wordsWithPrefix(String pref) %7B%0A        return wordsWithPrefix(pref, DEFAULT_K);%0A    %7D%0A%0A    /**%0A     * Gets words that matches %7B@code pref%7D and limit different lengths%0A     * with parameter %7B@code k%7D.%0A     * @param pref actual prefix to match%0A     * @param k number of different lengths%0A     * @return instance of Iterable class with words%0A     */
 %0A   
@@ -3557,24 +3557,109 @@
  k);%0A    %7D%0A%0A
+    /**%0A     * Gets amount of words in memory.%0A     * @return count of words%0A     */%0A
     public i

Document PrefixMatches class.