1 23 package org.infoglue.cms.applications.workflowtool.util; 24 25 28 public class RangeCheck 29 { 30 33 public static final int OK = 0; 34 35 38 public static final int EXACTLY = 1; 39 40 43 public static final int EXACTLY_ONE = 2; 44 45 48 public static final int LESS_THAN = 3; 49 50 53 public static final int GREATER_THAN = 4; 54 55 58 public static final int GREATER_THAN_ONE = 5; 59 60 63 public static final int BETWEEN = 6; 64 65 68 public static final int BETWEEN_ONE_AND_MANY = 7; 69 70 73 private final Integer min; 74 75 78 private final Integer max; 79 80 86 public RangeCheck(final Integer min, final Integer max) 87 { 88 this.min = min; 89 this.max = max; 90 } 91 92 97 public final Integer getMin() 98 { 99 return min; 100 } 101 102 107 public final Integer getMax() 108 { 109 return max; 110 } 111 112 118 public final int check(final int value) 119 { 120 boolean one = (min != null && min.intValue() == 1); 121 if(min == null && max == null) 122 { 123 return OK; 124 } 125 if(min == null) 126 { 127 return (value > max.intValue()) ? LESS_THAN : OK; 128 } 129 if(max == null) 130 { 131 return (value < min.intValue()) ? (one ? GREATER_THAN_ONE : GREATER_THAN) : OK; 132 } 133 if(min.equals(max) && value != min.intValue()) 134 { 135 return one ? EXACTLY_ONE : EXACTLY; 136 } 137 if(value < min.intValue() || value > max.intValue()) 138 { 139 return one ? BETWEEN_ONE_AND_MANY : BETWEEN; 140 } 141 return OK; 142 } 143 } 144 | Popular Tags |