KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > validators > Range


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.util.validators;
25
26 import org.infoglue.cms.exception.Bug;
27
28
29 /**
30  * <todo>
31  * Time is running out, the illusion fades away...
32  * This package will be refactored/extended after iteration 1.
33  * - move to com.holigrow.yoda.util.validators ?
34  * - interfaces + factory
35  * - constructor madness (setXXX instead of N constructors?)
36  * - more validators
37  * - more fun
38  * </todo>
39  *
40  * @@author <a HREF="meat_for_the_butcher@@yahoo.com">Patrik Nyborg</a>
41  */

42 public class Range {
43   // --- [Constants] -----------------------------------------------------------
44
// --- [Attributes] ----------------------------------------------------------
45

46   //
47
private int lowerLimit = 0;
48   //
49
private int upperLimit = 0;
50   //
51
private boolean hasUpperLimit = true;
52
53
54
55   // --- [Static] --------------------------------------------------------------
56
// --- [Constructors] --------------------------------------------------------
57

58   /**
59    *
60    */

61   Range() {
62     this.hasUpperLimit = false;
63   }
64
65   /**
66    *
67    */

68   public Range(int upperLimit) {
69     this(0, upperLimit);
70   }
71
72   /**
73    *
74    */

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   // --- [Public] --------------------------------------------------------------
86
// --- [X implementation] ----------------------------------------------------
87
// --- [X Overrides] ---------------------------------------------------------
88
// --- [Package protected] ---------------------------------------------------
89

90   /**
91    *
92    */

93   boolean isWithinLimits(int value) {
94     return (value >= this.lowerLimit) && (!this.hasUpperLimit || value <= this.upperLimit);
95   }
96
97
98
99   // --- [Private] -------------------------------------------------------------
100
// --- [Protected] -----------------------------------------------------------
101
// --- [Inner classes] -------------------------------------------------------
102
/**
103  * Returns the lowerLimit.
104  * @return int
105  */

106 public int getLowerLimit()
107 {
108     return lowerLimit;
109 }
110
111 /**
112  * Returns the upperLimit.
113  * @return int
114  */

115 public int getUpperLimit()
116 {
117     return upperLimit;
118 }
119
120 /**
121  * Returns the hasUpperLimit.
122  * @return boolean
123  */

124 public boolean getHasUpperLimit()
125 {
126     return hasUpperLimit;
127 }
128
129 }
Popular Tags