From: James Ahlborn Date: Wed, 13 Aug 2008 02:39:50 +0000 (+0000) Subject: add utility methods for getting size/scale/precision within valid range for a given... X-Git-Tag: rel_1_1_17~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=19f784490cf64bb54bd95aae17ff07b43f271763;p=jackcess.git 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 --- 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) {