com.zeevbelkin.commons
Class ComparablePattern

java.lang.Object
  extended by com.zeevbelkin.commons.ComparablePattern
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<ComparablePattern>

public class ComparablePattern
extends java.lang.Object
implements java.lang.Comparable<ComparablePattern>, java.io.Serializable

This class wraps Pattern to make it comparable and serializable. Also special "compare only" instances can be created for the optimization purposes. These instances can not be used to obtain a matcher.

Author:
Zeev (Vladimir) Belkin
See Also:
Serialized Form

Constructor Summary
ComparablePattern(java.util.regex.Pattern p)
          creates a ComparablePattern instance that wrap a Pattern
ComparablePattern(java.lang.String s, boolean compareonly)
           
 
Method Summary
 int compareTo(ComparablePattern o)
          compares the objects by comparing their string representations
static ComparablePattern compile(java.lang.String s)
          creates a new ComparablePattern instance that encapsulates a Pattern instance.
 boolean equals(java.lang.Object o)
          tests the objects equality by equality of their string representations
 int hashCode()
           
 java.util.regex.Matcher matcher(java.lang.CharSequence input)
          calls the wrapped object Pattern.matcher method
 java.lang.String toString()
          returns a string from which the encapsulated pattern was compiled, or, in case if the class instance is a "compare only" object the encapsulated string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComparablePattern

public ComparablePattern(java.lang.String s,
                         boolean compareonly)
Parameters:
s - a string to be compiled to the pattern, or to be encapsulated in a case of a "compare only" object
compareonly - should be true to create a "compare only" instance

ComparablePattern

public ComparablePattern(java.util.regex.Pattern p)
creates a ComparablePattern instance that wrap a Pattern

Parameters:
p - a pattern to wrap
Method Detail

toString

public java.lang.String toString()
returns a string from which the encapsulated pattern was compiled, or, in case if the class instance is a "compare only" object the encapsulated string.

Overrides:
toString in class java.lang.Object
Returns:

compile

public static ComparablePattern compile(java.lang.String s)
creates a new ComparablePattern instance that encapsulates a Pattern instance.

Returns:
new ComparablePattern instance

equals

public boolean equals(java.lang.Object o)
tests the objects equality by equality of their string representations

Overrides:
equals in class java.lang.Object
Parameters:
o -

matcher

public java.util.regex.Matcher matcher(java.lang.CharSequence input)
calls the wrapped object Pattern.matcher method

Returns:
result of the wrapped pattern Pattern.matcher call

compareTo

public int compareTo(ComparablePattern o)
compares the objects by comparing their string representations

Specified by:
compareTo in interface java.lang.Comparable<ComparablePattern>
Parameters:
o -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object