add methods

This commit is contained in:
Looly
2022-05-05 11:52:51 +08:00
parent fa9d095e4e
commit 78a5c53d98
10 changed files with 111 additions and 26 deletions

View File

@@ -1497,12 +1497,12 @@ public class CollUtil {
if (t instanceof Map) {
final Map<?, ?> map = (Map<?, ?>) t;
final Object value = map.get(fieldName);
return ObjUtil.equal(value, fieldValue);
return ObjUtil.equals(value, fieldValue);
}
// 普通Bean
final Object value = FieldUtil.getFieldValue(t, fieldName);
return ObjUtil.equal(value, fieldValue);
return ObjUtil.equals(value, fieldValue);
});
}

View File

@@ -50,7 +50,7 @@ public class VersionComparator implements Comparator<String>, Serializable {
*/
@Override
public int compare(final String version1, final String version2) {
if(ObjUtil.equal(version1, version2)) {
if(ObjUtil.equals(version1, version2)) {
return 0;
}
if (version1 == null && version2 == null) {

View File

@@ -206,7 +206,7 @@ public class Validator {
* @return 当两值都为null或相等返回true
*/
public static boolean equal(final Object t1, final Object t2) {
return ObjUtil.equal(t1, t2);
return ObjUtil.equals(t1, t2);
}
/**

View File

@@ -117,7 +117,7 @@ public class TableMap<K, V> implements Map<K, V>, Iterable<Map.Entry<K, V>>, Ser
public List<V> getValues(final K key) {
return CollUtil.getAny(
this.values,
ListUtil.indexOfAll(this.keys, (ele) -> ObjUtil.equal(ele, key))
ListUtil.indexOfAll(this.keys, (ele) -> ObjUtil.equals(ele, key))
);
}
@@ -131,7 +131,7 @@ public class TableMap<K, V> implements Map<K, V>, Iterable<Map.Entry<K, V>>, Ser
public List<K> getKeys(final V value) {
return CollUtil.getAny(
this.keys,
ListUtil.indexOfAll(this.values, (ele) -> ObjUtil.equal(ele, value))
ListUtil.indexOfAll(this.values, (ele) -> ObjUtil.equals(ele, value))
);
}

View File

@@ -216,9 +216,9 @@ public abstract class AbsTable<R, C, V> implements Table<R, C, V> {
}
if (obj instanceof Cell) {
final Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj;
return ObjUtil.equal(rowKey, other.getRowKey())
&& ObjUtil.equal(columnKey, other.getColumnKey())
&& ObjUtil.equal(value, other.getValue());
return ObjUtil.equals(rowKey, other.getRowKey())
&& ObjUtil.equals(columnKey, other.getColumnKey())
&& ObjUtil.equals(value, other.getValue());
}
return false;
}

View File

@@ -172,7 +172,7 @@ public class TreeUtil {
* @since 5.2.4
*/
public static <T> Tree<T> getNode(final Tree<T> node, final T id) {
if (ObjUtil.equal(id, node.getId())) {
if (ObjUtil.equals(id, node.getId())) {
return node;
}

View File

@@ -797,7 +797,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* @since 3.0.7
*/
public static <T> int indexOf(final T[] array, final Object value, final int beginIndexInclude) {
return matchIndex((obj) -> ObjUtil.equal(value, obj), beginIndexInclude, array);
return matchIndex((obj) -> ObjUtil.equals(value, obj), beginIndexInclude, array);
}
/**
@@ -810,7 +810,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* @since 3.0.7
*/
public static <T> int indexOf(final T[] array, final Object value) {
return matchIndex((obj) -> ObjUtil.equal(value, obj), array);
return matchIndex((obj) -> ObjUtil.equals(value, obj), array);
}
/**
@@ -861,7 +861,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
public static <T> int lastIndexOf(final T[] array, final Object value, final int endInclude) {
if (isNotEmpty(array)) {
for (int i = endInclude; i >= 0; i--) {
if (ObjUtil.equal(value, array[i])) {
if (ObjUtil.equals(value, array[i])) {
return i;
}
}
@@ -1816,7 +1816,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
}
for (int i = 0; i < subArray.length; i++) {
if (false == ObjUtil.equal(array[i + firstIndex], subArray[i])) {
if (false == ObjUtil.equals(array[i + firstIndex], subArray[i])) {
return indexOfSub(array, firstIndex + 1, subArray);
}
}
@@ -1861,7 +1861,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
}
for (int i = 0; i < subArray.length; i++) {
if (false == ObjUtil.equal(array[i + firstIndex], subArray[i])) {
if (false == ObjUtil.equals(array[i + firstIndex], subArray[i])) {
return lastIndexOfSub(array, firstIndex - 1, subArray);
}
}

View File

@@ -144,7 +144,7 @@ public class EnumUtil {
continue;
}
for (final Enum<?> enumObj : enums) {
if (ObjUtil.equal(value, FieldUtil.getFieldValue(enumObj, field))) {
if (ObjUtil.equals(value, FieldUtil.getFieldValue(enumObj, field))) {
return (E) enumObj;
}
}

View File

@@ -1,5 +1,6 @@
package cn.hutool.core.lang;
import cn.hutool.core.text.StrUtil;
import org.junit.Test;
public class AssertTest {
@@ -35,4 +36,27 @@ public class AssertTest {
//noinspection ConstantConditions
Assert.isTrue(i > 0, ()-> new IndexOutOfBoundsException("relation message to return"));
}
@Test
public void equalsTest() {
//String a="ab";
//final String b = new String("abc");
final String a = null;
final String b = null;
Assert.equals(a, b);
Assert.equals(a, b, "{}不等于{}", a, b);
Assert.equals(a, b, () -> new RuntimeException(StrUtil.format("{}和{}不相等", a, b)));
}
@Test
public void notEqualsTest() {
//String c="19";
//final String d = new String("19");
final String c = null;
final String d = "null";
//Assert.notEquals(c,d);
//Assert.notEquals(c,d,"{}等于{}",c,d);
Assert.notEquals(c, d, () -> new RuntimeException(StrUtil.format("{}和{}相等", c, d)));
}
}