diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java index b979ede0d..0a484dbd6 100755 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java @@ -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); }); } diff --git a/hutool-core/src/main/java/cn/hutool/core/comparator/VersionComparator.java b/hutool-core/src/main/java/cn/hutool/core/comparator/VersionComparator.java index 4aa138d8c..4ea067fb1 100644 --- a/hutool-core/src/main/java/cn/hutool/core/comparator/VersionComparator.java +++ b/hutool-core/src/main/java/cn/hutool/core/comparator/VersionComparator.java @@ -50,7 +50,7 @@ public class VersionComparator implements Comparator, 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) { diff --git a/hutool-core/src/main/java/cn/hutool/core/lang/Validator.java b/hutool-core/src/main/java/cn/hutool/core/lang/Validator.java index dba2bb7f8..368acb9a7 100755 --- a/hutool-core/src/main/java/cn/hutool/core/lang/Validator.java +++ b/hutool-core/src/main/java/cn/hutool/core/lang/Validator.java @@ -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); } /** diff --git a/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java b/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java index ddb7119cf..2e53c835a 100755 --- a/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java +++ b/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java @@ -117,7 +117,7 @@ public class TableMap implements Map, Iterable>, Ser public List 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 implements Map, Iterable>, Ser public List 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)) ); } diff --git a/hutool-core/src/main/java/cn/hutool/core/map/multi/AbsTable.java b/hutool-core/src/main/java/cn/hutool/core/map/multi/AbsTable.java index aa348e76d..25694ef42 100644 --- a/hutool-core/src/main/java/cn/hutool/core/map/multi/AbsTable.java +++ b/hutool-core/src/main/java/cn/hutool/core/map/multi/AbsTable.java @@ -216,9 +216,9 @@ public abstract class AbsTable implements Table { } 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; } diff --git a/hutool-core/src/main/java/cn/hutool/core/tree/TreeUtil.java b/hutool-core/src/main/java/cn/hutool/core/tree/TreeUtil.java index fdf24acc7..d4573c128 100755 --- a/hutool-core/src/main/java/cn/hutool/core/tree/TreeUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/tree/TreeUtil.java @@ -172,7 +172,7 @@ public class TreeUtil { * @since 5.2.4 */ public static Tree getNode(final Tree node, final T id) { - if (ObjUtil.equal(id, node.getId())) { + if (ObjUtil.equals(id, node.getId())) { return node; } diff --git a/hutool-core/src/main/java/cn/hutool/core/util/ArrayUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/ArrayUtil.java index 1c1ba1c1c..6d46e5c7a 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/ArrayUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/ArrayUtil.java @@ -797,7 +797,7 @@ public class ArrayUtil extends PrimitiveArrayUtil { * @since 3.0.7 */ public static 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 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 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); } } diff --git a/hutool-core/src/main/java/cn/hutool/core/util/EnumUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/EnumUtil.java index 05bc88702..faa86d349 100644 --- a/hutool-core/src/main/java/cn/hutool/core/util/EnumUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/EnumUtil.java @@ -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; } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java index c644964a6..cdb4507d3 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java @@ -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))); + + } } diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java index ce0e3969b..ca8b8d056 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java @@ -277,6 +277,56 @@ public class CellUtil { return false; } + /** + * 获取合并单元格{@link CellRangeAddress},如果不是返回null + * + * @param sheet {@link Sheet} + * @param locationRef 单元格地址标识符,例如A11,B5 + * @return {@link CellRangeAddress} + * @since 5.8.0 + */ + public static CellRangeAddress getCellRangeAddress(final Sheet sheet, final String locationRef) { + final CellLocation cellLocation = ExcelUtil.toLocation(locationRef); + return getCellRangeAddress(sheet, cellLocation.getX(), cellLocation.getY()); + } + + /** + * 获取合并单元格{@link CellRangeAddress},如果不是返回null + * + * @param cell {@link Cell} + * @return {@link CellRangeAddress} + * @since 5.8.0 + */ + public static CellRangeAddress getCellRangeAddress(final Cell cell) { + return getCellRangeAddress(cell.getSheet(), cell.getColumnIndex(), cell.getRowIndex()); + } + + /** + * 获取合并单元格{@link CellRangeAddress},如果不是返回null + * + * @param sheet {@link Sheet} + * @param x 列号,从0开始 + * @param y 行号,从0开始 + * @return {@link CellRangeAddress} + * @since 5.8.0 + */ + public static CellRangeAddress getCellRangeAddress(final Sheet sheet, final int x, final int y) { + if (sheet != null) { + final int sheetMergeCount = sheet.getNumMergedRegions(); + CellRangeAddress ca; + for (int i = 0; i < sheetMergeCount; i++) { + ca = sheet.getMergedRegion(i); + if (y >= ca.getFirstRow() && y <= ca.getLastRow() + && x >= ca.getFirstColumn() && x <= ca.getLastColumn()) { + return ca; + } + } + } + return null; + } + + + /** * 合并单元格,可以根据设置的值来合并行和列 * @@ -310,16 +360,7 @@ public class CellUtil { lastColumn // last column (0-based) ); - if (null != cellStyle) { - RegionUtil.setBorderTop(cellStyle.getBorderTop(), cellRangeAddress, sheet); - RegionUtil.setBorderRight(cellStyle.getBorderRight(), cellRangeAddress, sheet); - RegionUtil.setBorderBottom(cellStyle.getBorderBottom(), cellRangeAddress, sheet); - RegionUtil.setBorderLeft(cellStyle.getBorderLeft(), cellRangeAddress, sheet); - RegionUtil.setTopBorderColor(cellStyle.getTopBorderColor(),cellRangeAddress,sheet); - RegionUtil.setRightBorderColor(cellStyle.getRightBorderColor(),cellRangeAddress,sheet); - RegionUtil.setLeftBorderColor(cellStyle.getLeftBorderColor(),cellRangeAddress,sheet); - RegionUtil.setBottomBorderColor(cellStyle.getBottomBorderColor(),cellRangeAddress,sheet); - } + setMergeCellStyle(cellStyle, cellRangeAddress, sheet); return sheet.addMergedRegion(cellRangeAddress); } @@ -435,5 +476,25 @@ public class CellUtil { } return null; } + + /** + * 根据{@link CellStyle}设置合并单元格边框样式 + * + * @param cellStyle {@link CellStyle} + * @param cellRangeAddress {@link CellRangeAddress} + * @param sheet {@link Sheet} + */ + private static void setMergeCellStyle(final CellStyle cellStyle, final CellRangeAddress cellRangeAddress, final Sheet sheet) { + if (null != cellStyle) { + RegionUtil.setBorderTop(cellStyle.getBorderTop(), cellRangeAddress, sheet); + RegionUtil.setBorderRight(cellStyle.getBorderRight(), cellRangeAddress, sheet); + RegionUtil.setBorderBottom(cellStyle.getBorderBottom(), cellRangeAddress, sheet); + RegionUtil.setBorderLeft(cellStyle.getBorderLeft(), cellRangeAddress, sheet); + RegionUtil.setTopBorderColor(cellStyle.getTopBorderColor(), cellRangeAddress, sheet); + RegionUtil.setRightBorderColor(cellStyle.getRightBorderColor(), cellRangeAddress, sheet); + RegionUtil.setLeftBorderColor(cellStyle.getLeftBorderColor(), cellRangeAddress, sheet); + RegionUtil.setBottomBorderColor(cellStyle.getBottomBorderColor(), cellRangeAddress, sheet); + } + } // -------------------------------------------------------------------------------------------------------------- Private method end }