@Test public void one() { final List<String> values = asList("a", "b", "a", "c", "a", "d", "e"); assertTrue(Algorithms.one(values, Conditions.eq("c"))); assertTrue(Algorithms.one(values, Conditions.eq("a"))); assertTrue(Algorithms.one(values, Conditions.eq("e"))); assertFalse(Algorithms.one(values, Conditions.eq("f"))); }
@SuppressWarnings({"ImplicitNumericConversion"}) @Test public void count() { final List<String> values = asList("a", "b", "a", "c", "a", "d", "e"); assertEquals(3, Algorithms.count(values, Conditions.eq("a"))); assertEquals(1, Algorithms.count(values, Conditions.eq("e"))); assertEquals(0, Algorithms.count(values, Conditions.eq("f"))); }
@Test public void first() { final List<String> values = asList("a", "b", "a", "c", "a", "d", "e"); assertEquals("c", Algorithms.first(values, Conditions.eq("c"))); assertEquals("a", Algorithms.first(values, Conditions.eq("a"))); assertEquals("e", Algorithms.first(values, Conditions.eq("e"))); assertNull(Algorithms.first(values, Conditions.eq("f"))); }
@Test public void select2() { final List<String> values = asList("a", "b", "a", "c", "a", "d", "e"); assertEquals( asList("a", "a", "a"), Algorithms.select(values, new ArrayList<String>(10), Conditions.eq("a"))); }
@Test public void all() { final List<String> values = asList("a", "b", "a", "c", "a", "d", "e"); assertTrue(Algorithms.all(values, Conditions.gte("a"))); assertTrue(Algorithms.all(values, Conditions.lt("z"))); assertTrue(Algorithms.all(values, Conditions.lte("e"))); assertFalse(Algorithms.all(values, Conditions.gt("b"))); assertFalse(Algorithms.all(values, Conditions.eq("a"))); assertFalse(Algorithms.all(values, Conditions.eq("f"))); }