Skip to content

Commit

Permalink
Auto-expanding maps of maps of collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jun 4, 2016
1 parent aaf9348 commit a1efde2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rapidoid-commons/src/main/java/org/rapidoid/commons/Coll.java
Expand Up @@ -264,9 +264,21 @@ public Map<K2, V> map(K1 src) throws Exception {
});
}

public static <K1, K2, K3, V> Map<K1, Map<K2, Map<K3, V>>> mapOfMapOfMaps() {
return autoExpandingMap(new Mapper<K1, Map<K2, Map<K3, V>>>() {

@Override
public Map<K2, Map<K3, V>> map(K1 src) throws Exception {
return mapOfMaps();
}

});
}

public static <K, V> Map<K, List<V>> mapOfLists() {
return autoExpandingMap(new Mapper<K, List<V>>() {

@SuppressWarnings("unchecked")
@Override
public List<V> map(K src) throws Exception {
return synchronizedList();
Expand All @@ -275,9 +287,21 @@ public List<V> map(K src) throws Exception {
});
}

public static <K1, K2, V> Map<K1, Map<K2, List<V>>> mapOfMapOfLists() {
return autoExpandingMap(new Mapper<K1, Map<K2, List<V>>>() {

@Override
public Map<K2, List<V>> map(K1 src) throws Exception {
return mapOfLists();
}

});
}

public static <K, V> Map<K, Set<V>> mapOfSets() {
return autoExpandingMap(new Mapper<K, Set<V>>() {

@SuppressWarnings("unchecked")
@Override
public Set<V> map(K src) throws Exception {
return synchronizedSet();
Expand All @@ -286,6 +310,17 @@ public Set<V> map(K src) throws Exception {
});
}

public static <K1, K2, V> Map<K1, Map<K2, Set<V>>> mapOfMapOfSets() {
return autoExpandingMap(new Mapper<K1, Map<K2, Set<V>>>() {

@Override
public Map<K2, Set<V>> map(K1 src) throws Exception {
return mapOfSets();
}

});
}

public static <T> List<T> range(Iterable<T> items, int from, int to) {
U.must(from <= to, "'from' must be <= 'to'!");

Expand Down

0 comments on commit a1efde2

Please sign in to comment.