/* 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.template; import xbn.XBNObject; import xbn.array.APString; import xbn.array.AOSLookup; import xbn.array.AOSLHashtable; import xbn.array.CACExact; import xbn.array.CompareArrays; import xbn.array.UtilArray; import xbn.array.primitive.PASString; import xbn.array.primitive.PARSStrict; /**

The configuration for a TemplateOrderedGaps. See TemplateOrderedGaps.

Source code:  OGConfig.java.

Specifically, this is used as a TFilter, to enforce which gap names exist in a Template.

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class OGConfig extends XBNObject implements TFilter { private APString aps = null; private AOSLookup aosl = null; private boolean bDupGapsAllowed = false; /**

Create a TemplateOrderedGaps.

Equal to OGConfig(ms_rdrdGaps, -1)

**/ public OGConfig(String[] as_uniqueGapNames) { this(as_uniqueGapNames, -1); } /**

Create a TemplateOrderedGaps.

Equal to OGConfig(ms_rdrdGaps, i_rqdUnqGapCount, true)

**/ public OGConfig(String[] as_uniqueGapNames, int i_rqdUnqGapCount) { this(as_uniqueGapNames, i_rqdUnqGapCount, true); } /**

Create a TemplateOrderedGaps.

Equal to OGConfig(ms_rdrdGaps, -1, b_dupGapsAllowed)

**/ public OGConfig(String[] as_uniqueGapNames, boolean b_dupGapsAllowed) { this(as_uniqueGapNames, -1, b_dupGapsAllowed); } /**

Create a TemplateOrderedGaps.

@param as_uniqueGapNames The list of unique gap names expected to exist in the Template. May not be null. @param i_rqdUnqGapCount The number of gaps expected to be in as_uniqueGapNames. If you don't care how many gaps are in as_uniqueGapNames, set this to -1. Otherwise, this must be greater than zero. @param b_dupGapsAllowed If true, then each unique gap may be duplicated any number of times. If false, then each unique gap must only exist once. **/ public OGConfig(String[] as_uniqueGapNames, int i_rqdUnqGapCount, boolean b_dupGapsAllowed) { PARSStrict parss = (new PARSStrict()); PASString pass = new PASString(as_uniqueGapNames, parss); pass.crashIfBad("xbn.template.OGConfig.constructor", "as_uniqueGapNames"); aosl = (new UtilArray()).getAOSLFromAOS(as_uniqueGapNames, true); aps = new APString(as_uniqueGapNames, true); if(i_rqdUnqGapCount == 0 || i_rqdUnqGapCount < -1) { throwAX("constructor: i_rqdUnqGapCount must equal -1, or be greater than or equal to one. When -1, the length of as_uniqueGapNames does not matter.."); } if(i_rqdUnqGapCount != -1 && as_uniqueGapNames.length != i_rqdUnqGapCount) { throwAX("constructor: i_rqdUnqGapCount does not equal -1, but as_uniqueGapNames.length does not equal i_rqdUnqGapCount. Currently, i_rqdUnqGapCount=" + i_rqdUnqGapCount + " and as_uniqueGapNames.length=" + as_uniqueGapNames.length + "."); } bDupGapsAllowed = b_dupGapsAllowed; } /**

Are duplicate gaps allowed?

@return b_dupGapsAllowed, exactly as provided in the constructor. **/ public boolean areDupGapsAllowed() { return bDupGapsAllowed; } /**

Get the AOSLookup for direct manipulation.

**/ public final AOSLookup getAOSLookup() { return aosl; } public final AOSLHashtable getAOSLHashtable() { return getAOSLookup().getAOSLHashtable(); } public final APString getAPString() { return aps; } /**

Get the string existing at the requested array index.

@param i_dx The requested array index. **/ public String getString(int i_dx) { return getAPString().getString(i_dx); } /**

Get the array index at which the provided string exists.

@return getAOSLHashtable().getUniqueString(s_tr).getUnqArrIdx() **/ public int getArrIdx(String s_tr) { return getAOSLHashtable().getUniqueString(s_tr).getUnqArrIdx(); } /**

How many strings exist in the string array?

**/ public int getLength() { return getAPString().getLength(); } /**

Is the provided Template legal?

@param t_emplate The Template to analyze. May not be null. @return true
false **/ public boolean isTemplateValid(Template t_emplate) { throwAXIfNull(t_emplate, "t_emplate", "isTemplateValid"); CompareArrays ca = new CompareArrays(new CACExact()); ca.setAssumePAsValid(true); boolean b = ca.hasRqdValues(t_emplate.getUSAPUnique().getUniqueStringPAS(), getAPString().getPASString()); if(!b) { return false; } //The template has exactly correct set of gap names. if(areDupGapsAllowed()) { //There may or may not be duplicate gaps. Either //way, it's legal. return true; } //Duplicate gaps are not allowed. //If the absolute gap count is not equal to the unique gap //count, return false. Otherwise, return true. return (t_emplate.getUSAPAbsolute().getLength() == t_emplate.getUSAPUnique().getLength()); } /**

Get some information about this OGConfig.

**/ public String toString() { return super.toString() + ", areDupGapsAllowed()=" + areDupGapsAllowed() + ", getAPString().getPASString()=['" + getAPString().getPASString().getList("', '") + "']"; } }