Skip to content

Commit

Permalink
(yegor256#1384) Add ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Sep 15, 2020
1 parent 171c9ae commit c678410
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/org/cactoos/map/MapOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import java.util.HashMap;
import java.util.Map;
import org.cactoos.Func;
import org.cactoos.Scalar;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Joined;
import org.cactoos.iterable.Mapped;
import org.cactoos.scalar.Unchecked;

/**
* Iterable as {@link Map}.
Expand Down Expand Up @@ -148,12 +150,20 @@ public MapOf(final Map<X, Y> src,
* @param entries List of the entries
*/
public MapOf(final Iterable<Map.Entry<X, Y>> entries) {
super(() -> {
this(() -> {
final Map<X, Y> temp = new HashMap<>(0);
for (final Map.Entry<X, Y> entry : entries) {
temp.put(entry.getKey(), entry.getValue());
}
return Collections.unmodifiableMap(temp);
});
}

/**
* Ctor.
* @param scalar The scalar for Map.
*/
public MapOf(final Scalar<Map<X, Y>> scalar) {
super(new Unchecked<>(scalar).value());
}
}

0 comments on commit c678410

Please sign in to comment.