KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openidex > search > SearchPattern


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2005 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openidex.search;
21
22 /**
23  * Pattern describes the search conditions
24  *
25  * @since org.openidex.util/3 3.5, NB 4.1
26  * @author Martin Roskanin
27  */

28 public final class SearchPattern {
29
30     /** SearchExpression - a text to search */
31     private String JavaDoc searchExpression;
32
33     /** if true, only whole words were searched */
34     private boolean wholeWords;
35
36     /** if true, case sensitive search was preformed */
37     private boolean matchCase;
38
39     /** if true, regular expression search was performed */
40     private boolean regExp;
41
42     /** Creates a new instance of SearchPattern
43      * @param searchExpression a searched text
44      * @param wholeWords if true, only whole words were searched
45      * @param matchCase if true, case sensitive search was preformed
46      * @param regExp if true, regular expression search was performed
47      */

48     private SearchPattern(String JavaDoc searchExpression, boolean wholeWords,
49             boolean matchCase, boolean regExp) {
50         this.searchExpression = searchExpression;
51         this.wholeWords = wholeWords;
52         this.matchCase = matchCase;
53         this.regExp = regExp;
54     }
55  
56     /** Creates a new SearchPattern in accordance with given parameters
57      * @param searchExpression non-null String of a searched text
58      * @param wholeWords if true, only whole words were searched
59      * @param matchCase if true, case sensitive search was preformed
60      * @param regExp if true, regular expression search was performed
61      * @return a new SearchPattern in accordance with given parameters
62      */

63     public static SearchPattern create(String JavaDoc searchExpression, boolean wholeWords,
64             boolean matchCase, boolean regExp){
65         return new SearchPattern(searchExpression, wholeWords, matchCase, regExp);
66     }
67     
68     /** @return searchExpression */
69     public String JavaDoc getSearchExpression(){
70         return searchExpression;
71     }
72     
73     /** @return true if the wholeWords parameter was used during search performing */
74     public boolean isWholeWords(){
75         return wholeWords;
76     }
77     
78     /** @return true if the matchCase parameter was used during search performing */
79     public boolean isMatchCase(){
80         return matchCase;
81     }
82     
83     /** @return true if the regExp parameter was used during search performing */
84     public boolean isRegExp(){
85         return regExp;
86     }
87
88     public boolean equals(Object JavaDoc obj){
89         if (!(obj instanceof SearchPattern)){
90             return false;
91         }
92         SearchPattern sp = (SearchPattern)obj;
93         return (this.searchExpression.equals(sp.getSearchExpression()) &&
94                 this.wholeWords == sp.isWholeWords() &&
95                 this.matchCase == sp.isMatchCase() &&
96                 this.regExp == sp.isRegExp());
97     }
98     
99     public int hashCode() {
100         int result = 17;
101         result = 37*result + (this.wholeWords ? 1:0);
102         result = 37*result + (this.matchCase ? 1:0);
103         result = 37*result + (this.regExp ? 1:0);
104         result = 37*result + this.searchExpression.hashCode();
105         return result;
106     }
107 }
108
Popular Tags