You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/06/14 18:46:09 UTC
svn commit: r1798735 - /pivot/trunk/core/src/org/apache/pivot/util/Utils.java
Author: rwhitcomb
Date: Wed Jun 14 18:46:08 2017
New Revision: 1798735
URL: http://svn.apache.org/viewvc?rev=1798735&view=rev
Log:
Code enhancement: Add two new methods to Utils:
* defaultToString() -> returns string description of object just as Object.toString() would.
* simpleDefaultToString() -> same as above, except only the simple class name is used.
Modified:
pivot/trunk/core/src/org/apache/pivot/util/Utils.java
Modified: pivot/trunk/core/src/org/apache/pivot/util/Utils.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Utils.java?rev=1798735&r1=1798734&r2=1798735&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Utils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/Utils.java Wed Jun 14 18:46:08 2017
@@ -209,4 +209,32 @@ public class Utils {
+ " out of bounds [" + start + "," + end + "].");
}
}
+
+ /**
+ * Get the default value of {@link Object#toString} for any given object.
+ *
+ * @param obj Any object.
+ * @return The result of what {@link Object#toString} would return without
+ * any alternative implementation of <tt>toString()</tt> that may be implemented
+ * in the class or any intervening superclass.
+ */
+ public static String defaultToString(Object obj) {
+ return obj.getClass().getName() + "@" +
+ Integer.toHexString(System.identityHashCode(obj));
+ }
+
+ /**
+ * Get the (simple) default value of {@link Object#toString} for any given object.
+ *
+ * @param obj Any object.
+ * @return The result of what {@link Object#toString} would return without
+ * any alternative implementation of <tt>toString()</tt> that may be implemented
+ * in the class or any intervening superclass, except that the simple name
+ * of the class is used (without any package designation).
+ */
+ public static String simpleDefaultToString(Object obj) {
+ return obj.getClass().getSimpleName() + "@" +
+ Integer.toHexString(System.identityHashCode(obj));
+ }
+
}