Skip to content

Commit

Permalink
#1650 static map maker
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 21, 2022
1 parent 7a432b4 commit bbd4ffc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/org/cactoos/map/MapOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,20 @@ public MapOf(
* @param entries List of the entries
*/
public MapOf(final Iterable<Map.Entry<? extends X, ? extends Y>> entries) {
super(new HashMap<>(0));
super(MapOf.make(entries));
}

/**
* Ctor.
* @param entries List of the entries
* @return Map created
*/
private static <X, Y> Map<X, Y> make(
final Iterable<Map.Entry<? extends X, ? extends Y>> entries) {
final Map<X, Y> map = new HashMap<>(0);
for (final Map.Entry<? extends X, ? extends Y> entry : entries) {
this.put(entry.getKey(), entry.getValue());
map.put(entry.getKey(), entry.getValue());
}
return map;
}
}

0 comments on commit bbd4ffc

Please sign in to comment.