1 23 24 package org.infoglue.cms.util.validators; 25 26 import org.infoglue.cms.exception.Bug; 27 28 29 42 public class Range { 43 46 private int lowerLimit = 0; 48 private int upperLimit = 0; 50 private boolean hasUpperLimit = true; 52 53 54 55 58 61 Range() { 62 this.hasUpperLimit = false; 63 } 64 65 68 public Range(int upperLimit) { 69 this(0, upperLimit); 70 } 71 72 75 public Range(int lowerLimit, int upperLimit) { 76 if(lowerLimit < 0 || lowerLimit > upperLimit) { 77 throw new Bug("Illegal arguments : lowerLimit=" + lowerLimit + ", upperLimit=" + upperLimit + "."); 78 } 79 this.lowerLimit = lowerLimit; 80 this.upperLimit = upperLimit; 81 } 82 83 84 85 90 93 boolean isWithinLimits(int value) { 94 return (value >= this.lowerLimit) && (!this.hasUpperLimit || value <= this.upperLimit); 95 } 96 97 98 99 106 public int getLowerLimit() 107 { 108 return lowerLimit; 109 } 110 111 115 public int getUpperLimit() 116 { 117 return upperLimit; 118 } 119 120 124 public boolean getHasUpperLimit() 125 { 126 return hasUpperLimit; 127 } 128 129 } | Popular Tags |