/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.util; import xbn.XBNObject; /**
Manages an int that must conform to a RangeConfig. See RangeConfig.
Source code: Range.java.
Create a Range.
Note that isSet will return false, until you set a value.
@param range_config The RangeConfig. May not be null. **/ public Range(RangeConfig range_config) { throwAXIfNull(range_config, "range_config", sCNSTR); rConfig = range_config; //Initialize all internal variables...except range_config. reset(); } /**Create a Range.
@param range_config The RangeConfig. May not be null. @param i_value The initial value. Passed directly to set. **/ public Range(RangeConfig range_config, int i_value) { throwAXIfNull(range_config, "range_config", sCNSTR); rConfig = range_config; //Initialize all internal variables...except range_config. reset(); set(i_value); } /**Create a copy of the provided Range. This is a deep copy.
@param r_ange The Range to copy. May not be null. **/ public Range(Range r_ange) { try { rConfig = new RangeConfig(r_ange.rConfig); } catch(NullPointerException npx) { throwAX("constructor: r_ange is null."); } iValue = r_ange.iValue; } /**Get the current value.
@exception AssertException If no value has been set into this Range. **/ public int get() { if(!isSet()) { throwAX(".get: isSet() is false. You must set a value before getting it."); } return iValue; } /**Set the value to the provided int.
@param i_potential The potential value. Must be valid according to getRangeConfig().isValid. **/ public final void set(int i_potential) { if(!getRangeConfig().isValid(i_potential)) { throwAX(".set: i_potential is not valid according to getRangeConfig().isValid()."); } iValue = i_potential; bSet = true; } /**Get the RangeConfig for direct manipulation.
**/ public final RangeConfig getRangeConfig() { return rConfig; } /**Initialize this object as if a value were never set into it. The RangeConfig object is unaffected by this.
**/ public final void reset() { bSet = false; iValue = -1; } /**Has the value of this Range been set yet?
@return true If the one-parameter constructor was used to create this object, and the set function has not yet been called.Get some information about this Range.
**/ public String toString() { String sMid = null; if(!isSet()) { sMid = "false"; } else { sMid = "true, get()=" + get(); } return this.getClass().getName() + ": isSet()=" + sMid + ", [" + getRangeConfig().toString() + "]"; } }