1 19 20 package org.netbeans.modules.xml.axi.datatype; 21 22 import java.math.BigDecimal ; 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.List ; 26 import org.netbeans.modules.xml.axi.datatype.Datatype.Facet; 27 import org.netbeans.modules.xml.schema.model.Whitespace; 28 29 33 public abstract class NumberBase extends Datatype { 34 35 public final static Number UNBOUNDED_VALUE = Double.MAX_VALUE; 36 37 public final static String UNBOUNDED_STRING = "unbounded"; 39 static List <Facet> applicableFacets; 40 41 private Datatype.Kind kind; 42 43 private boolean hasFacets; 44 45 private boolean isList; 46 47 private List <Integer > totalDigits; 48 49 private List <Integer > fractionDigits; 50 51 private List <String > patterns; 52 53 private List <Whitespace.Treatment> whitespaces; 54 55 private List <Number > enumerations; 56 57 private List <Number > maxInclusives; 58 59 private List <Number > maxExclusives; 60 61 private List <Number > minInclusives; 62 63 private List <Number > minExclusives; 64 65 66 public NumberBase(Datatype.Kind kind) { 67 this.kind = kind; 68 } 69 70 public Datatype.Kind getKind() { 71 return kind; 72 } 73 74 public synchronized List <Facet> getApplicableFacets() { 75 if(applicableFacets == null) { 76 List <Facet> facets = new ArrayList <Facet>(); 77 facets.add(Facet.TOTATDIGITS); 78 facets.add(Facet.FRACTIONDIGITS); 79 facets.add(Facet.PATTERN); 80 facets.add(Facet.WHITESPACE); 81 facets.add(Facet.ENUMERATION); 82 facets.add(Facet.MAXINCLUSIVE); 83 facets.add(Facet.MAXEXCLUSIVE); 84 facets.add(Facet.MININCLUSIVE); 85 facets.add(Facet.MINEXCLUSIVE); 86 applicableFacets = Collections.unmodifiableList(facets); 87 } 88 return applicableFacets; 89 } 90 91 public boolean hasFacets() { 92 return hasFacets; 93 } 94 95 public boolean isList() { 96 return isList; 97 } 98 99 public void setIsList(boolean isList) { 100 this.isList = isList; 101 } 102 103 108 public List <String > getPatterns() { 109 return patterns; 110 } 111 112 117 public List <Number > getEnumerations() { 118 return enumerations; 119 } 120 121 126 public List <Whitespace.Treatment> getWhiteSpaces() { 127 return whitespaces; 128 } 129 130 135 public List <Integer > getTotalDigits() { 136 return totalDigits; 137 } 138 139 144 public List <Integer > getFractionDigits() { 145 return fractionDigits; 146 } 147 148 153 public List <Number > getMaxInclusives() { 154 return maxInclusives; 155 } 156 157 162 public List <Number > getMaxExclusives() { 163 return maxExclusives; 164 } 165 166 171 public List <Number > getMinInclusives() { 172 return minInclusives; 173 } 174 175 180 public List <Number > getMinExclusives() { 181 return minExclusives; 182 } 183 184 189 public void addPattern(String pattern) { 190 if(patterns == null) { 191 patterns = new ArrayList <String >(1); 192 hasFacets = true; 193 } 194 this.patterns.add(pattern); 195 } 196 197 202 public void addEnumeration(Number enumeration) { 203 if(enumerations == null) { 204 enumerations = new ArrayList <Number >(1); 205 hasFacets = true; 206 } 207 this.enumerations.add(enumeration); 208 } 209 210 215 public void addWhitespace(Whitespace.Treatment whitespace) { 216 if(whitespaces == null) { 217 whitespaces = new ArrayList <Whitespace.Treatment>(1); 218 hasFacets = true; 219 } 220 this.whitespaces.add(whitespace); 221 } 222 223 228 public void addTotalDigits(int totalDigits ) { 229 if(this.totalDigits == null) { 230 this.totalDigits = new ArrayList <Integer >(1); 231 hasFacets = true; 232 } 233 this.totalDigits.add(new Integer (totalDigits)); 234 } 235 236 241 public void addFractionDigits(int fractionDigits) { 242 if(this.fractionDigits == null) { 243 this.fractionDigits = new ArrayList <Integer >(1); 244 hasFacets = true; 245 } 246 this.fractionDigits.add(new Integer (fractionDigits)); 247 } 248 249 254 public void addMaxInclusive(Number maxInclusive) { 255 if(maxInclusives == null) { 256 maxInclusives = new ArrayList <Number >(1); 257 hasFacets = true; 258 } 259 this.maxInclusives.add(maxInclusive); 260 } 261 262 267 public void addMaxExclusive(Number maxExclusive) { 268 if(maxExclusives == null) { 269 maxExclusives = new ArrayList <Number >(1); 270 hasFacets = true; 271 } 272 this.maxExclusives.add(maxExclusive); 273 } 274 275 280 public void addMinInclusive(Number minInclusive) { 281 if(minInclusives == null) { 282 minInclusives = new ArrayList <Number >(1); 283 hasFacets = true; 284 } 285 this.minInclusives.add(minInclusive); 286 } 287 288 293 public void addMinExclusive(Number minExclusive) { 294 if(minExclusives == null) { 295 minExclusives = new ArrayList <Number >(1); 296 hasFacets = true; 297 } 298 this.minExclusives.add(minExclusive); 299 } 300 301 306 public void removePattern(String pattern) { 307 if(patterns != null) 308 patterns.remove(pattern); 309 } 310 311 316 public void removeEnumeration(Number enumeration) { 317 if(enumerations != null) 318 enumerations.remove(enumeration); 319 } 320 321 326 public void removeWhitespace(Whitespace.Treatment whitespace) { 327 if(whitespaces != null) 328 whitespaces.remove(whitespace); 329 } 330 331 336 public void removeTotalDigits(Number totalDigits ) { 337 if(this.totalDigits != null) 338 this.totalDigits.remove(totalDigits); 339 } 340 341 346 public void removeFractionDigits(Number fractionDigits) { 347 if(this.fractionDigits != null) 348 this.fractionDigits.remove(fractionDigits); 349 } 350 351 356 public void removeMaxInclusive(Number maxInclusive) { 357 if(maxInclusives != null) 358 maxInclusives.remove(maxInclusive); 359 } 360 361 366 public void removeMaxExclusive(Number maxExclusive) { 367 if(maxExclusives != null) 368 maxExclusives.remove(maxExclusive); 369 } 370 371 376 public void removeMinInclusive(Number minInclusive) { 377 if(minInclusives != null) 378 minInclusives.remove(minInclusive); 379 } 380 381 386 public void removeMinExclusive(Number minExclusive) { 387 if(minExclusives != null) 388 minExclusives.remove(minExclusive); 389 } 390 391 public static Number toNumber(String value) { 392 Number n = null; 393 if(value.equals(UNBOUNDED_STRING)) 394 n = UNBOUNDED_VALUE; 395 else { 396 try{ 397 n = new BigDecimal (value); 398 } catch(Throwable th) { 399 n = 0; 400 } 401 } 402 return n; 403 } 404 405 public static String toXMLString(Number val) { 406 if(val == UNBOUNDED_VALUE) 407 return UNBOUNDED_STRING; 408 else 409 return String.valueOf(val); 410 } 411 } 412 | Popular Tags |