Skip to content

Commit

Permalink
新建 com.feilong.core.util.CollectionsUtil.partition(List<T>, int) fix
Browse files Browse the repository at this point in the history
#261

封装类似于 com.feilong.lib.collection4.IterableUtils.size(Iterable<?>) 方法 fix
#255

封装 类似于com.feilong.lib.collection4.IterableUtils.get(Iterable<T>, int)
的方法 fix #254
  • Loading branch information
venusdrogon committed Jun 14, 2020
1 parent 990df12 commit 806f5b1
Show file tree
Hide file tree
Showing 30 changed files with 285 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package com.feilong.component.upload;

import static com.feilong.core.bean.ConvertUtil.toList;
import static com.feilong.core.util.CollectionsUtil.size;

import java.util.List;
import java.util.Map;

import com.feilong.context.DataHandler;
import com.feilong.lib.collection4.MapUtils;

/**
* The Class AbstractSimpleListDataHandler.
Expand All @@ -35,7 +35,7 @@ public abstract class AbstractSimpleListDataHandler<T> implements DataHandler{

@Override
public void handle(Map<String, Object> data){
int size = MapUtils.size(data);
int size = size(data);
if (size != 1){
throw new IllegalArgumentException("data size:[" + size + "] != 1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
package com.feilong.coreextension.util;

import static com.feilong.core.bean.ConvertUtil.toList;
import static com.feilong.core.util.CollectionsUtil.get;
import static com.feilong.core.util.CollectionsUtil.newArrayList;
import static com.feilong.core.util.CollectionsUtil.size;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.feilong.lib.collection4.IterableUtils;

/**
* 笛卡尔乘积.
*
Expand Down Expand Up @@ -164,7 +164,7 @@ public static <T> List<List<T>> cartesianProduct(Iterable<T>...iterables){
private static <T, I extends Iterable<T>> List<List<T>> cartesianProduct(Iterable<I> iterables){
int length = 1;
for (Iterable<T> iterable : iterables){
length *= IterableUtils.size(iterable);
length *= size(iterable);
}

//---------------------------------------------------------------
Expand Down Expand Up @@ -193,7 +193,7 @@ private static <T, I extends Iterable<T>> List<T> buildList(Iterable<I> iterable
//从不同的数组中取值
List<T> list = newArrayList();
for (Iterable<T> iterable : iterables){
list.add(IterableUtils.get(iterable, i % IterableUtils.size(iterable)));
list.add(get(iterable, i % size(iterable)));
}

//---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
at com.feilong.core.DefaultRuntimeExceptionTest.testRuntimeException(DefaultRuntimeExceptionTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.ArithmeticException: / by zero
at com.feilong.core.DefaultRuntimeExceptionTest.testRuntimeException(DefaultRuntimeExceptionTest.java:61)
... 23 more
Expand Down
4 changes: 2 additions & 2 deletions feilong-core/src/main/java/com/feilong/core/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
* @see com.feilong.lib.collection4.CollectionUtils#sizeIsEmpty(Object)
* @see com.feilong.lib.collection4.CollectionUtils#isEmpty(Collection)
* @see com.feilong.lib.collection4.CollectionUtils#isNotEmpty(Collection)
* @see com.feilong.lib.collection4.MapUtils#isEmpty(Map)
* @see com.feilong.lib.collection4.MapUtils#isNotEmpty(Map)
* @see "org.apache.commons.collections4.MapUtils#isEmpty(Map)"
* @see "org.apache.commons.collections4.MapUtils#isNotEmpty(Map)"
* @since 1.0.0
*/
public final class Validator{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ public static String toString(Object toBeConvertedValue){
* the connector
* @return 如果 <code>collection</code> 是null或者empty,返回 {@link StringUtils#EMPTY}<br>
* @see "org.springframework.util.StringUtils#collectionToDelimitedString(Collection, String, String, String)"
* @see com.feilong.lib.collection4.IteratorUtils#toString(Iterator)
* @see "org.apache.commons.collections4.IteratorUtils#toString(Iterator)"
* @see com.feilong.lib.lang3.StringUtils#join(Iterable, String)
* @since 1.11.0
*/
Expand Down Expand Up @@ -1211,7 +1211,7 @@ public static String toString(Object[] arrays,String connector){
* 如果 <code>toStringConfig</code> 是null,使用默认 {@link ToStringConfig#DEFAULT_CONNECTOR}以及 joinNullOrEmpty 进行连接<br>
* 都不是null,会循环,拼接toStringConfig.getConnector()
* @see "org.springframework.util.StringUtils#collectionToDelimitedString(Collection, String, String, String)"
* @see com.feilong.lib.collection4.IteratorUtils#toString(Iterator)
* @see "org.apache.commons.collections4.IteratorUtils#toString(Iterator)"
* @see com.feilong.lib.lang3.StringUtils#join(Iterable, String)
* @since 1.8.4 change param order
*/
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public static <K, V> Map<K, V> toMap(K key1,V value1,K key2,V value2){
* @param properties
* the properties
* @return 如果 <code>properties</code> 是null或者empty,返回 {@link Collections#emptyMap()}<br>
* @see com.feilong.lib.collection4.MapUtils#toProperties(Map)
* @see "org.apache.commons.collections4.MapUtils#toProperties(Map)"
* @since 1.7.1
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
Expand Down Expand Up @@ -1973,7 +1973,7 @@ public static <K, V, I, J> Map<I, J> toMap(Map<K, V> inputMap,final Class<I> key
* @return 如果 <code>inputMap</code> 是null或者empty,返回 {@link Collections#emptyMap()}<br>
* 如果 <code>keyTransformer</code> 是null,那么key直接使用<code>inputMap</code>的key<br>
* 如果 <code>valueTransformer</code> 是null,那么value 直接使用<code>inputMap</code>的 value<br>
* @see com.feilong.lib.collection4.MapUtils#transformedMap(Map, Transformer, Transformer)
* @see "org.apache.commons.collections4.MapUtils#transformedMap(Map, Transformer, Transformer)"
* @see "org.apache.commons.collections4.map.TransformedMap#transformedMap(Map, Transformer, Transformer)"
* @see <a href="https://github.com/venusdrogon/feilong-core/issues/497">issues497</a>
* @since 1.9.2
Expand Down Expand Up @@ -2267,7 +2267,7 @@ public static <V, K> Map<K, V> toMapUseEntrys(Map.Entry<K, V>...mapEntrys){
* @param map
* the map
* @return 如果 <code>map</code> 是null,返回 empty Properties<br>
* @see com.feilong.lib.collection4.MapUtils#toProperties(Map)
* @see "org.apache.commons.collections4.MapUtils#toProperties(Map)"
* @since 1.7.3
*/
public static Properties toProperties(final Map<String, String> map){
Expand Down Expand Up @@ -2340,8 +2340,8 @@ public static <T> List<T> toList(final Enumeration<T> enumeration){
* @return 如果 <code>collection</code> 是null,返回 {@link Collections#emptyList()}<br>
* 如果 <code>collection instanceof List</code>,那么强转成 list返回<br>
* 否则返回 <code>new ArrayList(collection)</code>
* @see com.feilong.lib.collection4.IterableUtils#toList(Iterable)
* @see com.feilong.lib.collection4.IteratorUtils#toList(Iterator)
* @see "org.apache.commons.collections4.IterableUtils#toList(Iterable)"
* @see "org.apache.commons.collections4.IteratorUtils#toList(Iterator)"
* @since 1.6.1
*/
public static <T> List<T> toList(final Collection<T> collection){
Expand Down Expand Up @@ -2691,7 +2691,7 @@ public static <T> T[] toArray(T...arrays){
* @see java.util.ArrayList#toArray()
* @see java.util.ArrayList#toArray(Object[])
*
* @see com.feilong.lib.collection4.IteratorUtils#toArray(Iterator,Class)
* @see "org.apache.commons.collections4.IteratorUtils#toArray(Iterator,Class)"
* @see "org.springframework.util.StringUtils#toStringArray(Collection)"
* @since 1.2.2
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.feilong.core.bean.PropertyDescriptorUtil.getSpringPropertyDescriptor;
import static com.feilong.core.bean.PropertyDescriptorUtil.isUseSpringOperate;
import static com.feilong.core.util.CollectionsUtil.first;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
Expand All @@ -26,9 +27,8 @@
import org.slf4j.LoggerFactory;

import com.feilong.core.DefaultRuntimeException;
import com.feilong.lib.beanutils.PropertyUtils;
import com.feilong.lib.collection4.IterableUtils;
import com.feilong.core.Validate;
import com.feilong.lib.beanutils.PropertyUtils;
import com.feilong.tools.slf4j.Slf4jUtil;

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ public static <T, O, K extends Collection<T>> K getPropertyValueCollection(
Validate.notBlank(propertyName, "propertyName can't be null/empty!");

//---------------------------------------------------------------
O o = IterableUtils.get(beanIterable, 0);
O o = first(beanIterable);
Class<?> klass = o.getClass();
//spring 操作
if (isUseSpringOperate(klass, propertyName)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
*/
package com.feilong.core.lang.thread;

import static com.feilong.core.util.CollectionsUtil.partition;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.feilong.core.lang.ThreadUtil;
import com.feilong.lib.collection4.ListUtils;
import com.feilong.core.Validate;
import com.feilong.core.lang.ThreadUtil;
import com.feilong.core.util.CollectionsUtil;
import com.feilong.tools.slf4j.Slf4jUtil;

/**
Expand Down Expand Up @@ -78,7 +80,8 @@ protected <T> void actualExecute(
* Builds the thread array.
*
* <p>
* 调用 {@link ListUtils#partition(List, int)} 对list 分成N份,对应的创建N份线程,每个线程的 名字 参见 {@link #buildThreadName(int, PartitionRunnableBuilder)}
* 调用 {@link CollectionsUtil#partition(List, int)} 对list 分成N份,对应的创建N份线程,每个线程的 名字 参见
* {@link #buildThreadName(int, PartitionRunnableBuilder)}
* </p>
*
* <p>
Expand Down Expand Up @@ -108,7 +111,7 @@ private static <T> Thread[] buildThreadArray(
ThreadGroup threadGroup = new ThreadGroup(buildThreadGroupName(list, partitionRunnableBuilder));

//将 list 分成 N 份
List<List<T>> groupList = ListUtils.partition(list, eachSize);
List<List<T>> groupList = partition(list, eachSize);

//-------------------------------------------------------------------
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import static com.feilong.core.Validator.isNullOrEmpty;
import static com.feilong.core.bean.ConvertUtil.toArray;
import static com.feilong.core.bean.ConvertUtil.toBigDecimal;
import static com.feilong.core.util.MapUtil.newLinkedHashMap;
import static com.feilong.core.lang.ObjectUtil.defaultIfNull;
import static com.feilong.core.util.CollectionsUtil.size;
import static com.feilong.core.util.MapUtil.newLinkedHashMap;
import static java.math.BigDecimal.ZERO;
import static java.util.Collections.emptyMap;

Expand All @@ -32,10 +33,9 @@
import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.Transformer;

import com.feilong.core.Validate;
import com.feilong.core.bean.PropertyUtil;
import com.feilong.core.lang.NumberUtil;
import com.feilong.lib.collection4.IterableUtils;
import com.feilong.core.Validate;

/**
* 专门用来统计数据的工具类.
Expand Down Expand Up @@ -167,7 +167,7 @@ public static <O> Map<String, BigDecimal> avg(Iterable<O> beanIterable,String[]

Map<String, BigDecimal> sumMap = sum(beanIterable, propertyNames);//先求和

int size = IterableUtils.size(beanIterable);
int size = size(beanIterable);
Map<String, BigDecimal> map = newLinkedHashMap(size);
for (Map.Entry<String, BigDecimal> entry : sumMap.entrySet()){
map.put(entry.getKey(), NumberUtil.getDivideValue(toBigDecimal(entry.getValue()), size, scale));
Expand Down Expand Up @@ -449,7 +449,7 @@ public static <O> Map<String, BigDecimal> sum(Iterable<O> beanIterable,String[]
}
Validate.noNullElements(propertyNames, "propertyNames can't be null/empty!");

Map<String, BigDecimal> sumMap = newLinkedHashMap(IterableUtils.size(beanIterable));
Map<String, BigDecimal> sumMap = newLinkedHashMap(size(beanIterable));
for (O obj : beanIterable){
if (null != includePredicate && !includePredicate.evaluate(obj)){
continue;
Expand Down
Loading

0 comments on commit 806f5b1

Please sign in to comment.