functionalj.map.FuncMapBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalj-core Show documentation
Show all versions of functionalj-core Show documentation
The module for FunctionalJ Core.
package functionalj.map;
import java.util.ArrayList;
import java.util.List;
import functionalj.map.FuncMap.UnderlineMap;
import functionalj.tuple.Tuple;
import functionalj.tuple.Tuple2;
import lombok.val;
public class FuncMapBuilder {
private final List> entries;
public FuncMapBuilder() {
this.entries = new ArrayList>();
}
private FuncMapBuilder(List> entries) {
this.entries = entries;
}
public FuncMapBuilder with(K key, V value) {
this.entries.add(Tuple.of(key, value));
return new FuncMapBuilder<>(this.entries);
}
public ImmutableFuncMap build() {
val map = FuncMap.underlineMap.orElse(UnderlineMap.HashMap).newMap();
for (Tuple2 entry : this.entries) {
K key = entry._1();
V value = entry._2();
map.put(key, value);
}
return new ImmutableFuncMap(map);
}
}