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 2005/01/05 06:16:15 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv/xs DecimalDV.java
mrglavas 2005/01/04 21:16:15
Modified: java/src/org/apache/xerces/impl/dv/xs DecimalDV.java
Log:
Implementing the new XSDecimal interface. Committing a patch from Naela Nissar with some modifications.
Revision Changes Path
1.12 +78 -2 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DecimalDV.java
Index: DecimalDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DecimalDV.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DecimalDV.java 6 Oct 2004 14:56:46 -0000 1.11
+++ DecimalDV.java 5 Jan 2005 05:16:15 -0000 1.12
@@ -16,8 +16,12 @@
package org.apache.xerces.impl.dv.xs;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
import org.apache.xerces.impl.dv.ValidationContext;
+import org.apache.xerces.xs.datatypes.XSDecimal;
/**
* Represent the schema type "decimal"
@@ -56,7 +60,7 @@
}
// Avoid using the heavy-weight java.math.BigDecimal
- static class XDecimal {
+ static class XDecimal implements XSDecimal {
// sign: 0 for vlaue 0; 1 for positive values; -1 for negative values
int sign = 1;
// total digits. >= 1
@@ -279,6 +283,78 @@
}
}
canonical = buffer.toString();
+ }
+
+ public BigDecimal getBigDecimal() {
+ if (sign == 0) {
+ return new BigDecimal(BigInteger.ZERO);
+ }
+ return new BigDecimal(toString());
+ }
+
+ public BigInteger getBigInteger() throws NumberFormatException {
+ if (fracDigits != 0) {
+ throw new NumberFormatException();
+ }
+ if (sign == 0) {
+ return BigInteger.ZERO;
+ }
+ if (sign == 1) {
+ return new BigInteger(ivalue);
+ }
+ return new BigInteger("-" + ivalue);
+ }
+
+ public long getLong() throws NumberFormatException {
+ if (fracDigits != 0) {
+ throw new NumberFormatException();
+ }
+ if (sign == 0) {
+ return 0L;
+ }
+ if (sign == 1) {
+ return Long.parseLong(ivalue);
+ }
+ return Long.parseLong("-" + ivalue);
+ }
+
+ public int getInt() throws NumberFormatException {
+ if (fracDigits != 0) {
+ throw new NumberFormatException();
+ }
+ if (sign == 0) {
+ return 0;
+ }
+ if (sign == 1) {
+ return Integer.parseInt(ivalue);
+ }
+ return Integer.parseInt("-" + ivalue);
+ }
+
+ public short getShort() throws NumberFormatException {
+ if (fracDigits != 0) {
+ throw new NumberFormatException();
+ }
+ if (sign == 0) {
+ return 0;
+ }
+ if (sign == 1) {
+ return Short.parseShort(ivalue);
+ }
+ return Short.parseShort("-" + ivalue);
+ }
+
+ public byte getByte() throws NumberFormatException {
+ if (fracDigits != 0) {
+ throw new NumberFormatException();
+ }
+ if (sign == 0) {
+ return 0;
+ }
+ if (sign == 1) {
+ return Byte.parseByte(ivalue);
+ }
+ return Byte.parseByte("-" + ivalue);
}
}
} // class DecimalDV
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org