4 * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
6 * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
7 * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
9 * Refer to the XMLSpy Documentation for further details.
10 * http://www.altova.com/xmlspy
14 package com.jmex.xml.types;
16 import java.math.BigDecimal;
17 import java.math.BigInteger;
19 public class SchemaFloat implements SchemaTypeNumber {
20 protected float value;
21 protected boolean isempty;
22 protected boolean isnull;
25 public SchemaFloat() {
29 public SchemaFloat(SchemaFloat newvalue) {
30 value = newvalue.value;
31 isempty = newvalue.isempty;
32 isnull = newvalue.isnull;
35 public SchemaFloat(float newvalue) {
39 public SchemaFloat(double newvalue) {
40 setValue( (float)newvalue );
43 public SchemaFloat(String newvalue) {
47 public SchemaFloat(SchemaType newvalue) {
51 public SchemaFloat(SchemaTypeNumber newvalue) {
52 assign( (SchemaType)newvalue );
56 public float getValue() {
60 public void setValue(float newvalue) {
66 public void parse(String s) {
68 String newvalue = SchemaNormalizedString.normalize(SchemaNormalizedString.WHITESPACE_COLLAPSE, s);
70 if( newvalue == null )
72 else if( newvalue.length() == 0)
76 value = Float.parseFloat(newvalue);
79 } catch( NumberFormatException e) {
80 throw new StringParseException(e);
85 public void assign(SchemaType newvalue) {
86 if( newvalue == null || newvalue.isNull() )
88 else if( newvalue.isEmpty() )
90 else if( newvalue instanceof SchemaTypeNumber ) {
91 value = ( (SchemaTypeNumber) newvalue).floatValue();
95 throw new TypesIncompatibleException( newvalue, this );
98 public void setNull() {
104 public void setEmpty() {
111 public int hashCode() {
112 return Float.floatToIntBits(value);
115 public boolean equals(Object obj) {
116 if (! (obj instanceof SchemaFloat))
118 return value == ( (SchemaFloat) obj).value;
121 public Object clone() {
122 return new SchemaFloat(this);
125 public String toString() {
126 if( isempty || isnull )
129 String result = Float.toString(value);
130 if( result.length() > 2 && result.substring( result.length()-2, result.length()).equals(".0") )
131 return result.substring( 0, result.length()-2 );
135 public int length() {
136 return toString().length();
139 public boolean booleanValue() {
140 return !(value==0 || value==Float.NaN);
143 public boolean isEmpty() {
147 public boolean isNull() {
151 public int compareTo(Object obj) {
152 return compareTo( (SchemaFloat) obj);
155 public int compareTo(SchemaFloat obj) {
156 return Float.compare(value, obj.value);
159 // interface SchemaTypeNumber
160 public int numericType() {
161 return NUMERIC_VALUE_FLOAT;
164 public int intValue() {
168 public long longValue() {
172 public BigInteger bigIntegerValue() {
174 return new BigInteger(toString());
175 } catch( NumberFormatException e ) {
176 throw new ValuesNotConvertableException( this, new SchemaInteger( 0 ) );
180 public float floatValue() {
184 public double doubleValue() {
188 public BigDecimal bigDecimalValue() {
189 return new BigDecimal(value);