You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2004/09/30 21:35:19 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv/xs TypeValidator.java XSSimpleTypeDecl.java DoubleDV.java FloatDV.java AbstractDateTimeDV.java

mrglavas    2004/09/30 12:35:19

  Modified:    java/src/org/apache/xerces/impl/dv/xs TypeValidator.java
                        XSSimpleTypeDecl.java DoubleDV.java FloatDV.java
                        AbstractDateTimeDV.java
  Log:
  XML Schema 1.1 makes a distinction between equality [1] and identity [2].
  For instance 0.0 is equal but not identical to -0.0 for the float and double
  datatypes. Also for date/time datatypes, two values representing the
  same moment in time in different timezones are equal but not identical.
  For many datatypes, the identity relation is the equality relation.
  
  Thanks to the patch by Naela Nissar we now make the distinction between
  identity and equality for datatypes.
  
  [1] http://www.w3.org/TR/2004/WD-xmlschema11-2-20040716/#equality
  [2] http://www.w3.org/TR/2004/WD-xmlschema11-2-20040716/#identity
  
  Revision  Changes    Path
  1.7       +9 -1      xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TypeValidator.java
  
  Index: TypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TypeValidator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TypeValidator.java	24 Feb 2004 22:44:24 -0000	1.6
  +++ TypeValidator.java	30 Sep 2004 19:35:19 -0000	1.7
  @@ -58,6 +58,14 @@
       public static final short EQUAL         = 0;
       public static final short GREATER_THAN  = 1;
       public static final short INDETERMINATE = 2;
  +    
  +    // where there is distinction between identity and equality, this method
  +    // will be overwritten
  +    // checks whether the two values are identical; for ex, this distinguishes 
  +    // -0.0 from 0.0 
  +    public boolean isIdentical (Object value1, Object value2) {
  +        return value1.equals(value2);
  +    }
   
       // check the order relation between the two values
       // the parameters are in compiled form (from getActualValue)
  
  
  
  1.56      +11 -2     xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
  
  Index: XSSimpleTypeDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- XSSimpleTypeDecl.java	30 Sep 2004 04:19:33 -0000	1.55
  +++ XSSimpleTypeDecl.java	30 Sep 2004 19:35:19 -0000	1.56
  @@ -1780,10 +1780,19 @@
       }//getActualValue()
   
       public boolean isEqual(Object value1, Object value2) {
  -        if (value1 == null)
  +        if (value1 == null) {
               return false;
  +        }
           return value1.equals(value2);
       }//isEqual()
  +    
  +    // determine whether the two values are identical
  +    public boolean isIdentical (Object value1, Object value2) {
  +        if (value1 == null) {
  +            return false;
  +        }
  +        return fDVs[fValidationDV].isIdentical(value1, value2);
  +    }//isIdentical()
   
       // normalize the string according to the whiteSpace facet
       public static String normalize(String content, short ws) {
  
  
  
  1.9       +23 -1     xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DoubleDV.java
  
  Index: DoubleDV.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DoubleDV.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DoubleDV.java	15 Sep 2004 05:12:23 -0000	1.8
  +++ DoubleDV.java	30 Sep 2004 19:35:19 -0000	1.9
  @@ -47,6 +47,15 @@
       public int compare(Object value1, Object value2) {
           return ((XDouble)value1).compareTo((XDouble)value2);
       }//compare()
  +    
  +    //distinguishes between identity and equality for double datatype
  +    //0.0 is equal but not identical to -0.0
  +    public boolean isIdentical (Object value1, Object value2) {
  +        if (value2 instanceof XDouble) {
  +            return ((XDouble)value1).isIdentical((XDouble)value2);
  +        }
  +        return false;
  +    }//isIdentical()
   
       private static final class XDouble implements XSDouble {
           private double value;
  @@ -86,6 +95,19 @@
                   return true;
   
               return false;
  +        }
  +        
  +        // NOTE: 0.0 is equal but not identical to -0.0
  +        public boolean isIdentical (XDouble val) {
  +            if (val == this) {
  +                return true;
  +            }
  +            
  +            Double d1 = new Double(value);
  +            Double d2 = new Double(val.value);
  +            
  +            //Double values of 0.0 and -0.0 return false for Double#equals method
  +            return d1.equals(d2); 
           }
   
           private int compareTo(XDouble val) {
  
  
  
  1.9       +23 -1     xml-xerces/java/src/org/apache/xerces/impl/dv/xs/FloatDV.java
  
  Index: FloatDV.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/FloatDV.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FloatDV.java	15 Sep 2004 05:12:23 -0000	1.8
  +++ FloatDV.java	30 Sep 2004 19:35:19 -0000	1.9
  @@ -47,6 +47,15 @@
       public int compare(Object value1, Object value2){
           return ((XFloat)value1).compareTo((XFloat)value2);
       }//compare()
  +    
  +    //distinguishes between identity and equality for float datatype
  +    //0.0 is equal but not identical to -0.0
  +    public boolean isIdentical (Object value1, Object value2) {  	 	
  +        if (value2 instanceof XFloat) {
  +            return ((XFloat)value1).isIdentical((XFloat)value2);
  +        }
  +        return false;
  +    }//isIdentical()
   
       private static final class XFloat implements XSFloat {
   
  @@ -87,6 +96,19 @@
                   return true;
   
               return false;
  +        }
  +        
  +        // NOTE: 0.0 is equal but not identical to -0.0
  +        public boolean isIdentical (XFloat val) {
  +            if (val == this) {
  +                return true;
  +            }
  +            
  +            Float f1 = new Float(value);
  +            Float f2 = new Float(val.value);
  +            
  +            //Float values of 0.0 and -0.0 return false for Float#equals method
  +            return f1.equals(f2); 
           }
   
           private int compareTo(XFloat val) {
  
  
  
  1.18      +22 -1     xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java
  
  Index: AbstractDateTimeDV.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractDateTimeDV.java	28 Sep 2004 21:12:33 -0000	1.17
  +++ AbstractDateTimeDV.java	30 Sep 2004 19:35:19 -0000	1.18
  @@ -52,6 +52,27 @@
       public short getAllowedFacets(){
           return ( XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_WHITESPACE | XSSimpleTypeDecl.FACET_ENUMERATION |XSSimpleTypeDecl.FACET_MAXINCLUSIVE |XSSimpleTypeDecl.FACET_MININCLUSIVE | XSSimpleTypeDecl.FACET_MAXEXCLUSIVE  | XSSimpleTypeDecl.FACET_MINEXCLUSIVE  );
       }//getAllowedFacets()
  +    
  +    
  +    // distinguishes between identity and equality for date/time values
  +    // ie: two values representing the same "moment in time" but with different 
  +    // remembered timezones are now equal but not identical.
  +    public boolean isIdentical (Object value1, Object value2) {
  +        if (!(value1 instanceof DateTimeData) || !(value2 instanceof DateTimeData)) {
  +            return false;
  +        }
  +        
  +        DateTimeData v1 = (DateTimeData)value1;
  +        DateTimeData v2 = (DateTimeData)value2;
  +        
  +        // original timezones must be the same in addition to date/time values
  +        // being 'equal'
  +        if ((v1.timezoneHr == v2.timezoneHr) && (v1.timezoneMin == v2.timezoneMin)) {
  +            return v1.equals(v2);
  +        }
  +        
  +        return false;
  +    }//isIdentical()
   
       // the parameters are in compiled form (from getActualValue)
       public int compare (Object value1, Object value2) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org