io.github.nichetoolkit.rest.util.ShuntUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-toolkit-utils Show documentation
Show all versions of rest-toolkit-utils Show documentation
Rest toolkit utils project for Spring Boot
package io.github.nichetoolkit.rest.util;
import java.util.*;
/**
* ShuntUtils
* @author Cyan ([email protected])
* @version v1.0.0
*/
public class ShuntUtils {
public static void shunt(boolean key, T data, Collection falseCollection, Collection trueCollection) {
if (key) {
trueCollection.add(data);
} else {
falseCollection.add(data);
}
}
public static void shunt(K key, T data, Map> shuntMap) {
Optional.ofNullable(key).ifPresent(value -> {
if (shuntMap.containsKey(value)) {
shuntMap.get(value).add(data);
} else {
List cacheList = new ArrayList<>();
cacheList.add(data);
shuntMap.put(value, cacheList);
}
});
}
public static void shunt(K key, Collection dataCollection, Map> shuntMap) {
Optional.ofNullable(key).ifPresent(value -> {
if (shuntMap.containsKey(value)) {
shuntMap.get(value).addAll(dataCollection);
} else {
List cacheCollection = new ArrayList<>(dataCollection);
shuntMap.put(value, cacheCollection);
}
});
}
public static void shuntNull(K key, T data, Collection falseCollection, Map> trueMap) {
Optional optional = Optional.ofNullable(key);
if (optional.isPresent()) {
shunt(key, data, trueMap);
} else {
falseCollection.add(data);
}
}
public static void shuntNull(K key, T data, Collection falseCollection, Collection trueCollection) {
Optional optional = Optional.ofNullable(key);
if (optional.isPresent()) {
trueCollection.add(data);
} else {
falseCollection.add(data);
}
}
public static void shuntContrast(Long srcKey, Long targetKey, T data, Collection equalCollection, Map> unequalMap) {
if (srcKey.equals(targetKey)) {
equalCollection.add(data);
} else {
shunt(targetKey, data, unequalMap);
}
}
public static void shuntContrast(K srcKey, K targetKey, T data, Collection equalCollection, Collection unequalCollection) {
if (srcKey.equals(targetKey)) {
equalCollection.add(data);
} else {
unequalCollection.add(data);
}
}
public static void shuntContain(K srcKey, Collection targetKeyCollection, T data, Map> shuntMap) {
if (targetKeyCollection.contains(srcKey)) {
shunt(srcKey,data,shuntMap);
}
}
}