/** * Factory method to create a defaulting map. * <p> * The transformer specified is called when a missing key is found. * The key is passed to the transformer as the input, and the result * will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Transformer factory) { if (factory == null) { throw new IllegalArgumentException("Transformer must not be null"); } return new DefaultedMap(map, factory); }
/** * Factory method to create a defaulting map. * <p> * The transformer specified is called when a missing key is found. * The key is passed to the transformer as the input, and the result * will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Transformer factory) { if (factory == null) { throw new IllegalArgumentException("Transformer must not be null"); } return new DefaultedMap(map, factory); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
public void testMapGet() { Map map = new DefaultedMap("NULL"); assertEquals(0, map.size()); assertEquals(false, map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); map.put("Key", "Value"); assertEquals(1, map.size()); assertEquals(true, map.containsKey("Key")); assertEquals("Value", map.get("Key")); assertEquals(false, map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); }
/** * Factory method to create a defaulting map. * <p> * The transformer specified is called when a missing key is found. * The key is passed to the transformer as the input, and the result * will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Transformer factory) { if (factory == null) { throw new IllegalArgumentException("Transformer must not be null"); } return new DefaultedMap(map, factory); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
/** * Factory method to create a defaulting map. * <p> * The value specified is returned when a missing key is found. * * @param map the map to decorate, must not be null * @param defaultValue the default value to return when the key is not found * @throws IllegalArgumentException if map is null */ public static Map decorate(Map map, Object defaultValue) { if (defaultValue instanceof Transformer) { defaultValue = ConstantTransformer.getInstance(defaultValue); } return new DefaultedMap(map, defaultValue); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
/** * Factory method to create a defaulting map. * <p> * The factory specified is called when a missing key is found. * The result will be returned as the result of the map get(key) method. * * @param map the map to decorate, must not be null * @param factory the factory to use, must not be null * @throws IllegalArgumentException if map or factory is null */ public static Map decorate(Map map, Factory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } return new DefaultedMap(map, FactoryTransformer.getInstance(factory)); }
@SuppressWarnings({"rawtypes", "unchecked"}) private Map wrap2(Map m) { return Collections .unmodifiableMap(DefaultedMap.decorate(m, new DefaultedMap(new Value((Bytes) null)))); }
@SuppressWarnings({"rawtypes", "unchecked"}) private Map wrap2(Map m) { return Collections.unmodifiableMap(DefaultedMap.decorate(m, new DefaultedMap(new Value( (Bytes) null)))); }