2002/css-validator/org/w3c/css/parser CssSelectors.java,1.30,1.31

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

Modified Files:
	CssSelectors.java 
Log Message:
clearer rewrite of canApply

Index: CssSelectors.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssSelectors.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- CssSelectors.java	12 Aug 2011 21:19:01 -0000	1.30
+++ CssSelectors.java	24 Aug 2011 19:46:55 -0000	1.31
@@ -350,6 +350,7 @@
 
     /**
      * Comparison is done on the string representation
+     *
      * @param selectors
      * @return
      */
@@ -451,8 +452,9 @@
 
     public void addAttribute(String attName, String value)
             throws InvalidParamException {
-        if (ac.getProfile() != null && !"".equals(ac.getProfile())) {
-            if (ac.getProfile().equals("mobile")) {
+        String profile = ac.getProfile();
+        if (profile != null && profile.length() != 0) {
+            if (profile.equals("mobile")) {
                 throw new InvalidParamException("notformobile", "attributes",
                         ac);
             }
@@ -478,32 +480,21 @@
     }
 
     final boolean canApply(ArrayList<Selector> attrs, ArrayList<Selector> attrs2) {
-        if (attrs.size() > 0) {
-            for (int i = 0; i < attrs.size(); i++) {
-                Selector selector = attrs.get(i);
-
-                Selector other = null;
-                int j = 0;
-                for (; j < attrs2.size(); j++) {
-                    other = attrs2.get(j);
-                    if (!other.equals(selector)) {
-                        other = null;
-                    } else {
-                        break;
-                    }
+        if (attrs.size()>0) {
+            int other_idx;
+            Selector other;
+            for (Selector selector : attrs) {
+                other_idx = attrs2.indexOf(selector);
+                if (other_idx == -1) {
+                    return false;
                 }
-                if (other != null) {
-                    if (!selector.canApply(other)) {
-                        return false;
-                    }
-                } else {
+                other = attrs2.get(other_idx);
+                if (!selector.canApply(other)) {
                     return false;
                 }
             }
-            return true;
         }
         return true;
-
     }
 
     /**

Received on Wednesday, 24 August 2011 19:47:01 UTC