001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 2005 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.openidex.search;
043:
044: /**
045: * Pattern describes the search conditions
046: *
047: * @since org.openidex.util/3 3.5, NB 4.1
048: * @author Martin Roskanin
049: */
050: public final class SearchPattern {
051:
052: /** SearchExpression - a text to search */
053: private String searchExpression;
054:
055: /** if true, only whole words were searched */
056: private boolean wholeWords;
057:
058: /** if true, case sensitive search was preformed */
059: private boolean matchCase;
060:
061: /** if true, regular expression search was performed */
062: private boolean regExp;
063:
064: /** Creates a new instance of SearchPattern
065: * @param searchExpression a searched text
066: * @param wholeWords if true, only whole words were searched
067: * @param matchCase if true, case sensitive search was preformed
068: * @param regExp if true, regular expression search was performed
069: */
070: private SearchPattern(String searchExpression, boolean wholeWords,
071: boolean matchCase, boolean regExp) {
072: this .searchExpression = searchExpression;
073: this .wholeWords = wholeWords;
074: this .matchCase = matchCase;
075: this .regExp = regExp;
076: }
077:
078: /** Creates a new SearchPattern in accordance with given parameters
079: * @param searchExpression non-null String of a searched text
080: * @param wholeWords if true, only whole words were searched
081: * @param matchCase if true, case sensitive search was preformed
082: * @param regExp if true, regular expression search was performed
083: * @return a new SearchPattern in accordance with given parameters
084: */
085: public static SearchPattern create(String searchExpression,
086: boolean wholeWords, boolean matchCase, boolean regExp) {
087: return new SearchPattern(searchExpression, wholeWords,
088: matchCase, regExp);
089: }
090:
091: /** @return searchExpression */
092: public String getSearchExpression() {
093: return searchExpression;
094: }
095:
096: /** @return true if the wholeWords parameter was used during search performing */
097: public boolean isWholeWords() {
098: return wholeWords;
099: }
100:
101: /** @return true if the matchCase parameter was used during search performing */
102: public boolean isMatchCase() {
103: return matchCase;
104: }
105:
106: /** @return true if the regExp parameter was used during search performing */
107: public boolean isRegExp() {
108: return regExp;
109: }
110:
111: public boolean equals(Object obj) {
112: if (!(obj instanceof SearchPattern)) {
113: return false;
114: }
115: SearchPattern sp = (SearchPattern) obj;
116: return (this .searchExpression.equals(sp.getSearchExpression())
117: && this .wholeWords == sp.isWholeWords()
118: && this .matchCase == sp.isMatchCase() && this .regExp == sp
119: .isRegExp());
120: }
121:
122: public int hashCode() {
123: int result = 17;
124: result = 37 * result + (this .wholeWords ? 1 : 0);
125: result = 37 * result + (this .matchCase ? 1 : 0);
126: result = 37 * result + (this .regExp ? 1 : 0);
127: result = 37 * result + this.searchExpression.hashCode();
128: return result;
129: }
130: }
|