org.netbeans.modules.jellytools.platform/3 3.13

org.netbeans.jellytools.util
Class StringFilter

java.lang.Object
  extended by org.netbeans.jellytools.util.StringFilter

public class StringFilter
extends Object

Filters string, you can simple use replaceString() method or create string filter for more sophisticated filtering.

Usage:

 StringFilter sf = new StringFilter();
 // remove 1st comment
 sf.addReplaceFilter("/*",  "*/", "");
 // replace all multiple spaces
 sf.addReplaceAllFilter("  ", " ");
 // change author name
 sf.addReplaceFilter("author: ", "", "author: spl@sun.com");
 String string = "/* comment */    4s  2s   3s author: xxx@sun.com";
 String result = sf.filter(string);
 

See Also:
replaceString(String original, String begin, String end, String replace)

Constructor Summary
StringFilter()
           
 
Method Summary
 void addReplaceAllFilter(String find, String replace)
          Adds replace pattern into Filter.
 void addReplaceFilter(String begin, String end, String replace)
          Adds replace pattern into Filter.
 String filter(String str)
          Filters string.
 void filterLinesToStream(String input, PrintStream output)
          Filters input string to a PrintStream.
static String replaceString(String original, String begin, String end, String replace)
          Finds substring which starts with first occurrence of 'begin' and ends with nearest next occurrence of 'end' and replces it with 'replace '.
static String replaceStringAll(String original, String find, String replace)
          Finds and replace all substrings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringFilter

public StringFilter()
Method Detail

addReplaceFilter

public void addReplaceFilter(String begin,
                             String end,
                             String replace)
Adds replace pattern into Filter.

Parameters:
begin - the begin of substring to be find
end - the end of substring to be find
replace - text to replace
See Also:
replaceString(String original, String begin, String end, String replace )

addReplaceAllFilter

public void addReplaceAllFilter(String find,
                                String replace)
Adds replace pattern into Filter.

Parameters:
find - text to find
replace - text to replace
See Also:
replaceString(String original, String begin, String end, String replace )

filter

public String filter(String str)
Filters string.

Parameters:
str - text to filter
Returns:
filtred string

replaceString

public static String replaceString(String original,
                                   String begin,
                                   String end,
                                   String replace)
Finds substring which starts with first occurrence of 'begin' and ends with nearest next occurrence of 'end' and replces it with 'replace '.

Usage:

 replaceString("a-bcd-ef",    "b",  "d",  "")   => a--ef
 replaceString("abc-def",     "",   "c",  "")   => -def
 replaceString("ab-cdef",     "c",  "",   "")   => ab-
 replaceString("ab-cdef-ab",  "ab", "ab", "AB") => AB-cdef-AB
 replaceString("abcdef",      "",    "",  "AB") => abcdef
 

Parameters:
replace - text to replace
original - the original string
begin - the begin of substring to be find
end - the end of substring to be find
Returns:
filtred string

replaceStringAll

public static String replaceStringAll(String original,
                                      String find,
                                      String replace)
Finds and replace all substrings.

Parameters:
original - the original string
find - text to find
replace - text to replace
Returns:
filtred string
See Also:
replaceString(String original, String begin, String end, String replace)

filterLinesToStream

public void filterLinesToStream(String input,
                                PrintStream output)
Filters input string to a PrintStream.

Parameters:
input - string to be filtered
output - stream to write results in

org.netbeans.modules.jellytools.platform/3 3.13

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.