ItemThreshold { static ItemThreshold fromConfigEntry(String entry) { if (Strings.isNullOrEmpty(entry)) { return null; } Inequality operator = Inequality.MORE_THAN; int qty = 0; for (int i = entry.length() - 1; i >= 0; i--) { char c = entry.charAt(i); if (c >= '0' && c <= '9' || Character.isWhitespace(c)) { continue; } switch (c) { case '<': operator = Inequality.LESS_THAN; case '>': if (i + 1 < entry.length()) { try { qty = Integer.parseInt(entry.substring(i + 1).trim()); } catch (NumberFormatException e) { qty = 0; operator = Inequality.MORE_THAN; } entry = entry.substring(0, i); } } break; } return new ItemThreshold(entry.trim(), qty, operator); }    }
@Test public void test() { Assert.assertEquals(ItemThreshold.fromConfigEntry("Dharok's platebody 100"), new ItemThreshold("Dharok's platebody 100", 0, MORE_THAN)); Assert.assertEquals(ItemThreshold.fromConfigEntry("Dharok's platebody 100<100"), new ItemThreshold("Dharok's platebody 100", 100, LESS_THAN)); Assert.assertEquals(ItemThreshold.fromConfigEntry("Dharok's platebody > 100"), new ItemThreshold("Dharok's platebody", 100, MORE_THAN)); Assert.assertEquals(ItemThreshold.fromConfigEntry("Dharok's platebody < 10 0"), new ItemThreshold("Dharok's platebody", 0, MORE_THAN)); }
@Test(timeout = 100) public void testExplosive() { String name = "archer" + Strings.repeat('e', 50000) + "s ring"; Assert.assertEquals(ItemThreshold.fromConfigEntry(name + " < 387"), new ItemThreshold(name, 387, LESS_THAN)); }