com.nearform.patrun
Class Patrun

java.lang.Object
  extended by com.nearform.patrun.Patrun

public class Patrun
extends Object

Package patrun is a fast pattern matcher on Go map properties For a full guide visit https://github.com/colmharte/patrun-java Need to pick out an object based on a subset of its properties? Say you've got: { x: 1 } -> A { x: 1, y: 1 } -> B { x: 1, y: 2 } -> C Then patrun can give you the following results: { x: 1 } -> A { x: 2 } -> no match { x: 1, y: 1 } -> B { x: 1, y: 2 } -> C { x: 2, y: 2 } -> no match { y: 1 } -> no match It's basically _query-by-example_ for property sets.


Constructor Summary
Patrun()
           
Patrun(Customiser custom)
          Constructor taking a customiser object to allow the add / find / remove method results to be customised
 
Method Summary
 Patrun add(Map<String,String> pat, Object data)
          Register a pattern, and the object that will be returned if an input matches.
 Patrun add(String pat, Object data)
          Register a pattern, and the object that will be returned if an input matches.
 Object find(Map<String,String> pat)
          Return the unique match for this subject, or null if not found.
 Object find(Map<String,String> pat, Boolean exact)
          Return the unique match for this subject, or null if not found.
 Object find(String pat)
          Return the unique match for this subject, or null if not found.
 Object find(String pat, Boolean exact)
          Return the unique match for this subject, or null if not found.
 Vector<Pattern> list()
          Return the list of all registered patterns.
 Vector<Pattern> list(Map<String,String> pat)
          Return the list of registered patterns that contain this partial pattern.
 Vector<Pattern> list(Map<String,String> pat, Boolean exact)
          Return the list of registered patterns that contain this partial pattern.
 Vector<Pattern> list(String pat)
          Return the list of registered patterns that contain this partial pattern.
 Vector<Pattern> list(String pat, Boolean exact)
          Return the list of registered patterns that contain this partial pattern.
 void remove(Map<String,String> pat)
          Remove this pattern, and it's object, from the matcher.
 void remove(String pat)
          Remove this pattern, and it's object, from the matcher.
 String toString()
          Generate a string representation of the decision tree for debugging.
 String toString(Printer printer)
          Generate a string representation of the decision tree for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Patrun

public Patrun()

Patrun

public Patrun(Customiser custom)
Constructor taking a customiser object to allow the add / find / remove method results to be customised

Parameters:
custom - an instance of the Customiser interface
Method Detail

add

public Patrun add(Map<String,String> pat,
                  Object data)
Register a pattern, and the object that will be returned if an input matches.

Parameters:
pat - a map of the pattern
data - the data to store for this pattern
Returns:
a reference to this to allow chaining of add calls

add

public Patrun add(String pat,
                  Object data)
Register a pattern, and the object that will be returned if an input matches.

Parameters:
pat - a string defintiion of the pattern takes the form key:value,key:value eg "a:1,b:2"
data - the data to store for this pattern
Returns:
a reference to this to allow chaining of add calls

find

public Object find(Map<String,String> pat,
                   Boolean exact)
Return the unique match for this subject, or null if not found. The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins. Unknown properties in the subject are ignored. If exact is set to true then all properties of a pattern must match. exact defaults to false.

Parameters:
pat - a map of the pattern to look for
exact - set to true if the match must exactly match the pattern
Returns:
the data stored against the matching pattern or null if no match

find

public Object find(Map<String,String> pat)
Return the unique match for this subject, or null if not found. The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins. Unknown properties in the subject are ignored.

Parameters:
pat - a Map representation of the pattern to look for
Returns:
the data stored against the matching pattern or null if no match

find

public Object find(String pat)
Return the unique match for this subject, or null if not found. The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins. Unknown properties in the subject are ignored.

Parameters:
pat - a string representation of the pattern to look for
Returns:
the data stored against the matching pattern or null if no match

find

public Object find(String pat,
                   Boolean exact)
Return the unique match for this subject, or null if not found. The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins. Unknown properties in the subject are ignored.

Parameters:
pat - a string representation of the pattern to look for
exact - set to true if the match must exactly match the pattern
Returns:
the data stored against the matching pattern or null if no match

remove

public void remove(Map<String,String> pat)
Remove this pattern, and it's object, from the matcher.

Parameters:
pat - a Map representation of the pattern to remove

remove

public void remove(String pat)
Remove this pattern, and it's object, from the matcher.

Parameters:
pat - a String representation of the pattern to remove

list

public Vector<Pattern> list(Map<String,String> pat,
                            Boolean exact)
Return the list of registered patterns that contain this partial pattern. You can use wildcards for property values. Omitted values are *not* equivalent to a wildcard of _"*"_, you must specify each property explicitly. You can provide a second boolean parameter, _exact_. If true, then only those patterns matching the pattern-partial exactly are returned.

Parameters:
pat - a Map representation of the pattern to match
exact - set to true if the match must exactly match the pattern
Returns:
a Vector of matched Patterns

list

public Vector<Pattern> list()
Return the list of all registered patterns.

Returns:
a Vector of matched Patterns

list

public Vector<Pattern> list(Map<String,String> pat)
Return the list of registered patterns that contain this partial pattern. You can use wildcards for property values. Omitted values are *not* equivalent to a wildcard of _"*"_, you must specify each property explicitly.

Parameters:
pat - a Map representation of the pattern to match
Returns:
a Vector of matched Patterns

list

public Vector<Pattern> list(String pat)
Return the list of registered patterns that contain this partial pattern. You can use wildcards for property values. Omitted values are *not* equivalent to a wildcard of _"*"_, you must specify each property explicitly.

Parameters:
pat - a String representation of the pattern to match
Returns:
a Vector of matched Patterns

list

public Vector<Pattern> list(String pat,
                            Boolean exact)
Return the list of registered patterns that contain this partial pattern. You can use wildcards for property values. Omitted values are *not* equivalent to a wildcard of _"*"_, you must specify each property explicitly. You can provide a second boolean parameter, _exact_. If true, then only those patterns matching the pattern-partial exactly are returned.

Parameters:
pat - a String representation of the pattern to match
exact - set to true if the match must exactly match the pattern
Returns:
a Vector of matched Patterns

toString

public String toString()
Generate a string representation of the decision tree for debugging.

Overrides:
toString in class Object
Returns:
a String representation of the decision tree

toString

public String toString(Printer printer)
Generate a string representation of the decision tree for debugging.

Parameters:
printer - an object i9mplementing the Printer interface to allow for customising the string representation of the data objects
Returns:
a String representation of the decision tree


Copyright © 2015. All rights reserved.