Simplify the ValueEval.toString() implementations and include more information on unexpected types of ValueEval

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1794956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-05-12 11:38:05 +00:00
parent d9df038f4a
commit e77156d9f4
7 changed files with 28 additions and 41 deletions

View File

@ -34,7 +34,7 @@ public final class BoolEval implements NumericValueEval, StringValueEval {
*
* @return the <tt>BoolEval</tt> instance representing <tt>b</tt>.
*/
public static final BoolEval valueOf(boolean b) {
public static BoolEval valueOf(boolean b) {
return b ? TRUE : FALSE;
}
@ -55,10 +55,8 @@ public final class BoolEval implements NumericValueEval, StringValueEval {
}
public String toString() {
StringBuilder sb = new StringBuilder(64);
sb.append(getClass().getName()).append(" [");
sb.append(getStringValue());
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
getStringValue() +
"]";
}
}

View File

@ -51,7 +51,8 @@ public final class ErrorEval implements ValueEval {
/**
* Translates an Excel internal error code into the corresponding POI ErrorEval instance
* @param errorCode
* @param errorCode An error code listed in {@link FormulaError}
* @throws RuntimeException If an unknown errorCode is specified
*/
public static ErrorEval valueOf(int errorCode) {
FormulaError error = FormulaError.forInt(errorCode);
@ -89,10 +90,8 @@ public final class ErrorEval implements ValueEval {
return _error.getString();
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(_error.getString());
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
_error.getString() +
"]";
}
}

View File

@ -34,10 +34,8 @@ public final class ExternalNameEval implements ValueEval {
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(_name.getNameText());
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
_name.getNameText() +
"]";
}
}

View File

@ -37,10 +37,8 @@ public final class FunctionNameEval implements ValueEval {
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(_functionName);
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
_functionName +
"]";
}
}

View File

@ -45,10 +45,8 @@ public final class StringEval implements StringValueEval {
}
public String toString() {
StringBuilder sb = new StringBuilder(64);
sb.append(getClass().getName()).append(" [");
sb.append(_value);
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
_value +
"]";
}
}

View File

@ -184,7 +184,7 @@ final class LookupUtils {
public static final CompareResult EQUAL = new CompareResult(false, 0);
public static final CompareResult GREATER_THAN = new CompareResult(false, +1);
public static final CompareResult valueOf(int simpleCompareResult) {
public static CompareResult valueOf(int simpleCompareResult) {
if(simpleCompareResult < 0) {
return LESS_THAN;
}
@ -194,7 +194,7 @@ final class LookupUtils {
return EQUAL;
}
public static final CompareResult valueOf(boolean matches) {
public static CompareResult valueOf(boolean matches) {
if(matches) {
return EQUAL ;
}
@ -215,11 +215,9 @@ final class LookupUtils {
return _isGreaterThan;
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(formatAsString());
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
formatAsString() +
"]";
}
private String formatAsString() {
@ -267,11 +265,9 @@ final class LookupUtils {
return compareSameType(other);
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(getValueAsString());
sb.append("]");
return sb.toString();
return getClass().getName() + " [" +
getValueAsString() +
"]";
}
protected abstract CompareResult compareSameType(ValueEval other);
/** used only for debug purposes */
@ -475,7 +471,7 @@ final class LookupUtils {
// zero is FALSE, everything else is TRUE
return 0.0 != nve.getNumberValue();
}
throw new RuntimeException("Unexpected eval type (" + valEval.getClass().getName() + ")");
throw new RuntimeException("Unexpected eval type (" + valEval + ")");
}
public static int lookupIndexOfValue(ValueEval lookupValue, ValueVector vector, boolean isRangeLookup) throws EvaluationException {

View File

@ -153,7 +153,7 @@ public final class Match extends Var2or3ArgFunction {
// else looks like a number
throw new EvaluationException(ErrorEval.NA);
}
throw new RuntimeException("Unexpected eval type (" + eval.getClass().getName() + ")");
throw new RuntimeException("Unexpected eval type (" + eval + ")");
}