public static void main(String[] args) { Map<String, String> map = PredicatedMap.predicatedMap(new CaseInsensitiveMap<String, String>(), NotNullPredicate.notNullPredicate(), NotNullPredicate.notNullPredicate()); map.put("one", "A"); System.out.println(map); System.out.printf("using oNe as the key to get the value from the map: %s\n", map.get("oNe")); System.out.println("Going to put a null key on the map"); try { map.put(null, "B"); } catch(Exception e) //I don't like that this process throws an exception. I'd much rather it just not put a null key in. { System.out.println(e.getMessage()); } //so to fix this I implemented my own using the abstractions provided by Commons Collections 4 Map<String, String> map2 = new FilteringPredicatedMap<>(); map2.put("one", "A"); map2.put(null, "B"); map2.put("three", null); map2.put("four", "D"); System.out.println(map2); Map<String, String> map3 = new FilteringPredicatedMap<>(new TreeMap<>(), (i -> i != null && i.equals("one")), FilteringPredicatedMap.nullPredicateInstance()); map3.put("one", "A"); map3.put(null, "B"); map3.put("three", null); map3.put("four", "D"); System.out.println(map3); }
/** * Test that all Predicate singletones hold singleton pattern in * serialization/deserialization process. */ @Test public void testSingletonPatternInSerialization() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testSingletonPatternInSerialization"); final Object[] singletones = new Object[]{ ExceptionPredicate.INSTANCE , FalsePredicate.INSTANCE , NotNullPredicate.INSTANCE , NullPredicate.INSTANCE , TruePredicate.INSTANCE }; for (final Object original : singletones) { org.apache.commons.collections4.TestUtils.assertSameAfterSerialization(("Singletone patern broken for " + (original.getClass())), original); } fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test that all Predicate singletones hold singleton pattern in * serialization/deserialization process. */ @Test(timeout = 1000) public void testSingletonPatternInSerialization_add2917() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testSingletonPatternInSerialization_add2917"); final Object[] singletones = new Object[]{ ExceptionPredicate.INSTANCE , FalsePredicate.INSTANCE , NotNullPredicate.INSTANCE , NullPredicate.INSTANCE , TruePredicate.INSTANCE }; for (final Object original : singletones) { org.apache.commons.collections4.TestUtils.assertSameAfterSerialization(("Singletone patern broken for " + (original.getClass())), original); org.apache.commons.collections4.TestUtils.assertSameAfterSerialization(("Singletone patern broken for " + (original.getClass())), original); } fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test that all Predicate singletones hold singleton pattern in * serialization/deserialization process. */ @Test public void testSingletonPatternInSerialization_literalMutation3032() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testSingletonPatternInSerialization_literalMutation3032"); final Object[] singletones = new Object[]{ ExceptionPredicate.INSTANCE , FalsePredicate.INSTANCE , NotNullPredicate.INSTANCE , NullPredicate.INSTANCE , TruePredicate.INSTANCE }; for (final Object original : singletones) { org.apache.commons.collections4.TestUtils.assertSameAfterSerialization(("foo" + (original.getClass())), original); } fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test that all Predicate singletones hold singleton pattern in * serialization/deserialization process. */ @Test(timeout = 1000) public void testSingletonPatternInSerialization_remove2351() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testSingletonPatternInSerialization_remove2351"); final Object[] singletones = new Object[]{ ExceptionPredicate.INSTANCE , FalsePredicate.INSTANCE , NotNullPredicate.INSTANCE , NullPredicate.INSTANCE , TruePredicate.INSTANCE }; for (final Object original : singletones) { } fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Gets a Predicate that checks if the input object passed in is not null. * * @param <T> the type that the predicate queries * @return the predicate * @see NotNullPredicate */ public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); }
/** * Returns a Builder with a NotNullPredicate. * * @param <E> the element type * @return a new Builder for predicated collections that ignores null values. * @since 4.1 */ public static <E> Builder<E> notNullBuilder() { return new Builder<E>(NotNullPredicate.<E>notNullPredicate()); }