You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2021/04/28 13:05:48 UTC
[empire-db] branch master updated: EMPIREDB-346 fix
This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new 409693f EMPIREDB-346 fix
409693f is described below
commit 409693f021f33540dbfa63ac134d417b9acdbee0
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Wed Apr 28 15:05:44 2021 +0200
EMPIREDB-346
fix
---
.../org/apache/empire/commons/ObjectUtils.java | 25 ++++++++++++----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java b/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
index 1df1b3d..30ba80c 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
@@ -92,7 +92,10 @@ public final class ObjectUtils
return new SimpleDateFormat(DATETIME_FORMAT);
}
};
-
+
+ // Interal literal for NULL
+ private static final String NULL = "NULL";
+
private ObjectUtils()
{
// Static Function only
@@ -173,19 +176,17 @@ public final class ObjectUtils
{ // Special enum handling
if (o2 instanceof Number)
return ((Enum<?>)o1).ordinal()==((Number)o2).intValue();
- else if (o2 instanceof Character)
- return ((Enum<?>)o1).name().equals(o2.toString());
- else
- return ((Enum<?>)o1).name().equals(o2);
+ // Compare Strings
+ String strVal = StringUtils.coalesce(getString((Enum<?>)o1), NULL);
+ return strVal.equals(getString(o2));
}
else if (o2 instanceof Enum<?>)
{ // Special enum handling
if (o1 instanceof Number)
return ((Enum<?>)o2).ordinal()==((Number)o1).intValue();
- else if (o1 instanceof Character)
- return ((Enum<?>)o2).name().equals(o1.toString());
- else
- return ((Enum<?>)o2).name().equals(o1);
+ // Compare Strings
+ String strVal = StringUtils.coalesce(getString((Enum<?>)o2), NULL);
+ return strVal.equals(getString(o1));
}
// Compare Strings
return o1.toString().equals(o2.toString());
@@ -561,7 +562,7 @@ public final class ObjectUtils
if (enumValue instanceof EnumValue)
return StringUtils.toString(((EnumValue)enumValue).toValue(false));
/* special case */
- if (enumValue==null || enumValue.name().equals("NULL"))
+ if (enumValue==null || enumValue.name().equals(NULL))
return null;
/* use name */
return enumValue.name();
@@ -572,6 +573,8 @@ public final class ObjectUtils
*/
public static String getString(Object value)
{
+ if (value==null || (value instanceof String))
+ return (String)value;
// convert
if (value instanceof Enum<?>)
return getString((Enum<?>)value);
@@ -580,7 +583,7 @@ public final class ObjectUtils
if (value==NO_VALUE)
return null;
// toString
- return (value!=null ? value.toString() : null);
+ return value.toString();
}
/**