From 19f784490cf64bb54bd95aae17ff07b43f271763 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Wed, 13 Aug 2008 02:39:50 +0000 Subject: [PATCH] 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 --- .../healthmarketscience/jackcess/DataType.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) { -- 2.39.5