All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.util.BYPStringPattern Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.util;


//------------------------------------------------------------------------------
/**
 Baeza-Yates, Perleberg string matching pattern object.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class BYPStringPattern { private String mPattern; private int mMaxMismatches = 0; private boolean mCaseInsensitive; //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- /** Creates a new Baeza-Yates, Perleberg string matching pattern. Use when mismatches are allowed but there is no ambiguity within positions or range specifications. * @param inValue the search (query) string */ public BYPStringPattern(String inValue) { mPattern = inValue; if (null == mPattern || 0 == mPattern.length()) { throw new RuntimeException("No search pattern specified!"); } else if (mPattern.length() > 128) { throw new RuntimeException("The pattern cannot be longer that 128 characters!"); } } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public boolean isCaseInsensitive() { return mCaseInsensitive; } //--------------------------------------------------------------------------- public BYPStringPattern setCaseInsensitive(boolean inValue) { mCaseInsensitive = inValue; return this; } //--------------------------------------------------------------------------- public BYPStringPattern setMaxMismatches(int inValue) { if (inValue >= mPattern.length()) { throw new RuntimeException("The number of allowed mismatches cannot be greater or equal to the pattern length!"); } mMaxMismatches = inValue; return this; } //--------------------------------------------------------------------------- public int getMaxMismatches() { return mMaxMismatches; } //--------------------------------------------------------------------------- public String getPatternString() { return mPattern; } //--------------------------------------------------------------------------- public int length() { return mPattern.length(); } //--------------------------------------------------------------------------- public BYPStringMatcher matcher(String inTargetString) { return new BYPStringMatcher(this, inTargetString); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy