kirk.util
Class Wildcard

java.lang.Object
  |
  +--kirk.util.Wildcard

public class Wildcard
extends Object

This class represents a wildcard. You construct this class by supplying the wildcard String, and then you can use it to check whether Strings comply to the wildcard. The default values for single character checking and any amount of character checking are ? and *, but you can specify your own when constructing.

Version:
1
Author:
Berend "Kirk" Wouda

Field Summary
protected  char anyamount
          The character that indicates any amount of characters.
protected  char single
          The character that indicates any single character.
protected  String wildcard
          The wildcard this class represents.
 
Constructor Summary
Wildcard(String wildcard)
          Constructs a new Wildcard with the specified wildcard, and the default character values.
Wildcard(String wildcard, char single, char anyamount)
          Constructs a new Wildcard with the specified wildcard, and the specified character values.
 
Method Summary
 String getWildcard()
          Returns the wildcard this object represents.
 boolean test(String line)
          Returns whether the passed line complies with this Wildcard.
protected  boolean testAnyAmount(StringTokenizer tokenizer, String line, int index)
          Returns whether the passed line complies to the passed wildcard indicated by tokenizer, up to the point where a string token appears in the wildcard.
protected  boolean testSingle(StringTokenizer tokenizer, String line, int index)
          Returns whether the passed line complies to the passed wildcard indicated by tokenizer, up to the point where an anyamount token appears in the wildcard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wildcard

protected String wildcard
The wildcard this class represents.


single

protected char single
The character that indicates any single character. Its standard value is '?'.


anyamount

protected char anyamount
The character that indicates any amount of characters. Its standard value is '*'.

Constructor Detail

Wildcard

public Wildcard(String wildcard,
                char single,
                char anyamount)
Constructs a new Wildcard with the specified wildcard, and the specified character values.

Parameters:
wildcard - The wildcard that strings that are tested with this object must comply with to pass.
single - The character that specifies a single character in a wildcard.
anyamount - The character that specifies any amount of characters in a wildcard.

Wildcard

public Wildcard(String wildcard)
Constructs a new Wildcard with the specified wildcard, and the default character values.

Parameters:
wildcard - The wildcard that strings that are tested with this object must comply with to pass.
Method Detail

test

public boolean test(String line)
Returns whether the passed line complies with this Wildcard.

Parameters:
line - The line to be checked.
Returns:
true when line complies with this Wildcard.

testSingle

protected boolean testSingle(StringTokenizer tokenizer,
                             String line,
                             int index)
Returns whether the passed line complies to the passed wildcard indicated by tokenizer, up to the point where an anyamount token appears in the wildcard. This method assumes that when it is called, no any amount of characters are allowed before the next token. As soon as this is allowed, this method passes control back to the calling method, which assumes that there are any amount of characters allowed before the next token (or is the starting method). This method works recursively, for as long as it is not in anyamount "mode".

Parameters:
tokenizer - The wildcard in a StringTokenizer.
line - The line to be tested.
index - The current position into line.
Returns:
Whether the passed line complies to the passed wildcard indicated by tokenizer.

testAnyAmount

protected boolean testAnyAmount(StringTokenizer tokenizer,
                                String line,
                                int index)
Returns whether the passed line complies to the passed wildcard indicated by tokenizer, up to the point where a string token appears in the wildcard. This method assumes that when it is called, any amount of characters are allowed before the next token. As soon as this isn't allowed anymore, this method passes control back to the calling method, which assumes that there are no characters allowed before the next token. This method works recursively, for as long as it is in anyamount "mode".

Parameters:
tokenizer - The wildcard in a StringTokenizer.
line - The line to be tested.
index - The current position into line.
Returns:
Whether the passed line complies to the passed wildcard indicated by tokenizer.

getWildcard

public String getWildcard()
Returns the wildcard this object represents.

Returns:
The wildcard this object represents.