You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/15 17:27:35 UTC

svn commit: r754686 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang/text: StrBuilder.java StrTokenizer.java

Author: sebb
Date: Sun Mar 15 16:27:34 2009
New Revision: 754686

URL: http://svn.apache.org/viewvc?rev=754686&view=rev
Log:
Genericize

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java?rev=754686&r1=754685&r2=754686&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java Sun Mar 15 16:27:34 2009
@@ -946,9 +946,9 @@
      * @return this, to enable chaining
      * @since 2.3
      */
-    public StrBuilder appendAll(Collection coll) {
+    public StrBuilder appendAll(Collection<?> coll) {
         if (coll != null && coll.size() > 0) {
-            Iterator it = coll.iterator();
+            Iterator<?> it = coll.iterator();
             while (it.hasNext()) {
                 append(it.next());
             }
@@ -965,7 +965,7 @@
      * @return this, to enable chaining
      * @since 2.3
      */
-    public StrBuilder appendAll(Iterator it) {
+    public StrBuilder appendAll(Iterator<?> it) {
         if (it != null) {
             while (it.hasNext()) {
                 append(it.next());
@@ -1007,10 +1007,10 @@
      * @param separator  the separator to use, null means no separator
      * @return this, to enable chaining
      */
-    public StrBuilder appendWithSeparators(Collection coll, String separator) {
+    public StrBuilder appendWithSeparators(Collection<?> coll, String separator) {
         if (coll != null && coll.size() > 0) {
             separator = (separator == null ? "" : separator);
-            Iterator it = coll.iterator();
+            Iterator<?> it = coll.iterator();
             while (it.hasNext()) {
                 append(it.next());
                 if (it.hasNext()) {
@@ -1031,7 +1031,7 @@
      * @param separator  the separator to use, null means no separator
      * @return this, to enable chaining
      */
-    public StrBuilder appendWithSeparators(Iterator it, String separator) {
+    public StrBuilder appendWithSeparators(Iterator<?> it, String separator) {
         if (it != null) {
             separator = (separator == null ? "" : separator);
             while (it.hasNext()) {
@@ -1292,6 +1292,7 @@
      * @return this, to enable chaining
      * @throws IndexOutOfBoundsException if the index is invalid
      */
+    @SuppressWarnings("null") // str cannot be null
     public StrBuilder insert(int index, String str) {
         validateIndex(index);
         if (str == null) {
@@ -1303,7 +1304,7 @@
             ensureCapacity(newSize);
             System.arraycopy(buffer, index, buffer, index + strLen, size - index);
             size = newSize;
-            str.getChars(0, strLen, buffer, index);
+            str.getChars(0, strLen, buffer, index); // str cannot be null here
         }
         return this;
     }
@@ -2576,7 +2577,7 @@
 
         /** {@inheritDoc} */
         @Override
-        protected List tokenize(char[] chars, int offset, int count) {
+        protected List<String> tokenize(char[] chars, int offset, int count) {
             if (chars == null) {
                 return super.tokenize(StrBuilder.this.buffer, 0, StrBuilder.this.size());
             } else {

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java?rev=754686&r1=754685&r2=754686&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java Sun Mar 15 16:27:34 2009
@@ -455,9 +455,9 @@
      *
      * @return the tokens as a String array
      */
-    public List getTokenList() {
+    public List<String> getTokenList() {
         checkTokenized();
-        List list = new ArrayList(tokens.length);
+        List<String> list = new ArrayList<String>(tokens.length);
         for (int i = 0; i < tokens.length; i++) {
             list.add(tokens[i]);
         }
@@ -612,11 +612,11 @@
         if (tokens == null) {
             if (chars == null) {
                 // still call tokenize as subclass may do some work
-                List split = tokenize(null, 0, 0);
-                tokens = (String[]) split.toArray(new String[split.size()]);
+                List<String> split = tokenize(null, 0, 0);
+                tokens = split.toArray(new String[split.size()]);
             } else {
-                List split = tokenize(chars, 0, chars.length);
-                tokens = (String[]) split.toArray(new String[split.size()]);
+                List<String> split = tokenize(chars, 0, chars.length);
+                tokens = split.toArray(new String[split.size()]);
             }
         }
     }
@@ -641,12 +641,12 @@
      * @param count  the number of characters to tokenize, must be valid
      * @return the modifiable list of String tokens, unmodifiable if null array or zero count
      */
-    protected List tokenize(char[] chars, int offset, int count) {
+    protected List<String> tokenize(char[] chars, int offset, int count) {
         if (chars == null || count == 0) {
-            return Collections.EMPTY_LIST;
+            return Collections.emptyList();
         }
         StrBuilder buf = new StrBuilder();
-        List tokens = new ArrayList();
+        List<String> tokens = new ArrayList<String>();
         int pos = offset;
         
         // loop around the entire buffer
@@ -668,7 +668,7 @@
      * @param list  the list to add to
      * @param tok  the token to add
      */
-    private void addToken(List list, String tok) {
+    private void addToken(List<String> list, String tok) {
         if (tok == null || tok.length() == 0) {
             if (isIgnoreEmptyTokens()) {
                 return;
@@ -691,7 +691,7 @@
      * @return the starting position of the next field (the character
      *  immediately after the delimiter), or -1 if end of string found
      */
-    private int readNextToken(char[] chars, int start, int len, StrBuilder workArea, List tokens) {
+    private int readNextToken(char[] chars, int start, int len, StrBuilder workArea, List<String> tokens) {
         // skip all leading whitespace, unless it is the
         // field delimiter or the quote character
         while (start < len) {
@@ -742,7 +742,7 @@
      *  then the length of string
      */
     private int readWithQuotes(char[] chars, int start, int len, StrBuilder workArea, 
-                               List tokens, int quoteStart, int quoteLen) 
+                               List<String> tokens, int quoteStart, int quoteLen) 
     {
         // Loop until we've found the end of the quoted
         // string or the end of the input