Search in sources :

Example 1 with SimpleCharPrefixTree

use of fr.neatmonster.nocheatplus.utilities.ds.prefixtree.SimpleCharPrefixTree in project NoCheatPlus by NoCheatPlus.

the class PathUtils method removePaths.

/**
 * Get a new ConfigFile instance with all paths removed (recursively by prefix).
 * @param config
 * @param removePaths
 * @return
 */
public static ConfigFile removePaths(final ConfigFile config, final Collection<String> removePaths) {
    final SimpleCharPrefixTree prefixes = new SimpleCharPrefixTree();
    for (final String path : removePaths) {
        prefixes.feed(path);
    }
    final ConfigFile newConfig = new ConfigFile();
    for (final Entry<String, Object> entry : config.getValues(true).entrySet()) {
        final String path = entry.getKey();
        final Object value = entry.getValue();
        // TODO: To support moving entire sections, this needs to be changed.
        if (value instanceof ConfigurationSection) {
            continue;
        }
        if (!prefixes.hasPrefix(path)) {
            newConfig.set(path, value);
        }
    }
    return newConfig;
}
Also used : SimpleCharPrefixTree(fr.neatmonster.nocheatplus.utilities.ds.prefixtree.SimpleCharPrefixTree) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with SimpleCharPrefixTree

use of fr.neatmonster.nocheatplus.utilities.ds.prefixtree.SimpleCharPrefixTree in project NoCheatPlus by NoCheatPlus.

the class TestSimpleCharPrefixTree method testPrefixWords.

@Test
public void testPrefixWords() {
    SimpleCharPrefixTree tree = new SimpleCharPrefixTree();
    tree.feedAll(feed, false, true);
    for (String input : mustFind) {
        if (!tree.hasPrefixWords(input)) {
            fail("Expect to be matched: '" + input + "'");
        }
    }
    for (String input : mustNotFind) {
        if (tree.hasPrefixWords(input)) {
            fail("Expect not to be matched: '" + input + "'");
        }
    }
}
Also used : SimpleCharPrefixTree(fr.neatmonster.nocheatplus.utilities.ds.prefixtree.SimpleCharPrefixTree) Test(org.junit.Test)

Aggregations

SimpleCharPrefixTree (fr.neatmonster.nocheatplus.utilities.ds.prefixtree.SimpleCharPrefixTree)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 Test (org.junit.Test)1