fun.langel.cql.util.Pair Maven / Gradle / Ivy
The newest version!
package fun.langel.cql.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author [email protected](GuHan)
* @since 2022/5/16 15:57
**/
public class Pair {
public static final Pair EMPTY = new EmptyPair(null, null);
private final L left;
private final R right;
private Pair(final L left, final R right) {
this.left = left;
this.right = right;
}
public static Pair of(final LL left, final RR right) {
if (left == null && right == null) {
return empty();
}
return new Pair(left, right);
}
public static EmptyPair empty() {
return new EmptyPair();
}
public L left() {
return this.left;
}
public R right() {
return this.right;
}
public Map toMap() {
final Map map = new HashMap<>();
map.put(left(), right());
return map;
}
public static class EmptyPair extends Pair {
private EmptyPair(Object left, Object right) {
super(left, right);
}
private EmptyPair() {
this(null, null);
}
}
public static Map asMap(List> pairs) {
final Map map = new HashMap<>();
for (Pair pair : pairs) {
map.put(pair.left(), pair.right());
}
return map;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy