#525 加强Utils Modules模块:晚上成果
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
<guava.version>20.0</guava.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-beanutils.version>1.9.3</commons-beanutils.version>
|
||||
<orika.version>1.5.0</orika.version>
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
<cglib.version>3.2.4</cglib.version>
|
||||
@@ -53,14 +52,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- for CollectionExtractor -->
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>${commons-beanutils.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- for JsonMapper -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
||||
+4
-5
@@ -6,14 +6,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springside.modules.utils.reflect.Reflections;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
/**
|
||||
* 提取集合内元素的内容,依赖BeanUtils(考虑取消依赖)
|
||||
* 提取集合内元素的内容
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Beta
|
||||
@@ -32,8 +31,8 @@ public class CollectionExtractor {
|
||||
|
||||
try {
|
||||
for (Object obj : collection) {
|
||||
map.put(PropertyUtils.getProperty(obj, keyPropertyName),
|
||||
PropertyUtils.getProperty(obj, valuePropertyName));
|
||||
map.put(Reflections.getProperty(obj, keyPropertyName),
|
||||
Reflections.getProperty(obj, valuePropertyName));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw Reflections.convertReflectionExceptionToUnchecked(e);
|
||||
@@ -53,7 +52,7 @@ public class CollectionExtractor {
|
||||
|
||||
try {
|
||||
for (Object obj : collection) {
|
||||
list.add(PropertyUtils.getProperty(obj, propertyName));
|
||||
list.add(Reflections.getProperty(obj, propertyName));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw Reflections.convertReflectionExceptionToUnchecked(e);
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.google.common.primitives.Longs;
|
||||
*
|
||||
* 5. ArrayList 与 Array的双向转换,包含Guava特有的原子类型的asList()
|
||||
*
|
||||
* 6. 集合运算,包括两个List是否完全相等,两个List的交集(重复元素将去重,from Commons Collecton)
|
||||
* 6. 集合运算,包括两个List是否完全相等,两个List的交集,并集,from Commons Collecton)
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
@@ -131,7 +131,7 @@ public class Lists {
|
||||
* @see java.util.Collections#emptyList()
|
||||
*/
|
||||
public static final <T> List<T> emptyList() {
|
||||
return (List<T>)Collections.EMPTY_LIST;
|
||||
return (List<T>) Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,6 +235,17 @@ public class Lists {
|
||||
return Arrays.asList(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个独立元素+一个数组组成新的list,而且独立元素在最前.
|
||||
*
|
||||
* 注意转换后的List不能写入.
|
||||
*
|
||||
* @see com.google.common.collect.Lists#asList(Object, Object[])
|
||||
*/
|
||||
public static <E> List<E> asList(E first, E[] rest) {
|
||||
return com.google.common.collect.Lists.asList(first, rest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrays.asList()的加强版, 返回一个底层为原始类型int的List
|
||||
*
|
||||
@@ -304,6 +315,18 @@ public class Lists {
|
||||
return !(it1.hasNext() || it2.hasNext());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回a+b的集合.
|
||||
*
|
||||
* 对比Apache Common Collection4 ListUtils, 优化了初始大小
|
||||
*/
|
||||
public static <E> List<E> union(final List<? extends E> list1, final List<? extends E> list2) {
|
||||
final ArrayList<E> result = new ArrayList<E>(list1.size() + list2.size());
|
||||
result.addAll(list1);
|
||||
result.addAll(list2);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回a与b的交集的新List(重复元素将去重)
|
||||
*
|
||||
|
||||
@@ -6,6 +6,16 @@ import java.util.Random;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
|
||||
/**
|
||||
* 关于网络的工具类.
|
||||
*
|
||||
* 1. Local Address(TODO)
|
||||
*
|
||||
* 2. 查找空闲端口
|
||||
*
|
||||
* @author calvin
|
||||
*
|
||||
*/
|
||||
public class Nets {
|
||||
|
||||
public static final int PORT_RANGE_MIN = 1024;
|
||||
|
||||
@@ -5,6 +5,15 @@ import java.util.List;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
|
||||
import com.google.common.base.Utf8;
|
||||
|
||||
/**
|
||||
* 尽量使用Common Lang StringUtils, 完全覆盖了guva对应的部分(除了split和join的API没那么酷)
|
||||
*
|
||||
* 本类仅补充少量额外方法.
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
public class Strings {
|
||||
|
||||
/**
|
||||
@@ -44,4 +53,12 @@ public class Strings {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算字符串被UTF8编码后的字节数 via guava
|
||||
*
|
||||
* @see Utf8#encodedLength(CharSequence)
|
||||
*/
|
||||
public static int utf8EncodedLength(CharSequence sequence) {
|
||||
return Utf8.encodedLength(sequence);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user