org.teiid.metadata.index
Class CharOperation

java.lang.Object
  extended by org.teiid.metadata.index.CharOperation

public final class CharOperation
extends java.lang.Object

This class is a collection of helper methods to manipulate char arrays.

Since:
2.1

Constructor Summary
CharOperation()
           
 
Method Summary
static boolean match(char[] pattern, char[] name, boolean isCaseSensitive)
          Answers true if the pattern matches the given name, false otherwise.
static boolean prefixEquals(char[] prefix, char[] name, boolean isCaseSensitive)
          Answers true if the given name starts with the given prefix, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharOperation

public CharOperation()
Method Detail

match

public static final boolean match(char[] pattern,
                                  char[] name,
                                  boolean isCaseSensitive)
Answers true if the pattern matches the given name, false otherwise. This char[] pattern matching accepts wild-cards '*' and '?'. When not case sensitive, the pattern is assumed to already be lowercased, the name will be lowercased character per character as comparing. If name is null, the answer is false. If pattern is null, the answer is true if name is not null.

For example:
  1.     pattern = { '?', 'b', '*' }
        name = { 'a', 'b', 'c' , 'd' }
        isCaseSensitive = true
        result => true
     
  2.     pattern = { '?', 'b', '?' }
        name = { 'a', 'b', 'c' , 'd' }
        isCaseSensitive = true
        result => false
     
  3.     pattern = { 'b', '*' }
        name = { 'a', 'b', 'c' , 'd' }
        isCaseSensitive = true
        result => false
     

Parameters:
pattern - the given pattern
name - the given name
isCaseSensitive - flag to know whether or not the matching should be case sensitive
Returns:
true if the pattern matches the given name, false otherwise TODO: this code was derived from eclipse CharOperation. It also lacks the ability to specify an escape character.

prefixEquals

public static final boolean prefixEquals(char[] prefix,
                                         char[] name,
                                         boolean isCaseSensitive)
Answers true if the given name starts with the given prefix, false otherwise. isCaseSensitive is used to find out whether or not the comparison should be case sensitive.

For example:
  1.     prefix = { 'a' , 'B' }
        name = { 'a' , 'b', 'b', 'a', 'b', 'a' }
        isCaseSensitive = false
        result => true
     
  2.     prefix = { 'a' , 'B' }
        name = { 'a' , 'b', 'b', 'a', 'b', 'a' }
        isCaseSensitive = true
        result => false
     

Parameters:
prefix - the given prefix
name - the given name
isCaseSensitive - to find out whether or not the comparison should be case sensitive
Returns:
true if the given name starts with the given prefix, false otherwise
Throws:
java.lang.NullPointerException - if the given name is null or if the given prefix is null


Copyright © 2009. All Rights Reserved.