com.softicar.platform.common.container.set.Sets Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.set;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
/**
* Auxiliary methods for {@link Set} instances.
*
* @author Oliver Richers
*/
public class Sets {
/**
* Same as {@link #difference(Set, Set, Function)} using {@link HashSet}.
*/
public static Set difference(Set a, Set b) {
return difference(a, b, HashSet::new);
}
/**
* Computes the difference between two {@link Set} instances.
*
* @param a
* the first {@link Set} (never null)
* @param b
* the {@link Set} to substract from the first {@link Set} (never
* null)
* @param factory
* the factory for the returned {@link Set} (never null)
* @return a new {@link Set} with all elements from the first {@link Set}
* that are not contained in the second {@link Set} (never
* null)
*/
public static Set difference(Set a, Set b, Function, Set> factory) {
Set difference = factory.apply(a);
difference.removeAll(b);
return difference;
}
}