Author: rwhitcomb
Date: Fri Jan  5 17:27:26 2018
New Revision: 1820327

URL: http://svn.apache.org/viewvc?rev=1820327&view=rev
Log:
Move the "defaultToString" and "simpleDefaultToString" methods out of
Utils and into ClassUtils (because they make more sense there).
Rename the longer method to just "simpleToString".
Change the references to these methods.
Add a new "checkTwoIndexBounds" method to Utils for use in several
places (such as the "set selection" methods in the text controls).

Modified:
    pivot/trunk/core/src/org/apache/pivot/util/ClassUtils.java
    pivot/trunk/core/src/org/apache/pivot/util/Utils.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java

Modified: pivot/trunk/core/src/org/apache/pivot/util/ClassUtils.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/ClassUtils.java?rev=1820327&r1=1820326&r2=1820327&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/ClassUtils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/ClassUtils.java Fri Jan  5 
17:27:26 2018
@@ -42,4 +42,31 @@ public class ClassUtils {
         return elements[level + 2].toString();
     }
 
+    /**
+     * 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 simpleToString(Object obj) {
+        return obj.getClass().getSimpleName() + "@" +
+            Integer.toHexString(System.identityHashCode(obj));
+    }
+
 }

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=1820327&r1=1820326&r2=1820327&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Utils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/Utils.java Fri Jan  5 17:27:26 
2018
@@ -264,7 +264,6 @@ public class Utils {
             throw new IndexOutOfBoundsException("Index " + index + " out of 
bounds [" + start + ","
                 + end + "].");
         }
-
         if (index + count > end) {
             throw new IndexOutOfBoundsException("Index + count " + index + "," 
+ count
                 + " out of bounds [" + start + "," + end + "].");
@@ -272,30 +271,26 @@ public class Utils {
     }
 
     /**
-     * Get the default value of {@link Object#toString} for any given object.
+     * Check that the given {@code startIndex} and {@code endIndex} are between
+     * the values of {@code start} and {@code end}.
      *
-     * @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 startIndex  The beginning index to check.
+     * @param endIndex    The ending index (inclusive) to check.
+     * @param start  The start of the acceptable range (inclusive).
+     * @param end    The end of the acceptable range (inclusive).
      *
-     * @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).
+     * @throws IllegalArgumentException if {@code endIndex} is &lt; {@code 
startIndex}.
+     * @throws IndexOutOfBoundsException if {@code startIndex} is &lt; {@code 
start} or {@code endIndex} is &gt; {@code end}.
      */
-    public static String simpleDefaultToString(Object obj) {
-        return obj.getClass().getSimpleName() + "@" +
-            Integer.toHexString(System.identityHashCode(obj));
+    public static void checkTwoIndexBounds(int startIndex, int endIndex, int 
start, int end) {
+        if (startIndex > endIndex) {
+            throw new IllegalArgumentException("endIndex (" + endIndex + ") < 
" + "startIndex (" + startIndex + ")");
+        }
+
+        if (startIndex < start || endIndex > end) {
+            throw new IndexOutOfBoundsException("startIndex " + startIndex + " 
or endIndex " + endIndex
+                + " out of bounds [" + start + "," + end + "].");
+        }
     }
 
 }

Modified: 
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java?rev=1820327&r1=1820326&r2=1820327&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java 
(original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java 
Fri Jan  5 17:27:26 2018
@@ -32,7 +32,7 @@ import java.text.AttributedCharacterIter
 
 import org.apache.pivot.text.AttributedStringCharacterIterator;
 import org.apache.pivot.text.CompositeIterator;
-import org.apache.pivot.util.Utils;
+import org.apache.pivot.util.ClassUtils;
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.Dimensions;
 import org.apache.pivot.wtk.GraphicsUtilities;
@@ -528,7 +528,7 @@ class TextPaneSkinTextNodeView extends T
         } else {
             textSubString = text.substring(start, start + length);
         }
-        return Utils.simpleDefaultToString(this) +
+        return ClassUtils.simpleToString(this) +
             " start=" + start + ",length=" + length + " [" + textSubString + 
"]";
     }
 


Reply via email to