WildcardMatchLoader extends CacheLoader<NamedQuantity, Boolean> { @Override public Boolean load(@Nonnull final NamedQuantity key) { if (Strings.isNullOrEmpty(key.getName())) { return false; } final String filteredName = key.getName().trim(); for (final ItemThreshold entry : itemThresholds) { if (WildcardMatcher.matches(entry.getItemName(), filteredName) && entry.quantityHolds(key.getQuantity())) { return true; } } return false; } WildcardMatchLoader(List<String> configEntries); @Override Boolean load(@Nonnull final NamedQuantity key);  }
@Test public void testLoadItems() { WildcardMatchLoader loader = new WildcardMatchLoader(Arrays.asList("rune*", "Abyssal whip")); assertTrue(loader.load(new NamedQuantity("rune pouch", 1))); assertTrue(loader.load(new NamedQuantity("Rune pouch", 1))); assertFalse(loader.load(new NamedQuantity("Adamant dagger", 1))); assertTrue(loader.load(new NamedQuantity("Runeite Ore", 1))); assertTrue(loader.load(new NamedQuantity("Abyssal whip", 1))); assertFalse(loader.load(new NamedQuantity("Abyssal dagger", 1))); }
@Test public void testLoadQuantities() { WildcardMatchLoader loader = new WildcardMatchLoader(Arrays.asList("rune* < 3", "*whip>3", "nature*<5", "*rune > 30")); assertTrue(loader.load(new NamedQuantity("Nature Rune", 50))); assertFalse(loader.load(new NamedQuantity("Nature Impling", 5))); assertTrue(loader.load(new NamedQuantity("Abyssal whip", 4))); assertFalse(loader.load(new NamedQuantity("Abyssal dagger", 1))); assertTrue(loader.load(new NamedQuantity("Rune Longsword", 2))); }
@Test(timeout = 1000) public void testExplosive() { String name = "archer" + Strings.repeat('e', 50000) + "s ring"; WildcardMatchLoader loader = new WildcardMatchLoader(Arrays.asList(name + "* < 100")); assertTrue(loader.load(new NamedQuantity(name, 50))); assertFalse(loader.load(new NamedQuantity(name, 150))); }