/* 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.util.LockOneWay; import xbn.util.Utility; import java.util.Hashtable; /**
Convenience class for creating an AOSLookup. See AOSLookup.
Source code: AOSLCreator.java. Example code See the source code for UtilArray.getAOSLFromPA.
Create an AOSLCreator with default values.
Equal to AOSLCreator(true)
Create an AOSLCreator.
Equal to AOSLCreator(b_dupStrsOk, -1)
Create an AOSLCreator.
Equal to AOSLCreator(true, -1)
Create an AOSLCreator.
Equal to AOSLCreator(b_dupStrsOk, i_unqStrCount, true)
Create an AOSLCreator.
Equal to AOSLCreator(b_dupStrsOk, -1, b_listStrsOnError)
Create an AOSLCreator.
Equal to AOSLCreator(true, i_unqStrCount, b_listStrsOnError)
Create an AOSLCreator.
@param b_dupStrsOk Are duplicate strings acceptable? If true, then yes. If false, no. See areDupStringsOk and addString. @param i_unqStrCount How many unique strings will exist in the AOSLookup (will be added via addString)? If -1, then the number of unique strings is not known. Otherwise, may not be less than one. See getUnqStrCount and addString. @param b_listStrsOnError Should the list of strings be printed in any error messages thrown? If true, then yes. If false, no. See doListStrsOnError. **/ public AOSLCreator(boolean b_dupStrsOk, int i_unqStrCount, boolean b_listStrsOnError) { if(i_unqStrCount != -1 && i_unqStrCount < 1) { throwAX("constructor: i_unqStrCount (" + i_unqStrCount + ") must equal -1 (indicating the number of unique strings is unknown) or be greater than zero."); } if(i_unqStrCount > 0) { ht = new Hashtable(i_unqStrCount, 1); } else { ht = new Hashtable(); } bDupStringsOk = b_dupStrsOk; iUnqStrCount = i_unqStrCount; bListStrsOnError = b_listStrsOnError; acoUnique = new VWObject(); acoAbsolute = new VWObject(); } /**Are duplicate strings okay?
@return b_dupStrsOk Exactly as provided to the constructor. **/ public final boolean areDupStringsOk() { return bDupStringsOk; } /**Is it known how many unique strings will be provided?
@return i_unqStrCount Exactly as provided to the constructor. **/ public final int getUnqStrCount() { return iUnqStrCount; } /**In the case of an error, should the list of strings be presented in the error message?
This setting, when getAOSLookup is called, is provided directly to the AOSLookup constructor.
@return b_listStrsOnError Exactly as provided to the constructor. **/ public final boolean doListStrsOnError() { return bListStrsOnError; } /**Add a new string to the AOSLookup.
It is expected strings are added in the same order in which they originally existed. The first string exists at absolute array index zero, the second at array index one, and so on.
@param s_tr The string @exception LockedException If isLocked equals true. This means all strings have been added. @exception AssertException If...Was the string-just-added unique?
@return true If the string just added is not equal to any string added before it (or is the first).How many unique strings have been added?. See addString.
**/ public final int getCountUnq() { return acoUnique.size(); } /**How many total strings have been added?. See addString.
**/ public final int getCountAbs() { return acoAbsolute.size(); } /**Get the AOSLookup.
**/ public final AOSLookup getAOSLookup() { throwLXIfUnlocked(isLocked(), "getAOSLookup"); return aosl; } //Required by LockOneWay...START public final void lock() { throwLXIfLocked(isLocked(), "lock"); if(ht.size() < 1) { throwAX("lock: Must call addString at least once."); } AOSLHashtable aoslh = null; UniqueStringAP usapAbsolute = null; UniqueStringAP usapUnique = null; if(getUnqStrCount() == -1) { aoslh = new AOSLHashtable((new Utility()).getOptimizedHT(ht), bFALSE_IN_PRODUCTION); } else if(getCountUnq() != getUnqStrCount()) { throwAX("getAOSLookup: getCountUnq() (" + getCountUnq() + ") is less than the getUnqStrCount() (" + getUnqStrCount() + ")"); } else { //The size was provided to us at construction, //so the Hashtable was optimized to begin with. aoslh = new AOSLHashtable(ht, bFALSE_IN_PRODUCTION); } ht = null; //Create the absolute-to-unique map. Object[] ao = acoAbsolute.getAOObject(); UniqueString[] aUsmd = new UniqueString[ao.length]; for(int i = 0; i < aUsmd.length; i++) { aUsmd[i] = (UniqueString)ao[i]; } usapAbsolute = (new UniqueStringAP(aUsmd)); //Create the unique array. ao = acoUnique.getAOObject(); aUsmd = new UniqueString[ao.length]; for(int i = 0; i < aUsmd.length; i++) { aUsmd[i] = (UniqueString)ao[i]; } usapUnique = (new UniqueStringAP(aUsmd)); aosl = new AOSLookup(aoslh, usapUnique, usapAbsolute, bFALSE_IN_PRODUCTION, doListStrsOnError()); bLocked = true; } public final boolean isLocked() { return bLocked; } //Required by LockOneWay...END }