OSDN Git Service

Set optimal mime types and executable settings.
[mikumikustudio/MikuMikuStudio.git] / src / com / jmex / xml / types / SchemaFloat.java
1 /**
2  * SchemaFloat.java
3  *
4  * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
5  *
6  * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
7  * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
8  *
9  * Refer to the XMLSpy Documentation for further details.
10  * http://www.altova.com/xmlspy
11  */
12
13
14 package com.jmex.xml.types;
15
16 import java.math.BigDecimal;
17 import java.math.BigInteger;
18
19 public class SchemaFloat implements SchemaTypeNumber {
20   protected float value;
21   protected boolean isempty;
22   protected boolean isnull;
23
24   // construction
25   public SchemaFloat() {
26     setEmpty();
27   }
28
29   public SchemaFloat(SchemaFloat newvalue) {
30     value = newvalue.value;
31     isempty = newvalue.isempty;
32     isnull = newvalue.isnull;
33   }
34
35   public SchemaFloat(float newvalue) {
36     setValue( newvalue );
37   }
38
39   public SchemaFloat(double newvalue) {
40     setValue( (float)newvalue );
41   }
42
43   public SchemaFloat(String newvalue) {
44     parse( newvalue );
45   }
46
47   public SchemaFloat(SchemaType newvalue) {
48     assign(newvalue);
49   }
50
51   public SchemaFloat(SchemaTypeNumber newvalue) {
52     assign( (SchemaType)newvalue );
53   }
54
55   // getValue, setValue
56   public float getValue() {
57     return value;
58   }
59
60   public void setValue(float newvalue) {
61     value = newvalue;
62     isempty = false;
63     isnull = false;
64   }
65
66   public void parse(String s) {
67           
68         String newvalue = SchemaNormalizedString.normalize(SchemaNormalizedString.WHITESPACE_COLLAPSE, s);
69
70     if( newvalue == null )
71       setNull();
72     else if( newvalue.length() == 0)
73       setEmpty();
74     else {
75       try {
76         value = Float.parseFloat(newvalue);
77         isempty = false;
78         isnull = false;
79       } catch( NumberFormatException e) {
80         throw new StringParseException(e);
81       }
82     }
83   }
84
85   public void assign(SchemaType newvalue) {
86     if( newvalue == null || newvalue.isNull() )
87       setNull();
88     else if( newvalue.isEmpty() )
89       setEmpty();
90     else if( newvalue instanceof SchemaTypeNumber ) {
91       value = ( (SchemaTypeNumber) newvalue).floatValue();
92       isempty = false;
93     }
94     else
95       throw new TypesIncompatibleException( newvalue, this );
96   }
97
98   public void setNull() {
99     isnull = true;
100     isempty = true;
101     value = 0;
102   }
103
104   public void setEmpty() {
105     isnull = false;
106     isempty = true;
107     value = 0;
108   }
109
110   // further
111   public int hashCode() {
112     return Float.floatToIntBits(value);
113   }
114
115   public boolean equals(Object obj) {
116     if (! (obj instanceof SchemaFloat))
117       return false;
118     return value == ( (SchemaFloat) obj).value;
119   }
120
121   public Object clone() {
122     return new SchemaFloat(this);
123   }
124
125   public String toString() {
126     if( isempty || isnull )
127       return "";
128
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 );
132     return result;
133   }
134
135   public int length() {
136     return toString().length();
137   }
138
139   public boolean booleanValue() {
140     return !(value==0 || value==Float.NaN);
141   }
142
143   public boolean isEmpty() {
144     return isempty;
145   }
146
147   public boolean isNull() {
148     return isnull;
149   }
150
151   public int compareTo(Object obj) {
152     return compareTo( (SchemaFloat) obj);
153   }
154
155   public int compareTo(SchemaFloat obj) {
156     return Float.compare(value, obj.value);
157   }
158
159   // interface SchemaTypeNumber
160   public int numericType() {
161     return NUMERIC_VALUE_FLOAT;
162   }
163
164   public int intValue() {
165     return (int) value;
166   }
167
168   public long longValue() {
169     return (long) value;
170   }
171
172   public BigInteger bigIntegerValue() {
173     try {
174       return new BigInteger(toString());
175     } catch( NumberFormatException e ) {
176       throw new ValuesNotConvertableException( this, new SchemaInteger( 0 ) );
177     }
178   }
179
180   public float floatValue() {
181     return value;
182   }
183
184   public double doubleValue() {
185     return value;
186   }
187
188   public BigDecimal bigDecimalValue() {
189     return new BigDecimal(value);
190   }
191 }