mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
feat: new object with 'of' method
This commit is contained in:
parent
5440cff37f
commit
018999e18f
@ -9,6 +9,7 @@ import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 比较器链。此链包装了多个比较器,最终比较结果按照比较器顺序综合多个比较器结果。<br>
|
||||
@ -81,6 +82,26 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
|
||||
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);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* 在链的尾部添加比较器,使用正向排序
|
||||
|
@ -20,10 +20,6 @@ public class Pair<K, V> extends CloneSupport<Pair<K, V>> implements Serializable
|
||||
private final K key;
|
||||
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;
|
||||
}
|
||||
|
||||
public static <K, V> Pair<K, V> of(K key, V value) {
|
||||
return new Pair<>(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取键
|
||||
* @return 键
|
||||
|
Loading…
x
Reference in New Issue
Block a user