2002/css-validator/org/w3c/css/values CssExpression.java,1.4,1.5

Update of /sources/public/2002/css-validator/org/w3c/css/values
In directory hutz:/tmp/cvs-serv21201

Modified Files:
	CssExpression.java 
Log Message:
using StringBuilder


Index: CssExpression.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssExpression.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- CssExpression.java	14 Sep 2005 15:15:33 -0000	1.4
+++ CssExpression.java	17 Mar 2008 17:51:33 -0000	1.5
@@ -15,176 +15,176 @@
  */
 public class CssExpression implements CssOperator {
 
-  /**
-   * Add a value to the end of the expression
-   * By default the next operator is a space
-   *
-   * @param value The value to append
-   */
-  public void addValue(CssValue value) {
-    items.addElement(new ValueOperator(value));
-    count++;
-  }
+    /**
+     * Add a value to the end of the expression
+     * By default the next operator is a space
+     *
+     * @param value The value to append
+     */
+    public void addValue(CssValue value) {
+	items.addElement(new ValueOperator(value));
+	count++;
+    }
 
-  /**
-   * Change the next operator
-   * Don't check if the operator is correct
-   *
-   * @param operator The operator
-   * @see CssOperator
-   */
-  public void setOperator(char operator) {
-    ((ValueOperator) items.elementAt(count-1)).operator = operator;
-  }
+    /**
+     * Change the next operator
+     * Don't check if the operator is correct
+     *
+     * @param operator The operator
+     * @see CssOperator
+     */
+    public void setOperator(char operator) {
+	((ValueOperator) items.elementAt(count-1)).operator = operator;
+    }
 
-  /**
-   * Change the next operator for the current position
-   * Don't check if the operator is correct
-   *
-   * @param operator The operator
-   * @see CssOperator
-   */
-  public void setCurrentOperator(char operator) {
-    ((ValueOperator) items.elementAt(index)).operator = operator;
-  }
+    /**
+     * Change the next operator for the current position
+     * Don't check if the operator is correct
+     *
+     * @param operator The operator
+     * @see CssOperator
+     */
+    public void setCurrentOperator(char operator) {
+	((ValueOperator) items.elementAt(index)).operator = operator;
+    }
 
-  /**
-   * Returns the current value of the expression
-   * don't change the position in the expression
-   */
-  public CssValue getValue() {
-    if (index == count)
-      return null;
-    else
-      return ((ValueOperator) items.elementAt(index)).value;
-  }
+    /**
+     * Returns the current value of the expression
+     * don't change the position in the expression
+     */
+    public CssValue getValue() {
+	if (index == count)
+	    return null;
+	else
+	    return ((ValueOperator) items.elementAt(index)).value;
+    }
 
-  /**
-   * Returns the current value of the expression
-   * don't change the position in the expression
-   */
-  public CssValue getNextValue() {
-    if (index+1 >= count)
-      return null;
-    else
-      return ((ValueOperator) items.elementAt(index+1)).value;
-  }
+    /**
+     * Returns the current value of the expression
+     * don't change the position in the expression
+     */
+    public CssValue getNextValue() {
+	if (index+1 >= count)
+	    return null;
+	else
+	    return ((ValueOperator) items.elementAt(index+1)).value;
+    }
 
     /* Modified by Sijtsche de Jong */
-  /**
-   * Returns the operator <strong>after</strong> the current value
-   * don't change the position in the expression
-   */
-  public char getOperator() {
-    if (index == count)
-      return SPACE;
-    else
-      return ((ValueOperator) items.elementAt(index)).operator;
-  }
-
-  /**
-   * Returns the number of elements
-   */
-  public int getCount() {
-    return count;
-  }
-
-  /**
-   * Insert the current value at the current position.
-   *
-   * @param value The value to insert
-   */
-  public void insert(CssValue value) {
-    items.insertElementAt(new ValueOperator(value), index);
-    count++;
-  }
+    /**
+     * Returns the operator <strong>after</strong> the current value
+     * don't change the position in the expression
+     */
+    public char getOperator() {
+	if (index == count)
+	    return SPACE;
+	else
+	    return ((ValueOperator) items.elementAt(index)).operator;
+    }
 
-  /**
-   * Removes the current value and his operator
-   */
-  public void remove() {
-    if (index != count)
-      items.removeElementAt(index);
-    count--;
-  }
+    /**
+     * Returns the number of elements
+     */
+    public int getCount() {
+	return count;
+    }
 
-  /**
-   * Returns true if there is no other element
-   */
-  public boolean end() {
-    return index == count;
-  }
+    /**
+     * Insert the current value at the current position.
+     *
+     * @param value The value to insert
+     */
+    public void insert(CssValue value) {
+	items.insertElementAt(new ValueOperator(value), index);
+	count++;
+    }
 
-  /**
-   * Change the position to the beginning
-   */
-  public void starts() {
-    index = 0;
-  }
+    /**
+     * Removes the current value and his operator
+     */
+    public void remove() {
+	if (index != count)
+	    items.removeElementAt(index);
+	count--;
+    }
 
-  /**
-   * Change the position to the end
-   */
-  public void ends() {
-    index = count;
-  }
+    /**
+     * Returns true if there is no other element
+     */
+    public boolean end() {
+	return index == count;
+    }
 
-  /**
-   * Change the position to the next
-   */
-  public void next() {
-    if (index < count)
-      index++;
-  }
+    /**
+     * Change the position to the beginning
+     */
+    public void starts() {
+	index = 0;
+    }
 
-  /**
-   * Change the position to the precedent
-   */
-  public void precedent() {
-    if (index > 0)
-      index--;
-  }
+    /**
+     * Change the position to the end
+     */
+    public void ends() {
+	index = count;
+    }
 
-  /**
-   * Returns a string representation of the object from the current position.
-   */
-  public String toString() {
-    String s = "";
-    for (int i = index; i < count; i++) {
-      ValueOperator vo = (ValueOperator) items.elementAt(i);
-      s += vo.value.toString() + vo.operator;
+    /**
+     * Change the position to the next
+     */
+    public void next() {
+	if (index < count)
+	    index++;
     }
 
-    if (s.length() > 0) {
-	return s.substring(0, s.length()-1);
-    } else {
-	return "**invalid state**";
+    /**
+     * Change the position to the precedent
+     */
+    public void precedent() {
+	if (index > 0)
+	    index--;
     }
-  }
 
-  /**
-   * Returns a string representation of the object before the current position.
-   */
-  public String toStringFromStart() {
-    String s = "";
-    for (int i = 0; i < index; i++) {
-      ValueOperator vo = (ValueOperator) items.elementAt(i);
-      s += vo.value.toString() + vo.operator;
+    /**
+     * Returns a string representation of the object from the current position.
+     */
+    public String toString() {
+	StringBuilder sb = new StringBuilder();
+	for (int i = index; i < count; i++) {
+	    ValueOperator vo = (ValueOperator) items.elementAt(i);
+	    sb.append(vo.value.toString()).append(vo.operator);
+	}
+	// remove the last one
+	if (sb.length() > 0) {
+	    return sb.deleteCharAt(sb.length()-1).toString();
+	} else {
+	    return "**invalid state**";
+	}
     }
 
-    return s;
-  }
+    /**
+     * Returns a string representation of the object before the current position.
+     */
+    public String toStringFromStart() {
+	StringBuilder sb = new StringBuilder();
+	for (int i = 0; i < index; i++) {
+	    ValueOperator vo = (ValueOperator) items.elementAt(i);
+	    sb.append(vo.value.toString()).append(vo.operator);
+	}
 
-  class ValueOperator {
-    ValueOperator(CssValue value) {
-      this.value = value;
-      this.operator = SPACE;
+	return sb.toString();
     }
-    CssValue value;
-    char operator;
-  }
 
-  private Vector items = new Vector();
-  private int count = 0;
-  private int index = 0;
+    class ValueOperator {
+	ValueOperator(CssValue value) {
+	    this.value = value;
+	    this.operator = SPACE;
+	}
+	CssValue value;
+	char operator;
+    }
+
+    private Vector items = new Vector();
+    private int count = 0;
+    private int index = 0;
 }

Received on Monday, 17 March 2008 17:52:09 UTC