Skip to content

Commit

Permalink
(yegor256#1384) Fill new map at construction
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Sep 15, 2020
1 parent 41ce82e commit 0c4db78
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/main/java/org/cactoos/map/MapOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.cactoos.map;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.cactoos.Func;
Expand Down Expand Up @@ -147,23 +146,20 @@ public MapOf(final Map<X, Y> src,

/**
* Ctor.
* @param entries List of the entries
* @param scalar The scalar for Map.
*/
public MapOf(final Iterable<Map.Entry<X, Y>> entries) {
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);
});
public MapOf(final Scalar<Map<X, Y>> scalar) {
this(new Unchecked<>(scalar).value().entrySet());
}

/**
* Ctor.
* @param scalar The scalar for Map.
* @param entries List of the entries
*/
public MapOf(final Scalar<Map<X, Y>> scalar) {
super(new Unchecked<>(scalar).value());
public MapOf(final Iterable<Map.Entry<X, Y>> entries) {
super(new HashMap<>());
for (final Map.Entry<X, Y> entry : entries) {
this.put(entry.getKey(), entry.getValue());
}
}
}

0 comments on commit 0c4db78

Please sign in to comment.