summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2008-08-13 02:39:50 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2008-08-13 02:39:50 +0000
commit19f784490cf64bb54bd95aae17ff07b43f271763 (patch)
treedf0b3c507cfa116a566fabdb0c412441a610ddc1
parent7094a4d9b6180c6c7b9772e314b539e498a362b7 (diff)
downloadjackcess-19f784490cf64bb54bd95aae17ff07b43f271763.tar.gz
jackcess-19f784490cf64bb54bd95aae17ff07b43f271763.zip
add utility methods for getting size/scale/precision within valid range for a given type
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@372 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/java/com/healthmarketscience/jackcess/DataType.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/DataType.java b/src/java/com/healthmarketscience/jackcess/DataType.java
index 8e08bec..022b521 100644
--- a/src/java/com/healthmarketscience/jackcess/DataType.java
+++ b/src/java/com/healthmarketscience/jackcess/DataType.java
@@ -352,6 +352,23 @@ public enum DataType {
return((value >= minValue) && (value <= maxValue));
}
+ public int toValidSize(int size) {
+ return toValidRange(size, getMinSize(), getMaxSize());
+ }
+
+ public int toValidScale(int scale) {
+ return toValidRange(scale, getMinScale(), getMaxScale());
+ }
+
+ public int toValidPrecision(int precision) {
+ return toValidRange(precision, getMinPrecision(), getMaxPrecision());
+ }
+
+ private int toValidRange(int value, int minValue, int maxValue) {
+ return((value > maxValue) ? maxValue :
+ ((value < minValue) ? minValue : value));
+ }
+
public static DataType fromByte(byte b) throws IOException {
DataType rtn = DATA_TYPES.get(b);
if (rtn != null) {