List of usage examples for org.apache.commons.collections.map PredicatedMap decorate
public static Map decorate(Map map, Predicate keyPredicate, Predicate valuePredicate)
From source file:com.discursive.jccook.collections.predicate.PredicatedMapExample.java
public void start() { // Create the Predicates ValidTeamPredicate validTeam = new ValidTeamPredicate(); ValidCoachPredicate validCoach = new ValidCoachPredicate(); // Tie two Predicates together into an AndPredicate AndPredicate valuePredicate = new AndPredicate(validTeam, validCoach); // Decorate a HashMap with a predicate on the value teamMap = PredicatedMap.decorate(new HashMap(), null, valuePredicate); // Manufacture some teams Team redSox = new Team("Red Sox", new Coach("Patrick", "Moloney")); Team yankees = new Team("Yankees", new Coach("David", "McGarry")); Team dodgers = new Team("Dodgers", new Coach("Nick", "Taylor")); Team twins = new Team(null, new Coach("Patrick", "Moloney")); Team braves = new Team("Braves", null); // The follow put calls should work fine teamMap.put("RedSox", redSox); teamMap.put("Yankees", yankees); teamMap.put("Dodgers", dodgers); // This put should fail because the team name is null try {//from ww w . ja v a 2 s. c om teamMap.put("Twins", twins); } catch (IllegalArgumentException iae) { System.out.println("Twins put failed, as expected"); } // This put should fail because the coach is null try { teamMap.put("Braves", braves); } catch (IllegalArgumentException iae) { System.out.println("Braves put failed, as expected"); } }
From source file:com.discursive.jccook.collections.predicate.ImprovedPredicatedMapExample.java
public void start() { // Create the Predicates PropertyPredicate teamName = new PropertyPredicate("name"); PropertyPredicate coachFirstName = new PropertyPredicate("coach.firstName"); PropertyPredicate coachLastName = new PropertyPredicate("coach.lastName"); // Tie three Predicates together into an AllPredicate Predicate[] predicateArray = new Predicate[] { teamName, coachFirstName, coachLastName }; AllPredicate valuePredicate = new AllPredicate(predicateArray); // Decorate a HashMap with a predicate on the value teamMap = PredicatedMap.decorate(new HashMap(), null, valuePredicate); // Manufacture some teams Team redSox = new Team("Red Sox", new Coach("Patrick", "Moloney")); Team yankees = new Team("Yankees", new Coach("David", "McGarry")); Team dodgers = new Team("Dodgers", new Coach("Nick", "Taylor")); Team twins = new Team(null, new Coach("Patrick", "Moloney")); Team braves = new Team("Braves", null); // The follow put calls should work fine teamMap.put("RedSox", redSox); teamMap.put("Yankees", yankees); teamMap.put("Dodgers", dodgers); // This put should fail because the team name is null try {//www . j av a 2s . c om teamMap.put("Twins", twins); } catch (IllegalArgumentException iae) { System.out.println("Twins put failed, as expected"); } // This put should fail because the coach is null try { teamMap.put("Braves", braves); } catch (IllegalArgumentException iae) { System.out.println("Braves put failed, as expected"); } }
From source file:com.discursive.jccook.collections.predicate.XPathPredicatedMapExample.java
public void start() { // Create the Predicates Predicate teamName = new XPathPredicate("./name"); Predicate coachFirstName = new XPathPredicate("./coach/firstName"); Predicate coachLastName = new XPathPredicate("./coach/lastName"); // Create a predicate that rejects all teams with name Dodgers Map variables = new HashMap(); variables.put("name", "Dodgers"); Predicate noDodgers = new NotPredicate(new XPathPredicate("./name[. = $name]", variables)); // Tie three Predicates together into an AllPredicate Predicate[] predicateArray = new Predicate[] { teamName, coachFirstName, coachLastName, noDodgers }; AllPredicate valuePredicate = new AllPredicate(predicateArray); // Decorate a HashMap with a predicate on the value teamMap = PredicatedMap.decorate(new HashMap(), null, valuePredicate); // Manufacture some teams Team redSox = new Team("Red Sox", new Coach("Patrick", "Moloney")); Team yankees = new Team("Yankees", new Coach("David", "McGarry")); Team dodgers = new Team("Dodgers", new Coach("Nick", "Taylor")); Team twins = new Team(null, new Coach("Patrick", "Moloney")); Team braves = new Team("Braves", null); // The follow put calls should work fine teamMap.put("RedSox", redSox); teamMap.put("Yankees", yankees); // This should fail because we have a predicate checking for "Dodgers" and rejecting try {/*from w ww.j ava 2s .c o m*/ teamMap.put("Dodgers", dodgers); } catch (IllegalArgumentException iae) { System.out.println("Dodgers put failed, as expected"); } // This put should fail because the team name is null try { teamMap.put("Twins", twins); } catch (IllegalArgumentException iae) { System.out.println("Twins put failed, as expected"); } // This put should fail because the coach is null try { teamMap.put("Braves", braves); } catch (IllegalArgumentException iae) { System.out.println("Braves put failed, as expected"); } }
From source file:org.displaytag.portlet.PortletHref.java
private Map createParameterMap() { return PredicatedMap.decorate(new HashMap(), PRED_TYPE_OF_STRING, PRED_OR_STR_STRARR); }
From source file:org.robotframework.javalib.keyword.KeywordMap.java
public KeywordMap() { map = new HashedMap(); map = PredicatedMap.decorate(map, UniquePredicate.getInstance(), TruePredicate.INSTANCE); map = PredicatedMap.decorate(map, NotNullPredicate.INSTANCE, NotNullPredicate.INSTANCE); }