Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * Finds the value that belongs to the given key in the given map. * If the key is null or no value is found, an {@link IllegalStateException} is thrown. */ public static <T1, T2> T2 find(T1 key, Map<T1, T2> map) throws IllegalStateException { if (key == null) throw new IllegalStateException("Key is null"); T2 ret = map.get(key); if (ret == null) throw new IllegalStateException("No value for key " + key); return ret; } }