KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > datatype > xsd > PrecisionRestrictDatatype


1 package com.thaiopensource.datatype.xsd;
2
3 import java.math.BigDecimal JavaDoc;
4
5 class PrecisionRestrictDatatype extends ValueRestrictDatatype {
6   private final int precision;
7
8   PrecisionRestrictDatatype(DatatypeBase base, int precision) {
9     super(base);
10     this.precision = precision;
11   }
12
13   boolean satisfiesRestriction(Object JavaDoc obj) {
14     return getPrecision((BigDecimal JavaDoc)obj) <= precision;
15   }
16
17   static int getPrecision(BigDecimal JavaDoc n) {
18     return n.movePointRight(n.scale()).abs().toString().length();
19   }
20 }
21
Popular Tags