/* 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.array; import xbn.util.XBNLocked; import xbn.named.Named; import xbn.util.LockOneWay; /**
Metadata for a unique string contained in an array. This object populates the "value" side of the AOSLookup's (internal) Hashtable. Also see AOSLCreator.
Source code: UniqueString.java
Create a UniqueString.
@param s_tr The unique string. May not be null. @param i_unqArrIdx The unique array index of the s_tr. May not be less than zero. **/ public UniqueString(String s_tr, int i_unqArrIdx) { throwAXIfNull(s_tr, "s_tr", sCNSTR); if(i_unqArrIdx < 0) { throwAX("constructor: i_unqArrIdx (" + i_unqArrIdx + ") may not be less than zero."); } sString = s_tr; iUnqArrIdx = i_unqArrIdx; iInstances = 1; } /**Get the unique string.
@return s_tr Exactly as provided to the constructor. **/ public final String getString() { return sString; } /**Get the unique array index of the string.
@return i unqArrIdx Exactly as provided to the constructor. **/ public final int getUnqArrIdx() { return iUnqArrIdx; } /**How many absolute instances (duplicates) of this unique string exist in the array?
@return[1 + the number of times incInstanceCount() was called]
**/
public final int getInstanceCount() {
return iInstances;
}
/**
Is there exactly one instance of this unique string?
@return(getInstanceCount() == 1)
**/
public boolean isSingular() {
return (getInstanceCount() == 1);
}
/**
Are there more than one instance of this unique string?
@return!isSingular()
**/
public boolean isMultiple() {
return !isSingular();
}
/**
Declare that another copy of this unique string was found in the array.
After this class is created, but before this function is called, the instance count is set to one. The first call to this function sets the instance count to two.
@exception LockedException If isLocked equals true. **/ public final void incInstanceCount() { throwLXIfLocked(isLocked(), "incInstanceCount"); iInstances++; } /**Get a full (deep) copy of this UniqueString.
**/ public final UniqueString getUSClone() { try { return (UniqueString)clone(); } catch(CloneNotSupportedException cnsx) { throwAX("getUSClone [SHOULD NEVER HAPPEN!]: " + cnsx.toString()); } //Never reached. Required for compile. return null; } /**Get a full (deep) copy of this UniqueString as an Object.
**/ protected final Object clone() throws CloneNotSupportedException { return (new UniqueString(iUnqArrIdx, iInstances, bLocked)); } private UniqueString(int i_unqArrIdx, int i_instances, boolean b_locked) { iUnqArrIdx = i_unqArrIdx; iInstances = i_instances; bLocked = b_locked; } //Required by Named...START public final String getName() { return getString(); } //Required by LockOneWay...END //Required by LockOneWay...START public final void lock() { bLocked = true; } public final boolean isLocked() { return bLocked; } //Required by LockOneWay...END }