feat: new object with 'of' method

This commit is contained in:
easepan 2020-09-09 18:32:17 +08:00
parent 5440cff37f
commit 018999e18f
2 changed files with 25 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Arrays;
/** /**
* 比较器链此链包装了多个比较器最终比较结果按照比较器顺序综合多个比较器结果<br> * 比较器链此链包装了多个比较器最终比较结果按照比较器顺序综合多个比较器结果<br>
@ -81,6 +82,26 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
orderingBits = bits; orderingBits = bits;
} }
public static <E> ComparatorChain<E> of(Comparator<E> comparator) {
return of(comparator, false);
}
public static <E> ComparatorChain<E> of(Comparator<E> comparator, boolean reverse) {
return new ComparatorChain<>(comparator, reverse);
}
public static <E> ComparatorChain<E> of(Comparator<E>... comparators) {
return of(Arrays.asList(comparators));
}
public static <E> ComparatorChain<E> of(List<Comparator<E>> comparators) {
return new ComparatorChain<>(comparators);
}
public static <E> ComparatorChain<E> of(List<Comparator<E>> comparators, BitSet bits) {
return new ComparatorChain<>(comparators, bits);
}
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
/** /**
* 在链的尾部添加比较器使用正向排序 * 在链的尾部添加比较器使用正向排序

View File

@ -20,10 +20,6 @@ public class Pair<K, V> extends CloneSupport<Pair<K, V>> implements Serializable
private final K key; private final K key;
private final V value; private final V value;
public static <K, V> Pair<K, V> of(K key, V value) {
return new Pair<>(key, value);
}
/** /**
* 构造 * 构造
* *
@ -35,6 +31,10 @@ public class Pair<K, V> extends CloneSupport<Pair<K, V>> implements Serializable
this.value = value; this.value = value;
} }
public static <K, V> Pair<K, V> of(K key, V value) {
return new Pair<>(key, value);
}
/** /**
* 获取键 * 获取键
* @return * @return