All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.container.set.Sets Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy