Skip to content

Commit

Permalink
improved collections utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigi R. Viggiano committed Apr 8, 2014
1 parent 403e979 commit 5dd337f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions owner/src/main/java/org/aeonbits/owner/util/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,30 @@ private Collections() {}

private static class EntryMap<K, V> extends AbstractMap<K, V> implements Serializable {
private static final long serialVersionUID = -789853606407653214L;
private final Set<Entry<K, V>> entries;
private final Set<Entry<? extends K, ? extends V>> entries;

private EntryMap(Entry<K, V>... entries) {
private EntryMap(Entry<? extends K, ? extends V>... entries) {
this.entries = set(entries);
}

@SuppressWarnings("unchecked")
private EntryMap(K key, V value) {
this(entry(key, value));
}

@Override
public Set<Entry<K, V>> entrySet() {
return entries;
return (Set) entries;
}
}

public static <K, V> Entry<K, V> entry(K key, V value) {
return new SimpleEntry<K, V>(key, value);
}

@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> map(K key, V value) {
return new EntryMap<K, V>(key, value);
return map(entry(key, value));
}

public static <K, V> Map<K, V> map(Map.Entry<? extends K, ? extends V>... entries) {
return new EntryMap<K, V>(entries);
}

public static <E> Set<E> set(E... elements) {
Expand Down

0 comments on commit 5dd337f

Please sign in to comment.