This commit is contained in:
Looly
2020-04-11 10:38:07 +08:00
parent 47be0f4f79
commit 73fd3b849f
21 changed files with 128 additions and 122 deletions

View File

@@ -42,6 +42,23 @@ import java.util.Map;
*/
public class BeanUtil {
/**
* 判断是否为可读的Bean对象判定方法是
*
* <pre>
* 1、是否存在只有无参数的getXXX方法或者isXXX方法
* 2、是否存在public类型的字段
* </pre>
*
* @param clazz 待测试类
* @return 是否为可读的Bean对象
* @see #hasGetter(Class)
* @see #hasPublicField(Class)
*/
public static boolean isReadableBean(Class<?> clazz) {
return hasGetter(clazz) || hasPublicField(clazz);
}
/**
* 判断是否为Bean对象判定方法是
*
@@ -53,6 +70,7 @@ public class BeanUtil {
* @param clazz 待测试类
* @return 是否为Bean对象
* @see #hasSetter(Class)
* @see #hasPublicField(Class)
*/
public static boolean isBean(Class<?> clazz) {
return hasSetter(clazz) || hasPublicField(clazz);

View File

@@ -351,6 +351,24 @@ public class CollUtil {
return IterUtil.join(iterable.iterator(), conjunction);
}
/**
* 以 conjunction 为分隔符将集合转换为字符串
*
* @param <T> 集合元素类型
* @param iterable {@link Iterable}
* @param conjunction 分隔符
* @param prefix 每个元素添加的前缀null表示不添加
* @param suffix 每个元素添加的后缀null表示不添加
* @return 连接后的字符串
* @since 5.3.0
*/
public static <T> String join(Iterable<T> iterable, CharSequence conjunction, String prefix, String suffix) {
if (null == iterable) {
return null;
}
return IterUtil.join(iterable.iterator(), conjunction, prefix, suffix);
}
/**
* 以 conjunction 为分隔符将集合转换为字符串<br>
* 如果集合元素为数组、{@link Iterable}或{@link Iterator},则递归组合其为字符串

View File

@@ -302,7 +302,9 @@ public class IterUtil {
* @param suffix 每个元素添加的后缀null表示不添加
* @return 连接后的字符串
* @since 4.0.10
* @deprecated 如果对象同时实现Iterable和Iterator接口会产生歧义请使用CollUtil.join
*/
@Deprecated
public static <T> String join(Iterable<T> iterable, CharSequence conjunction, String prefix, String suffix) {
if (null == iterable) {
return null;

View File

@@ -19,16 +19,16 @@ public class ChineseDate {
private static final Date baseDate = DateUtil.parseDate("1900-01-31");
//农历年
private int year;
private final int year;
//农历月
private int month;
private final int month;
//农历日
private int day;
private final int day;
//是否闰年
private boolean leap;
private String[] chineseNumber = {"", "", "", "", "", "", "", "", "", "", "十一", "十二"};
private String[] chineseNumberName = {"", "", "", "", "", "", "", "", "", "", "十一", ""};
private long[] lunarInfo = new long[]{0x04bd8, 0x04ae0, 0x0a570,
private final String[] chineseNumber = {"", "", "", "", "", "", "", "", "", "", "十一", "十二"};
private final String[] chineseNumberName = {"", "", "", "", "", "", "", "", "", "", "十一", ""};
private final long[] lunarInfo = new long[]{0x04bd8, 0x04ae0, 0x0a570,
0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,
@@ -51,7 +51,7 @@ public class ChineseDate {
0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2,
0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0};
//农历节日 *表示放假日
private String[] lFtv = new String[]{
private final String[] lFtv = new String[]{
"0101 春节", "0102 大年初二", "0103 大年初三", "0104 大年初四",
"0105 大年初五", "0106 大年初六", "0107 大年初七", "0105 路神生日",
"0115 元宵节", "0202 龙抬头", "0219 观世音圣诞", "0404 寒食节",

View File

@@ -1,11 +1,11 @@
package cn.hutool.core.io;
import cn.hutool.core.util.CharsetUtil;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import cn.hutool.core.util.CharsetUtil;
/**
* 基于快速缓冲FastByteBuffer的OutputStream随着数据的增长自动扩充缓冲区
* <p>
@@ -34,7 +34,6 @@ public class FastByteArrayOutputStream extends OutputStream {
buffer = new FastByteBuffer(size);
}
@SuppressWarnings("NullableProblems")
@Override
public void write(byte[] b, int off, int len) {
buffer.append(b, off, len);

View File

@@ -2402,7 +2402,7 @@ public class ArrayUtil {
if (ArrayUtil.isArray(item)) {
sb.append(join(ArrayUtil.wrap(item), conjunction, prefix, suffix));
} else if (item instanceof Iterable<?>) {
sb.append(IterUtil.join((Iterable<?>) item, conjunction, prefix, suffix));
sb.append(CollUtil.join((Iterable<?>) item, conjunction, prefix, suffix));
} else if (item instanceof Iterator<?>) {
sb.append(IterUtil.join((Iterator<?>) item, conjunction, prefix, suffix));
} else {

View File

@@ -938,7 +938,6 @@ public class ZipUtil {
addDir(subPath, out);
}
// 压缩目录下的子文件或目录
//noinspection ConstantConditions
for (File childFile : files) {
zip(childFile, srcRootDir, out, filter);
}

View File

@@ -1,5 +1,7 @@
package cn.hutool.core.clone;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.junit.Assert;
import org.junit.Test;
@@ -17,7 +19,10 @@ public class CloneTest {
Cat cat = new Cat();
Cat cat2 = cat.clone();
Assert.assertEquals(cat, cat2);
}
@Test
public void cloneTest2(){
//继承CloneSupport类
Dog dog = new Dog();
Dog dog2 = dog.clone();
@@ -30,7 +35,8 @@ public class CloneTest {
* @author Looly
*
*/
private static class Cat implements Cloneable<Cat>{
@Data
static class Cat implements Cloneable<Cat>{
private String name = "miaomiao";
private int age = 2;
@@ -42,35 +48,6 @@ public class CloneTest {
throw new CloneRuntimeException(e);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Cat other = (Cat) obj;
if (age != other.age) {
return false;
}
if (name == null) {
return other.name == null;
} else return name.equals(other.name);
}
}
/**
@@ -78,37 +55,10 @@ public class CloneTest {
* @author Looly
*
*/
private static class Dog extends CloneSupport<Dog>{
@EqualsAndHashCode(callSuper = false)
@Data
static class Dog extends CloneSupport<Dog>{
private String name = "wangwang";
private int age = 3;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Dog other = (Dog) obj;
if (age != other.age) {
return false;
}
if (name == null) {
return other.name == null;
} else return name.equals(other.name);
}
}
}

View File

@@ -179,6 +179,7 @@ public class CollUtilTest {
map.put("c", "3");
final String[] result = new String[1];
//noinspection deprecation
CollUtil.forEach(map, (key, value, index) -> {
if (key.equals("a")) {
result[0] = value;

View File

@@ -16,25 +16,25 @@ public class IterUtilTest {
@Test
public void fieldValueMapTest() {
ArrayList<Car> carList = CollUtil.newArrayList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList, "carNumber");
Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList.iterator(), "carNumber");
Assert.assertEquals("大众", carNameMap.get("123").getCarName());
Assert.assertEquals("奔驰", carNameMap.get("345").getCarName());
Assert.assertEquals("路虎", carNameMap.get("567").getCarName());
}
@Test
public void joinTest() {
ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
String join = IterUtil.join(list, ":");
String join = IterUtil.join(list.iterator(), ":");
Assert.assertEquals("1:2:3:4", join);
ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4);
String join1 = IterUtil.join(list1, ":");
String join1 = IterUtil.join(list1.iterator(), ":");
Assert.assertEquals("1:2:3:4", join1);
ArrayList<String> list2 = CollUtil.newArrayList("1", "2", "3", "4");
String join2 = IterUtil.join(list2, ":", "\"", "\"");
String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
}

View File

@@ -3,16 +3,14 @@ package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.convert.NumberWordFormater;
public class NumberWordFormatTest {
@Test
public void formatTest() {
String format = NumberWordFormater.format(100.23);
String format = NumberWordFormatter.format(100.23);
Assert.assertEquals("ONE HUNDRED AND CENTS TWENTY THREE ONLY", format);
String format2 = NumberWordFormater.format("2100.00");
String format2 = NumberWordFormatter.format("2100.00");
Assert.assertEquals("TWO THOUSAND ONE HUNDRED AND CENTS ONLY", format2);
}
}