From 67863cffe79cd9a36d28aca63e4feb41051af964 Mon Sep 17 00:00:00 2001 From: Markus Spann Date: Thu, 15 Feb 2024 10:47:48 +0100 Subject: [PATCH] Review toString methods - replace all usage of reflectionToString --- .../spannm/jackcess/expr/Identifier.java | 11 ++--- .../github/spannm/jackcess/impl/ByteUtil.java | 4 +- .../spannm/jackcess/impl/ColumnImpl.java | 12 ++--- .../spannm/jackcess/impl/CursorImpl.java | 6 ++- .../spannm/jackcess/impl/DatabaseImpl.java | 13 ++++- .../spannm/jackcess/impl/IndexData.java | 5 +- .../impl/InternalColumnValidator.java | 8 +-- .../spannm/jackcess/impl/PropertyMapImpl.java | 9 ++-- .../github/spannm/jackcess/impl/UsageMap.java | 3 +- .../complex/AttachmentColumnInfoImpl.java | 5 +- .../jackcess/impl/expr/Expressionator.java | 43 ++++++++-------- .../spannm/jackcess/impl/expr/FormatUtil.java | 7 ++- .../jackcess/impl/query/AppendQueryImpl.java | 3 +- .../impl/query/BaseSelectQueryImpl.java | 7 ++- .../spannm/jackcess/impl/query/QueryImpl.java | 34 ++++++------- .../github/spannm/jackcess/util/Joiner.java | 29 +++++------ .../spannm/jackcess/util/StringUtil.java | 49 ------------------- .../spannm/jackcess/util/ToStringBuilder.java | 2 +- .../spannm/jackcess/impl/IndexCodesTest.java | 2 +- .../spannm/jackcess/util/StringUtilTest.java | 12 ----- 20 files changed, 104 insertions(+), 160 deletions(-) diff --git a/src/main/java/io/github/spannm/jackcess/expr/Identifier.java b/src/main/java/io/github/spannm/jackcess/expr/Identifier.java index 569a5ce..fad4a52 100644 --- a/src/main/java/io/github/spannm/jackcess/expr/Identifier.java +++ b/src/main/java/io/github/spannm/jackcess/expr/Identifier.java @@ -17,6 +17,7 @@ package io.github.spannm.jackcess.expr; import java.util.Objects; +import java.util.Optional; /** * identifies a database entity (e.g. the name of a database field). An Identify must have an object name, but the @@ -72,13 +73,9 @@ public boolean equals(Object o) { @Override public String toString() { StringBuilder sb = new StringBuilder(); - if (_collectionName != null) { - sb.append("[").append(_collectionName).append("]."); - } - sb.append("[").append(_objectName).append("]"); - if (_propertyName != null) { - sb.append(".[").append(_propertyName).append("]"); - } + Optional.ofNullable(_collectionName).ifPresent(x -> sb.append('[').append(x).append("].")); + sb.append('[').append(_objectName).append(']'); + Optional.ofNullable(_propertyName).ifPresent(x -> sb.append('[').append(x).append("].")); return sb.toString(); } diff --git a/src/main/java/io/github/spannm/jackcess/impl/ByteUtil.java b/src/main/java/io/github/spannm/jackcess/impl/ByteUtil.java index 2517995..6415efb 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/ByteUtil.java +++ b/src/main/java/io/github/spannm/jackcess/impl/ByteUtil.java @@ -473,10 +473,10 @@ public static String toHexString(ByteBuffer buffer, } else { - rtn.append(" "); + rtn.append(' '); if (next % NUM_BYTES_PER_BLOCK == 0) { - rtn.append(" "); + rtn.append(' '); } } } diff --git a/src/main/java/io/github/spannm/jackcess/impl/ColumnImpl.java b/src/main/java/io/github/spannm/jackcess/impl/ColumnImpl.java index 5eb4f6a..dcaa5cf 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/ColumnImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/ColumnImpl.java @@ -1221,22 +1221,22 @@ private static String readGUIDValue(ByteBuffer buffer, ByteOrder order) { } StringBuilder sb = new StringBuilder(22); - sb.append("{"); + sb.append('{'); sb.append(ByteUtil.toHexString(buffer, 0, 4, false)); - sb.append("-"); + sb.append('-'); sb.append(ByteUtil.toHexString(buffer, 4, 2, false)); - sb.append("-"); + sb.append('-'); sb.append(ByteUtil.toHexString(buffer, 6, 2, false)); - sb.append("-"); + sb.append('-'); sb.append(ByteUtil.toHexString(buffer, 8, 2, false)); - sb.append("-"); + sb.append('-'); sb.append(ByteUtil.toHexString(buffer, 10, 6, false)); - sb.append("}"); + sb.append('}'); return sb.toString(); } diff --git a/src/main/java/io/github/spannm/jackcess/impl/CursorImpl.java b/src/main/java/io/github/spannm/jackcess/impl/CursorImpl.java index 329d72d..de287fa 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/CursorImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/CursorImpl.java @@ -721,7 +721,8 @@ protected boolean isCurrentRowValid() throws IOException { @Override public String toString() { - return getClass().getSimpleName() + " CurPosition " + _curPos + ", PrevPosition " + _prevPos; + return String.format("%s[id=%s, table=%s, prevPos=%s, curPos=%s]", + getClass().getSimpleName(), _id, _table, _prevPos, _curPos); } /** @@ -983,7 +984,8 @@ private PositionImpl getPreviousPosition() { @Override public String toString() { - return getClass().getSimpleName() + " " + _cursorId + " CurPosition " + _curPos + ", PrevPosition " + _prevPos; + return String.format("%s[cursorId=%s, curPos=%s, prevPos=%s]", + getClass().getSimpleName(), _cursorId, _curPos, _prevPos); } } diff --git a/src/main/java/io/github/spannm/jackcess/impl/DatabaseImpl.java b/src/main/java/io/github/spannm/jackcess/impl/DatabaseImpl.java index af17ec6..b87ef10 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/DatabaseImpl.java @@ -1864,7 +1864,18 @@ private static void validateName(String name, int maxLength, String nameType) { @Override public String toString() { - return StringUtil.reflectionToString(this); + return String.format( + "%s[file=%s, name=%s, readOnly=%s, tableParentId=%s, format=%s, tableNames=%s, pageChannel=%s, " + + "systemCatalog=%s, tableFinder=%s, accessControlEntries=%s, relParentId=%s, relationships=%s, queries=%s, " + + "complexCols=%s, newTableSIDs=%s, dbErrorHandler=%s, fileFormat=%s, charset=%s, timeZone=%s, zoneId=%s, defaultSortOrder=%s, " + + "defaultCodePage=%s, columnOrder=%s, enforceForeignKeys=%s, allowAutoNumInsert=%s, evaluateExpressions=%s, validatorFactory=%s, " + + "tableCache=%s, propsHandler=%s, dbParentId=%s, newObjOwner=%s, dbPropMaps=%s, summaryPropMaps=%s, userDefPropMaps=%s, " + + "linkResolver=%s, linkedDbs=%s, fkEnforcerSharedState=%s, evalCtx=%s, dtf=%s]", + getClass().getSimpleName(), + _file, _name, _readOnly, _tableParentId, _format, _tableNames, _pageChannel, _systemCatalog, _tableFinder, _accessControlEntries, _relParentId, + _relationships, _queries, _complexCols, _newTableSIDs, _dbErrorHandler, _fileFormat, _charset, _timeZone, _zoneId, _defaultSortOrder, _defaultCodePage, _columnOrder, _enforceForeignKeys, + _allowAutoNumInsert, _evaluateExpressions, _validatorFactory, _tableCache, _propsHandler, _dbParentId, Arrays.toString(_newObjOwner), _dbPropMaps, _summaryPropMaps, _userDefPropMaps, + _linkResolver, _linkedDbs, _fkEnforcerSharedState, _evalCtx, _dtf); } /** diff --git a/src/main/java/io/github/spannm/jackcess/impl/IndexData.java b/src/main/java/io/github/spannm/jackcess/impl/IndexData.java index 1dfc145..3a12c3c 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/IndexData.java +++ b/src/main/java/io/github/spannm/jackcess/impl/IndexData.java @@ -1456,7 +1456,10 @@ protected final void writeValue(Object value, ByteStream bout) throws IOExceptio @Override public String toString() { - return ToStringBuilder.builder(this).append("column", getColumn()).append("flags", getFlags() + " " + (isAscending() ? "(ASC)" : "(DSC)")).toString(); + return ToStringBuilder.builder(this) + .append("column", getColumn()) + .append("flags", getFlags() + " " + (isAscending() ? "(ASC)" : "(DSC)")) + .toString(); } } diff --git a/src/main/java/io/github/spannm/jackcess/impl/InternalColumnValidator.java b/src/main/java/io/github/spannm/jackcess/impl/InternalColumnValidator.java index 05ba832..3b03942 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/InternalColumnValidator.java +++ b/src/main/java/io/github/spannm/jackcess/impl/InternalColumnValidator.java @@ -59,18 +59,18 @@ public final Object validate(Column col, Object val) throws IOException { @Override public String toString() { - StringBuilder sb = new StringBuilder().append("{"); + StringBuilder sb = new StringBuilder('{'); if (_delegate instanceof InternalColumnValidator) { ((InternalColumnValidator) _delegate).appendToString(sb); } else if (_delegate != SimpleColumnValidator.INSTANCE) { sb.append("custom=").append(_delegate); } if (sb.length() > 1) { - sb.append(";"); + sb.append(';'); } appendToString(sb); - sb.append("}"); - return sb.toString(); + return sb.append('}') + .toString(); } protected abstract void appendToString(StringBuilder sb); diff --git a/src/main/java/io/github/spannm/jackcess/impl/PropertyMapImpl.java b/src/main/java/io/github/spannm/jackcess/impl/PropertyMapImpl.java index 66b4a03..e3f77f6 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/PropertyMapImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/PropertyMapImpl.java @@ -169,17 +169,16 @@ public String toString() { } public static String toString(PropertyMap map) { - StringBuilder sb = new StringBuilder(); - sb.append(PropertyMaps.DEFAULT_NAME.equals(map.getName()) ? "" : map.getName()) + StringBuilder sb = new StringBuilder(PropertyMaps.DEFAULT_NAME.equals(map.getName()) ? "" : map.getName()) .append(" {"); for (Iterator iter = map.iterator(); iter.hasNext();) { sb.append(iter.next()); if (iter.hasNext()) { - sb.append(","); + sb.append(','); } } - sb.append("}"); - return sb.toString(); + return sb.append('}') + .toString(); } public static Property createProperty(String name, DataType type, Object value) { diff --git a/src/main/java/io/github/spannm/jackcess/impl/UsageMap.java b/src/main/java/io/github/spannm/jackcess/impl/UsageMap.java index b1ba73d..58a1e3a 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/UsageMap.java +++ b/src/main/java/io/github/spannm/jackcess/impl/UsageMap.java @@ -998,7 +998,8 @@ private int updatePosition(int pageNumber) { @Override public String toString() { - return getClass().getSimpleName() + " CurPosition " + _curPageNumber + ", PrevPosition " + _prevPageNumber; + return String.format("%s[curPageNumber=%s, prevPageNumber=%s]", + getClass().getSimpleName(), _curPageNumber, _prevPageNumber); } /** diff --git a/src/main/java/io/github/spannm/jackcess/impl/complex/AttachmentColumnInfoImpl.java b/src/main/java/io/github/spannm/jackcess/impl/complex/AttachmentColumnInfoImpl.java index 13e2fa3..7adce07 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/complex/AttachmentColumnInfoImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/complex/AttachmentColumnInfoImpl.java @@ -348,7 +348,6 @@ public void delete() throws IOException { @Override public String toString() { - String dataStr = null; try { dataStr = ByteUtil.toHexString(getFileData()); @@ -356,8 +355,8 @@ public String toString() { dataStr = e.toString(); } - return "Attachment(" + getComplexValueForeignKey() + "," + getId() - + ") " + getFileUrl() + ", " + getFileName() + ", " + getFileType() + return "Attachment(" + getComplexValueForeignKey() + "," + getId() + ") " + + getFileUrl() + ", " + getFileName() + ", " + getFileType() + ", " + getFileTimeStampObject() + ", " + getFileFlags() + ", " + dataStr; } diff --git a/src/main/java/io/github/spannm/jackcess/impl/expr/Expressionator.java b/src/main/java/io/github/spannm/jackcess/impl/expr/Expressionator.java index e1717bc..d036105 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/expr/Expressionator.java +++ b/src/main/java/io/github/spannm/jackcess/impl/expr/Expressionator.java @@ -1044,7 +1044,7 @@ private static StringBuilder appendLeadingExpr( expr.toString(ctx, sb, isDebug); if (sb.length() > len) { // only add space if the leading expr added some text - sb.append(" "); + sb.append(' '); } return sb; } @@ -1159,22 +1159,23 @@ public String toString() { Map.Entry> e = getTopPos(); // TODO actually format expression? - StringBuilder sb = new StringBuilder() - .append("[token ").append(e.getKey()).append("] ("); + StringBuilder sb = new StringBuilder("[token ") + .append(e.getKey()).append("] ("); for (Iterator iter = e.getValue().iterator(); iter.hasNext();) { Token t = iter.next(); - sb.append("'").append(t.getValueStr()).append("'"); + sb.append('\'').append(t.getValueStr()).append('\''); if (iter.hasNext()) { - sb.append(","); + sb.append(','); } } - sb.append(")"); + sb.append(')'); if (_pendingExpr != null) { - sb.append(" [pending '").append(_pendingExpr.toDebugString(_ctx)) - .append("']"); + sb.append(" [pending '") + .append(_pendingExpr.toDebugString(_ctx)) + .append("']"); } return sb.toString(); @@ -1413,11 +1414,11 @@ protected boolean isValidationExpr() { protected StringBuilder toString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { if (isDebug) { - sb.append("<").append(getClass().getSimpleName()).append(">{"); + sb.append('<').append(getClass().getSimpleName()).append(">{"); } toExprString(ctx, sb, isDebug); if (isDebug) { - sb.append("}"); + sb.append('}'); } return sb; } @@ -1571,7 +1572,7 @@ protected void toExprString( if (_val.getType() == Value.Type.STRING) { literalStrToString((String) _val.get(), sb); } else if (_val.getType().isTemporal()) { - sb.append("#").append(_val.getAsString(ctx)).append("#"); + sb.append('#').append(_val.getAsString(ctx)).append('#'); } else { sb.append(_val.get()); } @@ -1637,9 +1638,9 @@ public void collectIdentifiers(Collection identifiers) { @Override protected void toExprString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { - sb.append("("); + sb.append('('); _expr.toString(ctx, sb, isDebug); - sb.append(")"); + sb.append(')'); } } @@ -1672,13 +1673,13 @@ public void collectIdentifiers(Collection identifiers) { @Override protected void toExprString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { - sb.append(_func.getName()).append("("); + sb.append(_func.getName()).append('('); if (!_params.isEmpty()) { exprListToString(_params, ",", ctx, sb, isDebug); } - sb.append(")"); + sb.append(')'); } } @@ -1734,7 +1735,7 @@ public void collectIdentifiers(Collection identifiers) { protected void toExprString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { appendLeadingExpr(_left, ctx, sb, isDebug) - .append(_op).append(" "); + .append(_op).append(' '); _right.toString(ctx, sb, isDebug); } } @@ -1795,7 +1796,7 @@ protected void toExprString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { sb.append(_op); if (isDebug || ((UnaryOp) _op).needsSpace()) { - sb.append(" "); + sb.append(' '); } _expr.toString(ctx, sb, isDebug); } @@ -1939,10 +1940,10 @@ public Value eval(EvalContext ctx) { protected void toExprString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { appendLeadingExpr(_expr, ctx, sb, isDebug) - .append(_op).append(" "); + .append(_op).append(' '); literalStrToString(_patternStr, sb); if (isDebug) { - sb.append("(").append(getPattern()).append(")"); + sb.append('(').append(getPattern()).append(')'); } } } @@ -1979,7 +1980,7 @@ protected void toExprString( appendLeadingExpr(_expr, ctx, sb, isDebug) .append(_op).append(" ("); exprListToString(_exprs, ",", ctx, sb, isDebug); - sb.append(")"); + sb.append(')'); } } @@ -2028,7 +2029,7 @@ public void collectIdentifiers(Collection identifiers) { protected void toExprString( LocaleContext ctx, StringBuilder sb, boolean isDebug) { appendLeadingExpr(_expr, ctx, sb, isDebug) - .append(_op).append(" "); + .append(_op).append(' '); _startRangeExpr.toString(ctx, sb, isDebug); sb.append(" And "); _endRangeExpr.toString(ctx, sb, isDebug); diff --git a/src/main/java/io/github/spannm/jackcess/impl/expr/FormatUtil.java b/src/main/java/io/github/spannm/jackcess/impl/expr/FormatUtil.java index 2b94a51..3c61735 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/expr/FormatUtil.java +++ b/src/main/java/io/github/spannm/jackcess/impl/expr/FormatUtil.java @@ -752,8 +752,7 @@ private static Fmt parseCustomNumberFormat(ExprBuf buf, Args args) { String[] fmtStrs = new String[NUM_NF_FMTS]; int fmtIdx = 0; StringBuilder pendingLiteral = new StringBuilder(); - NumberFormatter.NotationType[] expTypes = - new NumberFormatter.NotationType[NUM_NF_FMTS]; + NumberFormatter.NotationType[] expTypes = new NumberFormatter.NotationType[NUM_NF_FMTS]; boolean[] hasFmts = new boolean[NUM_NF_FMTS]; boolean[] hasReqDigit = new boolean[NUM_NF_FMTS]; @@ -1130,7 +1129,7 @@ public static String createNumberFormatPattern( fmt.append(incLeadDigit ? "0" : "#"); if (numDecDigits > 0) { - fmt.append("."); + fmt.append('.'); fmt.append("0".repeat(Math.max(0, numDecDigits))); } @@ -1140,7 +1139,7 @@ public static String createNumberFormatPattern( // the javadocs claim the second pattern does not need to be fully // defined, but it doesn't seem to work that way String mainPat = fmt.toString(); - fmt.append(";(").append(mainPat).append(")"); + fmt.append(";(").append(mainPat).append(')'); } return fmt.toString(); diff --git a/src/main/java/io/github/spannm/jackcess/impl/query/AppendQueryImpl.java b/src/main/java/io/github/spannm/jackcess/impl/query/AppendQueryImpl.java index c65b4c5..7e624b5 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/query/AppendQueryImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/query/AppendQueryImpl.java @@ -31,8 +31,7 @@ */ public class AppendQueryImpl extends BaseSelectQueryImpl implements AppendQuery { - public AppendQueryImpl(String name, List rows, int objectId, - int objectFlag) { + public AppendQueryImpl(String name, List rows, int objectId, int objectFlag) { super(name, rows, objectId, objectFlag, Type.APPEND); } diff --git a/src/main/java/io/github/spannm/jackcess/impl/query/BaseSelectQueryImpl.java b/src/main/java/io/github/spannm/jackcess/impl/query/BaseSelectQueryImpl.java index 3585acd..bdfb803 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/query/BaseSelectQueryImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/query/BaseSelectQueryImpl.java @@ -30,8 +30,7 @@ public abstract class BaseSelectQueryImpl extends QueryImpl implements BaseSelectQuery { - protected BaseSelectQueryImpl(String name, List rows, int objectId, - int objectFlag, Type type) { + protected BaseSelectQueryImpl(String name, List rows, int objectId, int objectFlag, Type type) { super(name, rows, objectId, objectFlag, type); } @@ -87,8 +86,8 @@ public String getSelectType() { } if (hasFlag(TOP_SELECT_TYPE)) { - StringBuilder builder = new StringBuilder(); - builder.append("TOP ").append(getFlagRow()._name1); + StringBuilder builder = new StringBuilder("TOP ") + .append(getFlagRow()._name1); if (hasFlag(PERCENT_SELECT_TYPE)) { builder.append(" PERCENT"); } diff --git a/src/main/java/io/github/spannm/jackcess/impl/query/QueryImpl.java b/src/main/java/io/github/spannm/jackcess/impl/query/QueryImpl.java index 166cf48..469b03b 100644 --- a/src/main/java/io/github/spannm/jackcess/impl/query/QueryImpl.java +++ b/src/main/java/io/github/spannm/jackcess/impl/query/QueryImpl.java @@ -23,14 +23,10 @@ import io.github.spannm.jackcess.impl.RowIdImpl; import io.github.spannm.jackcess.impl.RowImpl; import io.github.spannm.jackcess.query.Query; -import io.github.spannm.jackcess.util.StringUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** * Base class for classes which encapsulate information about an Access query. The {@link #toSQLString()} method can be @@ -46,11 +42,10 @@ public abstract class QueryImpl implements Query { private final String _name; private final List _rows; private final int _objectId; - private final Type _type; private final int _objectFlag; + private final Type _type; - protected QueryImpl(String name, List rows, int objectId, int objectFlag, - Type type) { + protected QueryImpl(String name, List rows, int objectId, int objectFlag, Type type) { _name = name; _rows = rows; _objectId = objectId; @@ -58,11 +53,9 @@ protected QueryImpl(String name, List rows, int objectId, int objectFlag, _objectFlag = objectFlag; if (type != Type.UNKNOWN) { - short foundType = getShortValue(getQueryType(rows), - _type.getValue()); + short foundType = getShortValue(getQueryType(rows), _type.getValue()); if (foundType != _type.getValue()) { - throw new IllegalStateException(withErrorContext( - "Unexpected query type " + foundType)); + throw new IllegalStateException(withErrorContext("Unexpected query type " + foundType)); } } } @@ -337,7 +330,8 @@ public String toSQLString() { @Override public String toString() { - return StringUtil.reflectionToString(this); + return String.format("%s[name=%s, rows=%d, objectId=%s, type=%s, objectFlag=%s]", + getClass().getSimpleName(), _name, _rows.size(), _objectId, _type, _objectFlag); } /** @@ -603,7 +597,8 @@ public io.github.spannm.jackcess.Row toTableRow() { @Override public String toString() { - return StringUtil.reflectionToString(this); + return String.format("%s[id=%s, attribute=%s, expression=%s, flag=%s, extra=%s, name1=%s, name2=%s, objectId=%s, order=%s]", + getClass().getSimpleName(), _id, _attribute, _expression, _flag, _extra, _name1, _name2, _objectId, Arrays.toString(_order)); } } @@ -696,8 +691,7 @@ private static final class SimpleTable extends TableSource { private final String _tableExpr; private SimpleTable(String tableName) { - this(tableName, toOptionalQuotedExpr( - new StringBuilder(), tableName, true).toString()); + this(tableName, toOptionalQuotedExpr(new StringBuilder(), tableName, true).toString()); } private SimpleTable(String tableName, String tableExpr) { @@ -754,7 +748,7 @@ protected void toString(StringBuilder sb, boolean isTopLevel) { } if (!isTopLevel) { - sb.append("("); + sb.append('('); } _from.toString(sb, false); @@ -764,15 +758,15 @@ protected void toString(StringBuilder sb, boolean isTopLevel) { boolean multiOnExpr = _on.size() > 1; if (multiOnExpr) { - sb.append("("); + sb.append('('); } sb.append(_on); if (multiOnExpr) { - sb.append(")"); + sb.append(')'); } if (!isTopLevel) { - sb.append(")"); + sb.append(')'); } } diff --git a/src/main/java/io/github/spannm/jackcess/util/Joiner.java b/src/main/java/io/github/spannm/jackcess/util/Joiner.java index ae8a6e4..872231a 100644 --- a/src/main/java/io/github/spannm/jackcess/util/Joiner.java +++ b/src/main/java/io/github/spannm/jackcess/util/Joiner.java @@ -222,8 +222,7 @@ private void toEntryValues(Object[] fromRow) { * Returns a pretty string describing the foreign key relationship backing this Joiner. */ public String toFKString() { - StringBuilder sb = new StringBuilder(); - sb.append("Foreign Key from "); + StringBuilder sb = new StringBuilder("Foreign Key from "); String fromType = "] (primary)"; String toType = "] (secondary)"; @@ -232,25 +231,27 @@ public String toFKString() { toType = "] (primary)"; } - sb.append(getFromTable().getName()).append("["); + sb.append(getFromTable().getName()) + .append('[') - sb.append(_fromCols.get(0).getName()); + .append(_fromCols.get(0).getName()); for (int i = 1; i < _fromCols.size(); ++i) { - sb.append(",").append(_fromCols.get(i).getName()); + sb.append(',').append(_fromCols.get(i).getName()); } - sb.append(fromType); + sb.append(fromType) - sb.append(" to ").append(getToTable().getName()).append("["); + .append(" to ") + .append(getToTable().getName()) + .append('['); List toCols = _toCursor.getIndex().getColumns(); sb.append(toCols.get(0).getName()); for (int i = 1; i < toCols.size(); ++i) { - sb.append(",").append(toCols.get(i).getName()); + sb.append(',').append(toCols.get(i).getName()); } - sb.append(toType) - .append(" (Db=") - .append(((DatabaseImpl) getFromTable().getDatabase()).getName()) - .append(")"); - - return sb.toString(); + return sb.append(toType) + .append(" (Db=") + .append(((DatabaseImpl) getFromTable().getDatabase()).getName()) + .append(')') + .toString(); } } diff --git a/src/main/java/io/github/spannm/jackcess/util/StringUtil.java b/src/main/java/io/github/spannm/jackcess/util/StringUtil.java index 14f8e34..c000919 100644 --- a/src/main/java/io/github/spannm/jackcess/util/StringUtil.java +++ b/src/main/java/io/github/spannm/jackcess/util/StringUtil.java @@ -1,11 +1,6 @@ package io.github.spannm.jackcess.util; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.nio.CharBuffer; -import java.util.Arrays; -import java.util.Comparator; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.IntStream; /** @@ -94,48 +89,4 @@ public static String remove(CharSequence cs, CharSequence remove) { return cs.toString().replace(remove, ""); } - /** - * Generates a string representation of {@code obj} using reflection on its non-static declared fields. - * - * @param obj object to generate string from - * @param longClassName use full class name if {@code true} or simple name if {@code false} - * @param hashCode include the object's hash code if {@code true} - * @return string representation - */ - public static String reflectionToString(Object obj, boolean longClassName, boolean hashCode) { - if (obj == null) { - return "null"; - } - StringBuilder sb = new StringBuilder(longClassName ? obj.getClass().getName() : obj.getClass().getSimpleName()); - if (hashCode) { - sb.append('@').append(Integer.toHexString(System.identityHashCode(obj))); - } - sb.append('['); - AtomicBoolean firstField = new AtomicBoolean(true); - Arrays.stream(obj.getClass().getDeclaredFields()).filter(f -> !Modifier.isStatic(f.getModifiers())).sorted(Comparator.comparing(Field::getName)).forEach(f -> { - if (!firstField.compareAndSet(true, false)) { - sb.append(','); - } - sb.append(f.getName()).append('='); - try { - f.setAccessible(true); - Object val = f.get(obj); - sb.append(val == null ? "" : val); - } catch (Exception _ex) { - sb.append('<').append(_ex).append('>'); - } - }); - return sb.append(']').toString(); - } - - /** - * Generates a string representation of {@code obj} using reflection on its non-static declared fields using the object's full class name and including the object's hash code.
- * - * @param obj object to generate string from - * @return string representation - */ - public static String reflectionToString(Object obj) { - return reflectionToString(obj, true, true); - } - } diff --git a/src/main/java/io/github/spannm/jackcess/util/ToStringBuilder.java b/src/main/java/io/github/spannm/jackcess/util/ToStringBuilder.java index 36ca148..8deda54 100644 --- a/src/main/java/io/github/spannm/jackcess/util/ToStringBuilder.java +++ b/src/main/java/io/github/spannm/jackcess/util/ToStringBuilder.java @@ -109,7 +109,7 @@ void appendInternal(StringBuilder _buffer, String _fieldName, Object _value) { if (_value instanceof byte[]) { ByteBuffer bb = PageChannel.wrap((byte[]) _value); int len = bb.remaining(); - _buffer.append("(").append(len).append(") ").append(ByteUtil.toHexString(bb, bb.position(), Math.min(len, maxByteDetailLen))); + _buffer.append('(').append(len).append(") ").append(ByteUtil.toHexString(bb, bb.position(), Math.min(len, maxByteDetailLen))); if (len > maxByteDetailLen) { _buffer.append("..."); } diff --git a/src/test/java/io/github/spannm/jackcess/impl/IndexCodesTest.java b/src/test/java/io/github/spannm/jackcess/impl/IndexCodesTest.java index 4e54de9..6af416d 100644 --- a/src/test/java/io/github/spannm/jackcess/impl/IndexCodesTest.java +++ b/src/test/java/io/github/spannm/jackcess/impl/IndexCodesTest.java @@ -675,7 +675,7 @@ private static void handleInternational2Entry(String inlineCodes, String entryCo public static String toUnicodeStr(Object obj) throws Exception { StringBuilder sb = new StringBuilder(); for (char c : obj.toString().toCharArray()) { - sb.append(toUnicodeStr(c)).append(" "); + sb.append(toUnicodeStr(c)).append(' '); } return sb.toString(); } diff --git a/src/test/java/io/github/spannm/jackcess/util/StringUtilTest.java b/src/test/java/io/github/spannm/jackcess/util/StringUtilTest.java index ac7c416..71eedc4 100644 --- a/src/test/java/io/github/spannm/jackcess/util/StringUtilTest.java +++ b/src/test/java/io/github/spannm/jackcess/util/StringUtilTest.java @@ -69,16 +69,4 @@ public void testRemove() { assertEquals("long", StringUtil.remove("long", "longer")); } - @Test - public void testReflectionToString() { - assertEquals("null", StringUtil.reflectionToString(null)); - String str = StringUtil.reflectionToString(new TestObj()); - assertTrue(str.matches("^io\\.github\\.spannm\\.jackcess\\.util\\.StringUtilTest\\$TestObj@[0-9a-f]+\\[strVal=testing\\]$")); - assertEquals("Integer[value=47]", StringUtil.reflectionToString(Integer.valueOf(47), false, false)); - } - - static class TestObj { - final String strVal = "testing"; - } - }