You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by je...@locus.apache.org on 2000/09/07 09:39:02 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype DoubleDatatypeValidator.java

jeffreyr    00/09/07 00:39:02

  Modified:    java/src/org/apache/xerces/validators/datatype
                        DoubleDatatypeValidator.java
  Log:
  Fixed defect reported by   Dave Finkbeiner about Double datatype not checking
  boundary correctly.
  
  Revision  Changes    Path
  1.7       +60 -17    xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java
  
  Index: DoubleDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DoubleDatatypeValidator.java	2000/08/01 06:06:24	1.6
  +++ DoubleDatatypeValidator.java	2000/09/07 07:39:01	1.7
  @@ -68,7 +68,7 @@
    *
    * @author Ted Leung
    * @author Jeffrey Rodriguez
  - * @version $Id: DoubleDatatypeValidator.java,v 1.6 2000/08/01 06:06:24 jeffreyr Exp $
  + * @version $Id: DoubleDatatypeValidator.java,v 1.7 2000/09/07 07:39:01 jeffreyr Exp $
    */
   
   public class DoubleDatatypeValidator extends AbstractDatatypeValidator {
  @@ -106,7 +106,7 @@
           fDerivedByList = derivedByList;
   
           if ( facets != null ) {   // Set Facet
  -            if ( fDerivedByList == false ) { 
  +            if ( fDerivedByList == false ) {
                   for (Enumeration e = facets.keys(); e.hasMoreElements();) {
                       String key = (String) e.nextElement();
                       if (key.equals(SchemaSymbols.ELT_PATTERN)) {
  @@ -260,26 +260,69 @@
        * check that a facet is in range, assumes that facets are compatible -- compatibility ensured by setFacets
        */
       private void boundsCheck(double d) throws InvalidDatatypeValueException {
  -        boolean inUpperBound = false;
  -        boolean inLowerBound = false;
   
  -        if ( isMaxInclusiveDefined ) {
  -            inUpperBound = ( d <= fMaxInclusive );
  -        } else if ( isMaxExclusiveDefined ) {
  -            inUpperBound = ( d <  fMaxExclusive );
  +        boolean minOk = false;
  +        boolean maxOk = false;
  +        String  upperBound =  (fMaxExclusive != Double.MAX_VALUE )? (   Double.toString( fMaxExclusive)) :
  +                              ( ( fMaxInclusive != Double.MAX_VALUE )? Double.toString( fMaxInclusive):"");
  +
  +        String  lowerBound =  (fMinExclusive != Double.MIN_VALUE )? ( Double.toString( fMinExclusive ) ):
  +                              (( fMinInclusive != Double.MIN_VALUE )? Double.toString( fMinInclusive ):""); 
  +        String  lowerBoundIndicator = "";
  +        String  upperBoundIndicator = "";
  +
  +
  +        if ( isMaxInclusiveDefined) {
  +            maxOk = (d <= fMaxInclusive);
  +            upperBound          = Double.toString( fMaxInclusive );
  +            if ( upperBound != null ) {
  +                upperBoundIndicator = "<="; 
  +            } else {
  +                upperBound="";
  +            }
  +        } else if ( isMaxExclusiveDefined) {
  +            maxOk = (d < fMaxExclusive );
  +            upperBound = Double.toString(fMaxExclusive );
  +            if ( upperBound != null ) {
  +                upperBoundIndicator = "<";
  +            } else {
  +                upperBound = "";
  +            }
  +        } else {
  +            maxOk = (!isMaxInclusiveDefined && ! isMaxExclusiveDefined);
           }
   
  -        if ( isMinInclusiveDefined ) {
  -            inLowerBound = ( d >= fMinInclusive );
  -        } else if ( isMinExclusiveDefined ) {
  -            inLowerBound = ( d >  fMinExclusive );
  -        }
  +
  +
  +        if ( isMinInclusiveDefined) {
   
  -        if ( inUpperBound == false  || inLowerBound == false ) { // within bounds ?
  -            getErrorString(DatatypeMessageProvider.OutOfBounds,
  -                           DatatypeMessageProvider.MSG_NONE,
  -                           new Object [] { new Double(d), "","","","" }); //REVISIT
  +            minOk = (d >=  fMinInclusive );
  +            lowerBound = Double.toString( fMinInclusive );
  +            if ( lowerBound != null ) {
  +                lowerBoundIndicator = "<=";
  +            } else {
  +                lowerBound = "";
  +            }
  +        } else if ( isMinExclusiveDefined) {
  +            minOk = (d > fMinExclusive);
  +            lowerBound = Double.toString( fMinExclusive  );
  +            if ( lowerBound != null ) {
  +                lowerBoundIndicator = "<";
  +            } else {
  +                lowerBound = "";
  +            }
  +        } else {
  +            minOk = (!isMinInclusiveDefined && !isMinExclusiveDefined);
           }
  +
  +        if (!(minOk && maxOk))
  +            throw new InvalidDatatypeValueException (
  +                             getErrorString(DatatypeMessageProvider.OutOfBounds,
  +                                  DatatypeMessageProvider.MSG_NONE,
  +                                      new Object [] { Double.toString(d) ,  lowerBound ,
  +                                          upperBound, lowerBoundIndicator, upperBoundIndicator}));
  +
  +
       }
   
       private void enumCheck(double v) throws InvalidDatatypeValueException {