This patch (committed) fixes some bugs in the TabSet class:

2006-07-24  David Gilbert  <[EMAIL PROTECTED]>

        * javax/swing/text/TabSet.java
        (TabSet): Check for null argument,
        (getTab): Throw IllegalArgumentException for index out of bounds,
        (getTabIndexAfter): Changed test to '<=',
        and updated API docs all over,
        * javax/swing/text/TabStop.java: Updated API docs.

Regards,

Dave
Index: javax/swing/text/TabSet.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/TabSet.java,v
retrieving revision 1.3
diff -u -r1.3 TabSet.java
--- javax/swing/text/TabSet.java        13 Sep 2005 23:44:50 -0000      1.3
+++ javax/swing/text/TabSet.java        24 Jul 2006 17:09:08 -0000
@@ -39,20 +39,44 @@
 
 import java.io.Serializable;
 
+/**
+ * A set of tab stops.  Instances of this class are immutable.
+ */
 public class TabSet implements Serializable
 {
   /** The serialization UID (compatible with JDK1.5). */
   private static final long serialVersionUID = 2367703481999080593L;
 
+  /** Storage for the tab stops. */
   TabStop[] tabs;
 
+  /**
+   * Creates a new <code>TabSet</code> containing the specified tab stops.
+   * 
+   * @param t  the tab stops (<code>null</code> permitted).
+   */
   public TabSet(TabStop[] t) 
   {
-    tabs = t;
+    if (t != null)
+      tabs = (TabStop[]) t.clone();
+    else 
+      tabs = new TabStop[0];
   }
  
+  /**
+   * Returns the tab stop with the specified index.
+   * 
+   * @param i  the index.
+   * 
+   * @return The tab stop.
+   * 
+   * @throws IllegalArgumentException if <code>i</code> is not in the range 
+   *     <code>0</code> to <code>getTabCount() - 1</code>.
+   */
   public TabStop getTab(int i) 
   {
+    if (i < 0 || i >= tabs.length)
+      throw new IllegalArgumentException("Index out of bounds.");
     return tabs[i];
   }
 
@@ -65,11 +89,23 @@
       return tabs[idx];        
   }
 
+  /**
+   * Returns the number of tab stops in this tab set.
+   * 
+   * @return The number of tab stops in this tab set.
+   */
   public int getTabCount() 
   {
     return tabs.length;
   }
 
+  /**
+   * Returns the index of the specified tab, or -1 if the tab is not found.
+   * 
+   * @param tab  the tab (<code>null</code> permitted).
+   * 
+   * @return The index of the specified tab, or -1.
+   */
   public int getTabIndex(TabStop tab) 
   {
     for (int i = 0; i < tabs.length; ++i)
@@ -78,17 +114,28 @@
     return -1;
   }
 
+  /**
+   * Returns the index of the tab at or after the specified location.
+   * 
+   * @param location  the tab location.
+   * 
+   * @return The index of the tab stop, or -1.
+   */
   public int getTabIndexAfter(float location) 
   {
-    int idx = -1;
-    for (int i = 0; i < tabs.length; ++i)
+    for (int i = 0; i < tabs.length; i++)
       {
-        if (location < tabs[i].getPosition())
-          idx = i;
+        if (location <= tabs[i].getPosition())
+          return i;
       }
-    return idx;
+    return -1;
   }
 
+  /**
+   * Returns a string representation of this <code>TabSet</code>.
+   * 
+   * @return A string representation of this <code>TabSet</code>.
+   */
   public String toString()
   {
     StringBuffer sb = new StringBuffer();
Index: javax/swing/text/TabStop.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/TabStop.java,v
retrieving revision 1.4
diff -u -r1.4 TabStop.java
--- javax/swing/text/TabStop.java       24 Jul 2006 16:17:29 -0000      1.4
+++ javax/swing/text/TabStop.java       24 Jul 2006 17:09:08 -0000
@@ -39,6 +39,9 @@
 
 import java.io.Serializable;
 
+/**
+ * Represents a tab position in some text.
+ */
 public class TabStop implements Serializable
 {
   /** The serialization UID (compatible with JDK1.5). */
@@ -61,18 +64,42 @@
   int align;
   int leader;
 
+  /**
+   * Creates a new <code>TabStop</code> for the specified tab position.
+   * 
+   * @param pos  the tab position.
+   */
   public TabStop(float pos) 
   {
     this(pos, ALIGN_LEFT, LEAD_NONE);
   }
   
+  /**
+   * Creates a new <code>TabStop</code> with the specified attributes.
+   * 
+   * @param pos  the tab position.
+   * @param align  the alignment (one of [EMAIL PROTECTED] #ALIGN_LEFT}, 
+   *     [EMAIL PROTECTED] #ALIGN_CENTER}, [EMAIL PROTECTED] #ALIGN_RIGHT}, 
[EMAIL PROTECTED] #ALIGN_DECIMAL} 
+   *     or [EMAIL PROTECTED] #ALIGN_BAR}).
+   * @param leader  the leader (one of [EMAIL PROTECTED] #LEAD_NONE}, [EMAIL 
PROTECTED] #LEAD_DOTS}, 
+   *     [EMAIL PROTECTED] #LEAD_EQUALS}, [EMAIL PROTECTED] #LEAD_HYPHENS}, 
[EMAIL PROTECTED] #LEAD_THICKLINE} 
+   *     or [EMAIL PROTECTED] #LEAD_UNDERLINE}).
+   */
   public TabStop(float pos, int align, int leader)
   {
     this.pos = pos;
     this.align = align;
     this.leader = leader;
   }
-    
+  
+  /**
+   * Tests this <code>TabStop</code> for equality with an arbitrary object.
+   * 
+   * @param other  the other object (<code>null</code> permitted).
+   * 
+   * @return <code>true</code> if this <code>TabStop</code> is equal to 
+   *     the specified object, and <code>false</code> otherwise.
+   */
   public boolean equals(Object other) 
   {
     return (other != null)
@@ -82,21 +109,45 @@
       && (((TabStop)other).getAlignment() == this.getAlignment());
   }
 
+  /**
+   * Returns the tab alignment.  This should be one of [EMAIL PROTECTED] 
#ALIGN_LEFT}, 
+   * [EMAIL PROTECTED] #ALIGN_CENTER}, [EMAIL PROTECTED] #ALIGN_RIGHT}, [EMAIL 
PROTECTED] #ALIGN_DECIMAL} or 
+   * [EMAIL PROTECTED] #ALIGN_BAR}.
+   * 
+   * @return The tab alignment.
+   */
   public int getAlignment() 
   {
     return align;
   }
 
+  /**
+   * Returns the leader type.  This should be one of [EMAIL PROTECTED] 
#LEAD_NONE}, 
+   * [EMAIL PROTECTED] #LEAD_DOTS}, [EMAIL PROTECTED] #LEAD_EQUALS}, [EMAIL 
PROTECTED] #LEAD_HYPHENS}, 
+   * [EMAIL PROTECTED] #LEAD_THICKLINE} or [EMAIL PROTECTED] #LEAD_UNDERLINE}.
+   * 
+   * @return The leader type.
+   */
   public int getLeader() 
   {
     return leader;
   }
 
+  /**
+   * Returns the tab position.
+   * 
+   * @return The tab position.
+   */
   public float getPosition() 
   {
     return pos;
   }
 
+  /**
+   * Returns a hash code for this <code>TabStop</code>.
+   * 
+   * @return A hash code.
+   */
   public int hashCode() 
   {
     return (int) pos + (int) leader + (int) align;

Reply via email to