package com.voodoodyne.gstrap.lang;

import java.util.Collection;
import java.util.Map;


/**
 * Utility methods for comparison and list testing that are typesafe.  Gets around the annoying problem with
 * Set.contains(), Map.get(), etc which doesn't give you compiler checking if you change the type of the
 * value passed in.
 */
public class Safe
{
	/**
	 * Adds and checks for null.
	 */
	public static <T> boolean addNotNull(Collection<T> coll, T element) {
		if (element == null)
			throw new NullPointerException();
		
		return coll.add(element);
	}

	/**
	 * Collection.contains() but with type safety. 
	 */
	public static <T> boolean contains(final Collection<T> coll, T element) {
		return coll.contains(element);
	}
	
	/**
	 * Collection.remove() but with type safety.
	 */
	public static <T> boolean remove(final Collection<T> coll, T element) {
		return coll.remove(element);
	}
	
	/**
	 * Map.remove() but with type safety.
	 */
	public static <K, V> V remove(final Map<K, V> map, K key) {
		return map.remove(key);
	}
	
	/**
	 * Map.get() but with type safety.
	 */
	public static <K, V> V get(final Map<K, V> map, K key) {
		return map.get(key);
	}
}
@@ -1208,10 +1208,283 @@
 y);%0D%0A%09%7D%0D
+%0A%0D%0A%09/**%0D%0A%09 * Map.get() but with type safety.%0D%0A%09 * @return the defaultValue if the result of get() is null%0D%0A%09 */%0D%0A%09public static %3CK, V%3E V get(final Map%3CK, V%3E map, K key, V defaultValue) %7B%0D%0A%09%09final V value = get(map, key);%0D%0A%09%09return value == null ? defaultValue : value;%0D%0A%09%7D%0D
 %0A%7D

Add Safe.get() overload with a defaultValue