5. Set operations
Union
Collection union = new ArrayList(group1);
for (Object o : group1) {
if(!group2.contains(o)) {
union.add(o);
}
}
"
CollectionUtils.union(group1, group2);
6. Set operations
Intersection
Collection<Object> intersection = new ArrayList<>();
for (Object o : group1) {
if (group2.contains(o)) {
intersection.add(o);
}
}
for (Object o : group2) {
if (group1.contains(o)) {
intersection.add(o);
}
}
CollectionUtils.intersection(group1, group2);
7. Set operations
Disjunction
Collection<Object> disjunction = new ArrayList<>();
for (Object o : group1) {
if (!group2.contains(o)) {
disjunction.add(o);
}
}
for (Object o : group2) {
if (!group1.contains(o)) {
disjunction.add(o);
}
}
CollectionUtils.disjunction(group1, group2);
15. Transformer
private static class Campaign {
public enum Type {
Sales,
Service,
Other
}
public static final Transformer<Campaign, Campaign.Type> TO_TYPE = new Transformer<Campaign,
Type>() {
@Override
public Type transform(Campaign campaign) {
return campaign.getType();
}
};
private Type type;
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}