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

org.sellcom.javafx.collection.ObservableEnumSet Maven / Gradle / Ivy

/*
 * Copyright (c) 2015-2017 Petr Zelenka .
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sellcom.javafx.collection;

import static javafx.collections.FXCollections.observableSet;

import java.util.EnumSet;

import org.sellcom.core.Contract;

import javafx.collections.ObservableSet;

/**
 * Operations with {@link ObservableSet}s of enum types.
 *
 * @since 1.0
 *
 * @see EnumSet
 * @see ObservableSet
 */
public class ObservableEnumSet {

	private ObservableEnumSet() {
		// Utility class, not to be instantiated
	}


	/**
	 * Creates an observable set containing all the elements in the given element type.
	 *
	 * @throws IllegalArgumentException if {@code elementType} is {@code null}
	 *
	 * @since 1.0
	 *
	 * @see EnumSet#allOf(Class)
	 */
	public static > ObservableSet allOf(Class elementType) {
		Contract.checkArgument(elementType != null, "Element type must not be null");

		return observableSet(EnumSet.allOf(elementType));
	}

	/**
	 * Creates an observable set containing all the elements not contained in the given enum set.
	 *
	 * @throws IllegalArgumentException if {@code enumSet} is {@code null}
	 *
	 * @since 1.0
	 *
	 * @see EnumSet#complementOf(EnumSet)
	 */
	public static > ObservableSet complementOf(EnumSet enumSet) {
		Contract.checkArgument(enumSet != null, "Enum set must not be null");

		return observableSet(EnumSet.complementOf(enumSet));
	}

	/**
	 * Creates an empty observable set with the given element type.
	 *
	 * @throws IllegalArgumentException if {@code elementType} is {@code null}
	 *
	 * @since 1.0
	 *
	 * @see EnumSet#noneOf(Class)
	 */
	public static > ObservableSet noneOf(Class elementType) {
		Contract.checkArgument(elementType != null, "Element type must not be null");

		return observableSet(EnumSet.noneOf(elementType));
	}

	/**
	 * Creates an observable set containing the given elements.
	 *
	 * @throws IllegalArgumentException if {@code firstElement} is {@code null}
	 *
	 * @since 1.0
	 *
	 * @see EnumSet#of(Enum, Enum...)
	 */
	@SafeVarargs
	public static > ObservableSet of(E firstElement, E... otherElements) {
		Contract.checkArgument(firstElement != null, "First element set must not be null");

		return observableSet(EnumSet.of(firstElement, otherElements));
	}

	/**
	 * Creates an observable set containing all the elements in the given range.
	 * Both the first element and the last element are inclusive.
	 *
	 * @throws IllegalArgumentException if {@code firstElement} is {@code null}
	 * @throws IllegalArgumentException if {@code lastElement} is {@code null}
	 *
	 * @since 1.0
	 *
	 * @see EnumSet#range(Enum, Enum)
	 */
	public static > ObservableSet range(E firstElement, E lastElement) {
		Contract.checkArgument(firstElement != null, "First element set must not be null");
		Contract.checkArgument(lastElement != null, "Last element set must not be null");

		return observableSet(EnumSet.range(firstElement, lastElement));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy