2002/css-validator/org/w3c/css/media/css3 MediaAspectRatio.java,1.1,1.2 MediaDeviceAspectRatio.java,1.1,1.2

Update of /sources/public/2002/css-validator/org/w3c/css/media/css3
In directory hutz:/tmp/cvs-serv31862/css/media/css3

Modified Files:
	MediaAspectRatio.java MediaDeviceAspectRatio.java 
Log Message:
ratio is now a value, as it should

Index: MediaDeviceAspectRatio.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/media/css3/MediaDeviceAspectRatio.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- MediaDeviceAspectRatio.java	21 Oct 2011 01:49:07 -0000	1.1
+++ MediaDeviceAspectRatio.java	22 Oct 2011 13:36:22 -0000	1.2
@@ -9,8 +9,6 @@
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
-import org.w3c.css.values.CssNumber;
-import org.w3c.css.values.CssOperator;
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
@@ -19,8 +17,6 @@
  */
 public class MediaDeviceAspectRatio extends MediaFeature {
 
-    int h, w;
-
     /**
      * Create a new MediaHeight
      */
@@ -39,47 +35,25 @@
             throws InvalidParamException {
 
         if (expression != null) {
-            if (expression.getCount() != 2) {
+            if (expression.getCount() != 1) {
                 throw new InvalidParamException("unrecognize", ac);
             }
             CssValue val = expression.getValue();
 
-            if (val.getType() == CssTypes.CSS_NUMBER) {
-                CssNumber valnum = (CssNumber) val;
-                if (!valnum.isInteger()) {
-                    throw new InvalidParamException("integer",
-                            val.toString(), ac);
-                }
-                w = valnum.getInt();
-                // TODO FIXME this should be replaced when / is no longer
-                // an operator
-                if (expression.getOperator() != CssOperator.SLASH) {
-                    throw new InvalidParamException("operator", expression.toString(), ac);
-                }
-                // now the second value
-                expression.next();
-                val = expression.getValue();
-                if (val.getType() == CssTypes.CSS_NUMBER) {
-                    valnum = (CssNumber) val;
-                    if (!valnum.isInteger()) {
-                        throw new InvalidParamException("integer",
-                                val.toString(), ac);
-                    }
-                    h = valnum.getInt();
-                    // perfect, now set the modifier
-                    setModifier(ac, modifier);
-                    return;
-                }
+            if (val.getType() == CssTypes.CSS_RATIO) {
+                value = val;
+                setModifier(ac, modifier);
+            } else {
+                throw new InvalidParamException("unrecognize", ac);
             }
-            // otherwise... fail
-            throw new InvalidParamException("value", expression.getValue(),
-                    getFeatureName(), ac);
+            setModifier(ac, modifier);
         } else {
             if (modifier != null) {
                 throw new InvalidParamException("nomodifiershortmedia",
                         getFeatureName(), ac);
             }
         }
+
     }
 
     public MediaDeviceAspectRatio(ApplContext ac, String modifier, CssExpression expression)
@@ -92,9 +66,7 @@
      */
 
     public Object get() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(w).append('/').append(h);
-        return sb.toString();
+        return value;
     }
 
     /**
@@ -112,32 +84,13 @@
     public boolean equals(MediaFeature other) {
         try {
             MediaDeviceAspectRatio mar = (MediaDeviceAspectRatio) other;
-            if (h == 0 || mar.h == 0) {
-                return (w == 0 && mar.w == 0 && h == 0 && mar.h == 0);
+            if (value == null) {
+                return (other.value == null);
             }
-            float thisRatio = ((float) w) / ((float) h);
-            float otherRatio = ((float) mar.w) / ((float) mar.h);
-
-            return (thisRatio == otherRatio)
-                    && (((modifier == null) && (mar.modifier == null)) || ((modifier != null) && modifier.equals(mar.modifier)));
+            return value.equals(other.value);
         } catch (ClassCastException cce) {
             return false;
         }
     }
 
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        if (h == 0 && w == 0) {
-            return getFeatureName();
-        }
-        StringBuilder sb = new StringBuilder();
-        if (modifier != null) {
-            sb.append(modifier).append('-');
-        }
-        sb.append(getFeatureName());
-        sb.append(':').append(w).append('/').append(h);
-        return sb.toString();
-    }
 }

Index: MediaAspectRatio.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/media/css3/MediaAspectRatio.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- MediaAspectRatio.java	21 Oct 2011 01:49:07 -0000	1.1
+++ MediaAspectRatio.java	22 Oct 2011 13:36:22 -0000	1.2
@@ -9,8 +9,6 @@
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
-import org.w3c.css.values.CssNumber;
-import org.w3c.css.values.CssOperator;
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
@@ -19,8 +17,6 @@
  */
 public class MediaAspectRatio extends MediaFeature {
 
-    int h, w;
-
     /**
      * Create a new MediaHeight
      */
@@ -39,41 +35,18 @@
             throws InvalidParamException {
 
         if (expression != null) {
-            if (expression.getCount() != 2) {
+            if (expression.getCount() != 1) {
                 throw new InvalidParamException("unrecognize", ac);
             }
             CssValue val = expression.getValue();
 
-            if (val.getType() == CssTypes.CSS_NUMBER) {
-                CssNumber valnum = (CssNumber) val;
-                if (!valnum.isInteger()) {
-                    throw new InvalidParamException("integer",
-                            val.toString(), ac);
-                }
-                w = valnum.getInt();
-                // TODO FIXME this should be replaced when / is no longer
-                // an operator
-                if (expression.getOperator() != CssOperator.SLASH) {
-                    throw new InvalidParamException("operator", expression.toString(), ac);
-                }
-                // now the second value
-                expression.next();
-                val = expression.getValue();
-                if (val.getType() == CssTypes.CSS_NUMBER) {
-                    valnum = (CssNumber) val;
-                    if (!valnum.isInteger()) {
-                        throw new InvalidParamException("integer",
-                                val.toString(), ac);
-                    }
-                    h = valnum.getInt();
-                    // perfect, now set the modifier
-                    setModifier(ac, modifier);
-                    return;
-                }
+            if (val.getType() == CssTypes.CSS_RATIO) {
+                value = val;
+                setModifier(ac, modifier);
+            } else {
+                throw new InvalidParamException("unrecognize", ac);
             }
-            // otherwise... fail
-            throw new InvalidParamException("value", expression.getValue(),
-                    getFeatureName(), ac);
+            setModifier(ac, modifier);
         } else {
             if (modifier != null) {
                 throw new InvalidParamException("nomodifiershortmedia",
@@ -92,9 +65,7 @@
      */
 
     public Object get() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(w).append('/').append(h);
-        return sb.toString();
+        return value;
     }
 
     /**
@@ -112,32 +83,12 @@
     public boolean equals(MediaFeature other) {
         try {
             MediaAspectRatio mar = (MediaAspectRatio) other;
-            if (h == 0 || mar.h == 0) {
-                return (w == 0 && mar.w == 0 && h == 0 && mar.h == 0);
+            if (value == null) {
+                return (other.value == null);
             }
-            float thisRatio = ((float) w) / ((float) h);
-            float otherRatio = ((float) mar.w) / ((float) mar.h);
-
-            return (thisRatio == otherRatio)
-                    && (((modifier == null) && (mar.modifier == null)) || ((modifier != null) && modifier.equals(mar.modifier)));
+            return value.equals(other.value);
         } catch (ClassCastException cce) {
             return false;
         }
     }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        if (h == 0 && w == 0) {
-            return getFeatureName();
-        }
-        StringBuilder sb = new StringBuilder();
-        if (modifier != null) {
-            sb.append(modifier).append('-');
-        }
-        sb.append(getFeatureName());
-        sb.append(':').append(w).append('/').append(h);
-        return sb.toString();
-    }
 }

Received on Saturday, 22 October 2011 13:36:27 UTC