- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 20 Mar 2008 12:15:56 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/selectors
In directory hutz:/tmp/cvs-serv17893
Modified Files:
SelectorsList.java
Log Message:
toString optimizations
Index: SelectorsList.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/SelectorsList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- SelectorsList.java 13 Aug 2007 12:38:22 -0000 1.3
+++ SelectorsList.java 20 Mar 2008 12:15:54 -0000 1.4
@@ -53,17 +53,19 @@
public class SelectorsList {
// the list of selectors
- private ArrayList selectors;
+ private ArrayList<Selector> selectors;
private ApplContext ac;
private int specificity;
+ private String stringrep = null;
+
/**
* Creates a new empty SelectorsList
*/
public SelectorsList() {
- selectors = new ArrayList();
+ selectors = new ArrayList<Selector>();
}
/**
@@ -72,14 +74,14 @@
*/
public SelectorsList(ApplContext ac) {
this.ac = ac;
- selectors = new ArrayList();
+ selectors = new ArrayList<Selector>();
}
/**
* Returns the selectors list
* @return Returns the selectors list.
*/
- public ArrayList getSelectors() {
+ public ArrayList<Selector> getSelectors() {
return selectors;
}
@@ -87,8 +89,9 @@
* Sets the selectors list
* @param selectors The selectors list to set.
*/
- public void setSelectors(ArrayList selectors) {
+ public void setSelectors(ArrayList<Selector> selectors) {
this.selectors = selectors;
+ stringrep = null;
}
/**
@@ -97,7 +100,7 @@
* @return the nth selector
*/
public Selector getSelector(int index) {
- return (Selector) selectors.get(index);
+ return selectors.get(index);
}
/**
@@ -115,12 +118,14 @@
*/
public void addSelector(Selector selector) throws InvalidParamException {
if(selectors.size() > 0) {
- Selector last = (Selector) selectors.get(selectors.size() - 1);
+ Selector last = selectors.get(selectors.size() - 1);
if(last instanceof PseudoElementSelector) {
- throw new InvalidParamException("pseudo-element", selector, ac.getMsg().getString(ac.getCssVersion()), ac);
+ throw new InvalidParamException("pseudo-element", selector,
+ ac.getMsg().getString(ac.getCssVersion()), ac);
}
}
selectors.add(selector);
+ stringrep = null;
}
/**
@@ -235,11 +240,20 @@
* @return the String representation of this SelectorsList
*/
public String toString() {
- StringBuffer res = new StringBuffer();
- for(int i = 0; i < selectors.size(); i++) {
+ if (stringrep != null ) {
+ return stringrep;
+ }
+ StringBuilder res = new StringBuilder();
+ int selsize = selectors.size();
+ for(int i = 0; i < selsize; i++) {
res.append(selectors.get(i));
}
- return res.toString();
+ stringrep = res.toString();
+ return stringrep;
+ }
+
+ public boolean isToStringCached() {
+ return (stringrep != null);
}
/**
Received on Thursday, 20 March 2008 12:16:39 UTC