/** * <p>Returns the elements as a MutableMap applying the keyFunction and valueFunction to each element.</p> * <p>Examples:</p> * {@code MutableMap<Integer, String> map1 = * Interval.oneTo(5).stream().collect(Collectors2.toMap(Functions.identity(), Object::toString));}<br> * {@code MutableMap<Integer, String> map2 = * Interval.oneTo(5).reduceInPlace(Collectors2.toMap(Functions.identity(), Object::toString));} * <p> * Equivalent to using @{@link RichIterable#toMap(Function, Function)} * </p> * {@code MutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString);} */ public static <T, K, V> Collector<T, ?, MutableMap<K, V>> toMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collector.of( Maps.mutable::empty, (map, each) -> map.put(keyFunction.valueOf(each), valueFunction.valueOf(each)), (r1, r2) -> { r1.putAll(r2); return r1; }, EMPTY_CHARACTERISTICS); }
/** * <p>Returns the elements as a MutableMap applying the keyFunction and valueFunction to each element.</p> * <p>Examples:</p> * {@code MutableMap<Integer, String> map1 = * Interval.oneTo(5).stream().collect(Collectors2.toMap(Functions.identity(), Object::toString));}<br> * {@code MutableMap<Integer, String> map2 = * Interval.oneTo(5).reduceInPlace(Collectors2.toMap(Functions.identity(), Object::toString));} * <p> * Equivalent to using @{@link RichIterable#toMap(Function, Function)} * </p> * {@code MutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString);} */ public static <T, K, V> Collector<T, ?, MutableMap<K, V>> toMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collector.of( Maps.mutable::empty, (map, each) -> map.put(keyFunction.valueOf(each), valueFunction.valueOf(each)), (r1, r2) -> { r1.putAll(r2); return r1; }, EMPTY_CHARACTERISTICS); }
/** * <p>Returns the elements as an ImmutableMap applying the keyFunction and valueFunction to each element.</p> * <p>Examples:</p> * {@code ImmutableMap<Integer, String> map1 = * Interval.oneTo(5).stream().collect(Collectors2.toImmutableMap(Functions.identity(), Object::toString));}<br> * {@code ImmutableMap<Integer, String> map2 = * Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableMap(Functions.identity(), Object::toString));} * <p> * Equivalent to using @{@link RichIterable#toMap(Function, Function)} * </p> * {@code ImmutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString).toImmutable();} */ public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collector.<T, MutableMap<K, V>, ImmutableMap<K, V>>of( Maps.mutable::empty, (map, each) -> map.put(keyFunction.valueOf(each), valueFunction.valueOf(each)), (r1, r2) -> { r1.putAll(r2); return r1; }, MutableMap::toImmutable, EMPTY_CHARACTERISTICS); }
/** * <p>Returns the elements as an ImmutableMap applying the keyFunction and valueFunction to each element.</p> * <p>Examples:</p> * {@code ImmutableMap<Integer, String> map1 = * Interval.oneTo(5).stream().collect(Collectors2.toImmutableMap(Functions.identity(), Object::toString));}<br> * {@code ImmutableMap<Integer, String> map2 = * Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableMap(Functions.identity(), Object::toString));} * <p> * Equivalent to using @{@link RichIterable#toMap(Function, Function)} * </p> * {@code ImmutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString).toImmutable();} */ public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collector.<T, MutableMap<K, V>, ImmutableMap<K, V>>of( Maps.mutable::empty, (map, each) -> map.put(keyFunction.valueOf(each), valueFunction.valueOf(each)), (r1, r2) -> { r1.putAll(r2); return r1; }, MutableMap::toImmutable, EMPTY_CHARACTERISTICS); }
@Override public void combineOne(SumByBigDecimalProcedure<T, V> thingToCombine) { if (this.result.isEmpty()) { this.result.putAll(thingToCombine.getResult()); } else { thingToCombine.getResult().forEachKeyValue((key, value) -> this.result.updateValue(key, Functions0.zeroBigDecimal(), original -> original.add(value))); } } }
@Override public void combineOne(SumByBigIntegerProcedure<T, V> thingToCombine) { if (this.result.isEmpty()) { this.result.putAll(thingToCombine.getResult()); } else { thingToCombine.getResult().forEachKeyValue((key, value) -> this.result.updateValue(key, Functions0.zeroBigInteger(), original -> original.add(value))); } } }
@Override public void combineOne(SumByBigIntegerProcedure<T, V> thingToCombine) { if (this.result.isEmpty()) { this.result.putAll(thingToCombine.getResult()); } else { thingToCombine.getResult().forEachKeyValue((key, value) -> this.result.updateValue(key, Functions0.zeroBigInteger(), original -> original.add(value))); } } }
@Override public void combineOne(SumByBigDecimalProcedure<T, V> thingToCombine) { if (this.result.isEmpty()) { this.result.putAll(thingToCombine.getResult()); } else { thingToCombine.getResult().forEachKeyValue((key, value) -> this.result.updateValue(key, Functions0.zeroBigDecimal(), original -> original.add(value))); } } }
/** * <p>Returns the elements as an ImmutableMap applying the keyFunction and valueFunction to each element.</p> * <p>Examples:</p> * {@code ImmutableMap<Integer, String> map1 = * Interval.oneTo(5).stream().collect(Collectors2.toImmutableMap(Functions.identity(), Object::toString));}<br> * {@code ImmutableMap<Integer, String> map2 = * Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableMap(Functions.identity(), Object::toString));} * <p> * Equivalent to using @{@link RichIterable#toMap(Function, Function)} * </p> * {@code ImmutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString).toImmutable();} */ public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collector.<T, MutableMap<K, V>, ImmutableMap<K, V>>of( Maps.mutable::empty, (map, each) -> map.put(keyFunction.valueOf(each), valueFunction.valueOf(each)), (r1, r2) -> { r1.putAll(r2); return r1; }, MutableMap::toImmutable, EMPTY_CHARACTERISTICS); }
/** * <p>Returns the elements as a MutableMap applying the keyFunction and valueFunction to each element.</p> * <p>Examples:</p> * {@code MutableMap<Integer, String> map1 = * Interval.oneTo(5).stream().collect(Collectors2.toMap(Functions.identity(), Object::toString));}<br> * {@code MutableMap<Integer, String> map2 = * Interval.oneTo(5).reduceInPlace(Collectors2.toMap(Functions.identity(), Object::toString));} * <p> * Equivalent to using @{@link RichIterable#toMap(Function, Function)} * </p> * {@code MutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString);} */ public static <T, K, V> Collector<T, ?, MutableMap<K, V>> toMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collector.of( Maps.mutable::empty, (map, each) -> map.put(keyFunction.valueOf(each), valueFunction.valueOf(each)), (r1, r2) -> { r1.putAll(r2); return r1; }, EMPTY_CHARACTERISTICS); }
@Override public void combineOne(SumByBigDecimalProcedure<T, V> thingToCombine) { if (this.result.isEmpty()) { this.result.putAll(thingToCombine.getResult()); } else { thingToCombine.getResult().forEachKeyValue((key, value) -> this.result.updateValue(key, Functions0.zeroBigDecimal(), original -> original.add(value))); } } }
@Override public void combineOne(SumByBigIntegerProcedure<T, V> thingToCombine) { if (this.result.isEmpty()) { this.result.putAll(thingToCombine.getResult()); } else { thingToCombine.getResult().forEachKeyValue((key, value) -> this.result.updateValue(key, Functions0.zeroBigInteger(), original -> original.add(value))); } } }
protected Main() { // use the hashing strategy to allow commands of any case to be handled MutableMap<String, Procedure<String[]>> commandMap = HashingStrategyMaps.mutable.of(HashingStrategies.fromFunction(new Function<String, String>() { @Override public String valueOf(String s) { return s.toLowerCase(); } })); commandMap.putAll(getCommandMap().toMap()); this.commandMap = commandMap.toImmutable(); }
@Override public String prepare(String content, ChangeInput change, DbEnvironment env) { MutableMap<String, String> tokens = Maps.mutable.<String, String>empty() .withKeyValue("dbSchemaSuffix", env.getDbSchemaSuffix()) .withKeyValue("dbSchemaPrefix", env.getDbSchemaPrefix()); for (Schema schema : env.getSchemas()) { PhysicalSchema physicalSchema = env.getPhysicalSchema(schema.getName()); tokens.put(schema.getName() + "_physicalName", physicalSchema.getPhysicalName()); if (env.getPlatform() != null) { tokens.put(schema.getName() + "_schemaSuffixed", env.getPlatform().getSchemaPrefix(physicalSchema)); tokens.put(schema.getName() + "_subschemaSuffixed", env.getPlatform().getSubschemaPrefix(physicalSchema)); } } if (env.getDefaultTablespace() != null) { tokens.put("defaultTablespace", env.getDefaultTablespace()); } tokens.putAll(env.getTokens().castToMap()); // allow clients to override these values if needed return new Tokenizer(tokens, env.getTokenPrefix(), env.getTokenSuffix()).tokenizeString(content); } }
@Override public String prepare(String content, ChangeInput change, DbEnvironment env) { MutableMap<String, String> tokens = Maps.mutable.<String, String>empty() .withKeyValue("dbSchemaSuffix", env.getDbSchemaSuffix()) .withKeyValue("dbSchemaPrefix", env.getDbSchemaPrefix()); for (Schema schema : env.getSchemas()) { PhysicalSchema physicalSchema = env.getPhysicalSchema(schema.getName()); tokens.put(schema.getName() + "_physicalName", physicalSchema.getPhysicalName()); if (env.getPlatform() != null) { tokens.put(schema.getName() + "_schemaSuffixed", env.getPlatform().getSchemaPrefix(physicalSchema)); tokens.put(schema.getName() + "_subschemaSuffixed", env.getPlatform().getSubschemaPrefix(physicalSchema)); } } if (env.getDefaultTablespace() != null) { tokens.put("defaultTablespace", env.getDefaultTablespace()); } tokens.putAll(env.getTokens().castToMap()); // allow clients to override these values if needed return new Tokenizer(tokens, env.getTokenPrefix(), env.getTokenSuffix()).tokenizeString(content); } }