com.softicar.platform.common.container.map.set.SetMaps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.map.set;
import com.softicar.platform.common.container.map.list.ListTreeMap;
import com.softicar.platform.common.core.exceptions.SofticarDeveloperException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.TreeSet;
public class SetMaps {
public static , T extends Comparable> Map toInvertedMap(SetMap input, boolean allowCollisions) {
Map output = new TreeMap<>();
for (Entry> entry: input.entrySet()) {
S inputKey = entry.getKey();
for (T inputValue: entry.getValue()) {
if (allowCollisions || !output.containsKey(inputValue)) {
output.put(inputValue, inputKey);
} else {
throw new SofticarDeveloperException("Collision detected while inverting a %s (in collision-free mode).", SetMap.class.getSimpleName());
}
}
}
return output;
}
public static , T extends Comparable> SetMap toInvertedSetMap(SetMap input) {
SetMap output = new SetMap<>();
for (Entry> entry: input.entrySet()) {
S inputKey = entry.getKey();
for (T inputValue: entry.getValue()) {
output.addToSet(inputValue, inputKey);
}
}
return output;
}
public static , T extends Comparable> ListTreeMap toListMap(SetMap input) {
ListTreeMap output = new ListTreeMap<>();
for (Entry> entry: input.entrySet()) {
S inputKey = entry.getKey();
for (T inputValue: entry.getValue()) {
output.addToList(inputValue, inputKey);
}
}
return output;
}
}