O
Ossie
Note the output below. Is this a reasonable way to determine if a
phrase is
found within a collection of patterns? Is there a better way to manage
the
validation of the phrase against a collection of patterns? My fear is
this
is pretty intense way of validating the pattern of the phrase.
[omoore@skipper tmp]$ java MyExample "STK PIPE" "*PART" "this should
not qualify for exlcusion" "AA1234567890"
============================================
phrase: STK PIPE
exlclude? true
============================================
phrase: *PART
exlclude? true
============================================
phrase: this should not qualify for exlcusion
exlclude? false
============================================
phrase: AA1234567890
exlclude? true
============================================
[omoore@skipper tmp]$ cat MyExample.java
import java.util.*;
import java.util.regex.*;
public class MyExample
{
public static void main(String [] args)
{
System.out.println("============================================");
for ( int i = 0 ; i < args.length ; i++ )
{
System.out.println(" phrase: " + args );
System.out.println("exlclude? " + isPhraseInExcludeList(args) );
System.out.println("============================================");
}
}
public static void initPatternVector()
{
m_ExcludedPhraseList = new Vector(0);
//starts with 'STK '
m_ExcludedPhraseList.add("STK .*");
//starts with '*'
m_ExcludedPhraseList.add("[*].*");
//containing 'FRT'
m_ExcludedPhraseList.add(".*FRT.*");
//starts 2 upper & 6 nbrs
m_ExcludedPhraseList.add("[A-Z]{2}[0-9]{6}.*");
}
public static boolean isPhraseInExcludeList(String phrase)
{
if ( m_ExcludedPhraseList == null)
{
initPatternVector();
}
for ( int i = 0 ; i < m_ExcludedPhraseList.capacity() ; i++ )
{
String pattern = (String) m_ExcludedPhraseList.get(i);
if( Pattern.matches( pattern , phrase ) )
{
return true;
}
}
return false;
}
public static Vector m_ExcludedPhraseList;
}
[omoore@skipper tmp]$
phrase is
found within a collection of patterns? Is there a better way to manage
the
validation of the phrase against a collection of patterns? My fear is
this
is pretty intense way of validating the pattern of the phrase.
[omoore@skipper tmp]$ java MyExample "STK PIPE" "*PART" "this should
not qualify for exlcusion" "AA1234567890"
============================================
phrase: STK PIPE
exlclude? true
============================================
phrase: *PART
exlclude? true
============================================
phrase: this should not qualify for exlcusion
exlclude? false
============================================
phrase: AA1234567890
exlclude? true
============================================
[omoore@skipper tmp]$ cat MyExample.java
import java.util.*;
import java.util.regex.*;
public class MyExample
{
public static void main(String [] args)
{
System.out.println("============================================");
for ( int i = 0 ; i < args.length ; i++ )
{
System.out.println(" phrase: " + args );
System.out.println("exlclude? " + isPhraseInExcludeList(args) );
System.out.println("============================================");
}
}
public static void initPatternVector()
{
m_ExcludedPhraseList = new Vector(0);
//starts with 'STK '
m_ExcludedPhraseList.add("STK .*");
//starts with '*'
m_ExcludedPhraseList.add("[*].*");
//containing 'FRT'
m_ExcludedPhraseList.add(".*FRT.*");
//starts 2 upper & 6 nbrs
m_ExcludedPhraseList.add("[A-Z]{2}[0-9]{6}.*");
}
public static boolean isPhraseInExcludeList(String phrase)
{
if ( m_ExcludedPhraseList == null)
{
initPatternVector();
}
for ( int i = 0 ; i < m_ExcludedPhraseList.capacity() ; i++ )
{
String pattern = (String) m_ExcludedPhraseList.get(i);
if( Pattern.matches( pattern , phrase ) )
{
return true;
}
}
return false;
}
public static Vector m_ExcludedPhraseList;
}
[omoore@skipper tmp]$