|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.cafesoft.core.field.StringFieldValuePattern
StringFieldValuePattern implements a pattern for matching
String values. This class supports String patterns of the following form:
NOTE:A pattern that contains multiple wildcard characters such as *abc*def* are illegal. If a pattern contains two wildcard characters those wildcard characters must be at the start and at the end of the pattern.
| Constructor Summary | |
StringFieldValuePattern(String pattern,
boolean matchCase)
Create a new StringFieldValuePattern. |
|
| Method Summary | |
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one. |
String |
getPattern()
Get a String representation of the pattern. |
int |
hashCode()
Get the hashCode of the StringFieldValuePattern object. |
boolean |
matchCase()
Determine if this pattern matches case. |
boolean |
matches(Object fieldValue)
Check for a field value match against this FieldValuePattern. |
BigDecimal |
score()
Get the score of the FieldValuePattern. |
String |
toString()
Returns a string representation of the object. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public StringFieldValuePattern(String pattern,
boolean matchCase)
throws InvalidPatternException
pattern - the String representation of the pattern, which may
have any of the following forms:
matchCase - if true, then pattern matching is case sensitive,
else the match is done case insensitively.
InvalidPatternException - if pattern contains multiple wildcards
that do not bookend the expected pattern. Therefore, the
only valid pattern that contains multiple wildcards is *| Method Detail |
public boolean matches(Object fieldValue)
Algorithm for matching strings:
matches in interface FieldValuePatternfieldValue - the field value.
public String getPattern()
getPattern in interface FieldValuePatternpublic boolean matchCase()
public BigDecimal score()
The FieldValuePattern's score is a value that determines how specific a particular a pattern is. For instance, a StringFieldValuePattern needs to know which pattern "*" or "abc" is more specific. This method allows scores a pattern. The absolute implementation of the score method is implementation specific.
The score for a StringFieldValuePattern is calculated using the following algorithm.
Therefore, applying these rules to the following list of String yields
the following results:
| Pattern | Match Case | Score | How did we get that score. |
|
* |
false | -0.25 | 1.00 - 1.25 = -0.25 |
| * | true | -0.25 | 1.00 - 1.25 = -0.25 |
| null | false | 0.00 | null scores 0.00 |
| null | true | 0.00 | null scores 0.00 |
| empty string | false | 0.01 | 0.00 + 0.01 = 0.01 |
| empty string | true | 0.02 | 0.00 + 0.01 + 0.01 = 0.02 |
| *b* | false | 0.51 | 3.00 - 1.25 - 1.25 + 0.01 = 0.51 |
| *b* | true | 0.52 | 3.00 - 1.25 - 1.25 + 0.01 + 0.01= 0.52 |
| b | false | 1.01 | 1.00 + 0.01 = 1.01 |
| b | true | 1.02 | 1.00 + 0.01 + 0.01 = 1.02 |
| *bc | false | 1.76 | 3.00 - 1.25 + 0.01 = 1.76 |
| *bc | true | 1.77 | 3.00 - 1.25 + 0.01 + 0.01 = 1.77 |
| a*c | false | 1.76 | 3.00 - 1.25 + 0.01 = 1.76 |
| a*c | true | 1.77 | 3.00 - 1.25 + 0.01 + 0.01 = 1.77 |
| ab* | false | 1.76 | 3.00 - 1.25 + 0.01 = 1.76 |
| ab* | true | 1.77 | 3.00 - 1.25 + 0.01 + 0.01 = 1.77 |
| ab | false | 2.01 | 2.00 + 0.01 = 2.01 |
| ab | true | 2.02 | 2.00 + 0.01 + 0.01 = 2.02 |
| abc | false | 3.01 | 3.00 + 0.01 = 3.01 |
| abc | true | 3.02 | 3.00 + 0.01 + 0.01 = 3.02 |
score in interface FieldValuePatternpublic int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectobj - the reference object with which to compare.
public String toString()
toString in class Object
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||