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

jedi.option.Options Maven / Gradle / Ivy

The newest version!
package jedi.option;

import java.util.Map;

/**
 * A factory of option types for convenience and static importing, and other
 * utility methods.
 */
public final class Options {

	/**
	 * Factory method for Some.
	 * 
	 * @return Some(value)
	 */
	public static  Option some(T value) {
		return new Some(value);
	}

	/**
	 * Factory method for None.
	 * 
	 * @return None
	 */
	public static  Option none() {
		return new None();
	}

	/**
	 * @return Some(value) or None if value is null
	 */
	public static  Option option(T value) {
		return value == null ? Options. none() : some(value);
	}

	/**
	 * Get an Option for a key's value in a Map.
	 * 
	 * @param map
	 *            the map to retrieve a value from
	 * @param key
	 *            the key to use
	 * @return None if the map does not contain a value for key or the value is null.
	 *         Some(value) if the map did contain a non-null value for key.
	 */
	public static  Option get(Map map, K key) {
		return option(map.get(key));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy