/** * 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); }
public Map makeEmptyMap() { return DefaultedMap.decorate(new HashMap(), nullFactory); }
@SuppressWarnings({"rawtypes", "unchecked"}) private Map wrap2(Map m) { return Collections .unmodifiableMap(DefaultedMap.decorate(m, new DefaultedMap(new Value((Bytes) null)))); }
public void enableVersioning(DatabaseType dbType, Connection connection) { try { String ddl = format((String) enableVersioningDDL.get(dbType), versionTable, versionColumn, appliedDateColumn, durationColumn); connection.createStatement().executeUpdate(ddl); } catch (SQLException e) { throw new MigrationException("Could not create version-tracking table '" + versionTable + "'.", e); } }
@SuppressWarnings({"rawtypes", "unchecked"}) private Map wrap2(Map m) { return Collections.unmodifiableMap(DefaultedMap.decorate(m, new DefaultedMap(new Value( (Bytes) null)))); }
/** * 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); }
public void testMapGet2() { HashMap base = new HashMap(); Map map = DefaultedMap.decorate(base, "NULL"); assertEquals(0, map.size()); assertEquals(0, base.size()); assertEquals(false, map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); map.put("Key", "Value"); assertEquals(1, map.size()); assertEquals(1, base.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 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); }
public void testMapGet3() { HashMap base = new HashMap(); Map map = DefaultedMap.decorate(base, ConstantFactory.getInstance("NULL")); assertEquals(0, map.size()); assertEquals(0, base.size()); assertEquals(false, map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); map.put("Key", "Value"); assertEquals(1, map.size()); assertEquals(1, base.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 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 testMapGet4() { HashMap base = new HashMap(); Map map = DefaultedMap.decorate(base, new Transformer() { public Object transform(Object input) { if (input instanceof String) { return "NULL"; } return "NULL_OBJECT"; } }); assertEquals(0, map.size()); assertEquals(0, base.size()); assertEquals(false, map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); assertEquals("NULL_OBJECT", map.get(new Integer(0))); map.put("Key", "Value"); assertEquals(1, map.size()); assertEquals(1, base.size()); assertEquals(true, map.containsKey("Key")); assertEquals("Value", map.get("Key")); assertEquals(false, map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); assertEquals("NULL_OBJECT", map.get(new Integer(0))); }
/** * 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); }
@SuppressWarnings({"unchecked"}) private Map<Column, Value> wrap(Map<Column, Bytes> map) { Map<Column, Value> ret = Maps.transformValues(map, new Function<Bytes, Value>() { @Override public Value apply(Bytes input) { return new Value(input); } }); return Collections.unmodifiableMap(DefaultedMap.decorate(ret, new Value((Bytes) null))); }
/** * 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({"unchecked"}) private Map<Column, Value> wrap(Map<Column, Bytes> map) { Map<Column, Value> ret = Maps.transformValues(map, input -> new Value(input)); return Collections.unmodifiableMap(DefaultedMap.decorate(ret, new Value((Bytes) null))); }
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 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 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); }