mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-12-08 01:59:14 +08:00
add test
This commit is contained in:
parent
2fb775ec7c
commit
0d45154019
@ -1388,13 +1388,42 @@ public class CollUtil {
|
|||||||
|
|
||||||
final Iterator<K> keyIterator = keys.iterator();
|
final Iterator<K> keyIterator = keys.iterator();
|
||||||
final Iterator<V> valueIterator = values.iterator();
|
final Iterator<V> valueIterator = values.iterator();
|
||||||
while (entryCount > 0) {
|
while (entryCount-- > 0) {
|
||||||
map.put(keyIterator.next(), valueIterator.next());
|
map.put(keyIterator.next(), valueIterator.next());
|
||||||
entryCount--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将两个列表的元素按照索引一一配对,通过指定的函数进行合并,返回一个新的结果列表。
|
||||||
|
* 新列表的长度将以两个输入列表中较短的那个为准。
|
||||||
|
*
|
||||||
|
* @param <A> 第一个列表的元素类型
|
||||||
|
* @param <B> 第二个列表的元素类型
|
||||||
|
* @param <R> 结果列表的元素类型
|
||||||
|
* @param collectionA 第一个列表
|
||||||
|
* @param collectionB 第二个列表
|
||||||
|
* @param zipper 合并函数,接收来自listA和listB的两个元素,返回一个结果元素
|
||||||
|
* @return 合并后的新列表
|
||||||
|
* @since 5.8.42
|
||||||
|
*/
|
||||||
|
public static <A, B, R> List<R> zip(Collection<A> collectionA, Collection<B> collectionB, BiFunction<A, B, R> zipper) {
|
||||||
|
if (CollUtil.isEmpty(collectionA) || CollUtil.isEmpty(collectionB)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
Assert.notNull(zipper, "Zipper function must not be null");
|
||||||
|
|
||||||
|
int size = Math.min(collectionA.size(), collectionB.size());
|
||||||
|
final List<R> result = new ArrayList<>(size);
|
||||||
|
final Iterator<A> aIterator = collectionA.iterator();
|
||||||
|
final Iterator<B> bIterator = collectionB.iterator();
|
||||||
|
|
||||||
|
while(size-- > 0) {
|
||||||
|
result.add(zipper.apply(aIterator.next(), bIterator.next()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -138,7 +138,7 @@ public class CronPattern {
|
|||||||
* @param isMatchSecond 是否匹配秒
|
* @param isMatchSecond 是否匹配秒
|
||||||
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
||||||
*/
|
*/
|
||||||
public boolean match(final Calendar calendar, final boolean isMatchSecond) {
|
public boolean match(final Calendar calendar, final boolean isMatchSecond) {
|
||||||
return match(PatternUtil.getFields(calendar, isMatchSecond));
|
return match(PatternUtil.getFields(calendar, isMatchSecond));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user