org.gcube.data.trees.patterns
Class Patterns

java.lang.Object
  extended by org.gcube.data.trees.patterns.Patterns

public class Patterns
extends Object

Defines a simple EDSL for Patterns and other related facilities.

Author:
Fabio Simeoni

Field Summary
static QName any
          A wildcard for labels.
static AnyValue anyval
          The null constraint.
static boolean C
          A marker for condition edges.
 
Constructor Summary
Patterns()
           
 
Method Summary
static After after(Calendar c)
          Returns a After constraint for a given calendar.
static AfterDate afterDate(Date d)
          Returns an AfterDate constraint for a given date.
static
<T> All<T>
all(Constraint<T> constraint1, Constraint<T> constraint2)
          Returns an All constraint that combines two or more Constraints.
static AnyPattern any()
          The AnyPattern.
static AtLeastPattern atleast(QName label, Pattern pattern)
          Returns an AtLeastPattern for a given label and a given Pattern.
static AtLeastPattern atleast(String label, Pattern pattern)
          Returns an AtLeastPattern for a given label and a given Pattern.
static Before before(Calendar c)
          Returns a Before constraint for a given calendar.
static BeforeDate before(Date d)
          Returns a BeforeDate constraint for a given date.
static BoolPattern bool()
          Returns an unconstrained BoolPattern predicate.
static BoolPattern bool(Constraint<? super Boolean> c)
          Returns a BoolPattern with a given constraint.
static CalendarPattern calendar()
          Returns an unconstrained CalendarPattern.
static CalendarPattern calendar(Constraint<? super Calendar> c)
          Returns a CalendarPatternwith a given constraint.
static EdgePattern clone(EdgePattern pattern)
          Clones an EdgePattern.
static Pattern clone(Pattern pattern)
          Clones a Pattern.
static EdgePattern cond(EdgePattern p)
          Marks an EdgePattern as a condition.
static CutTreePattern cut(TreePattern pattern)
          Returns a CutTreePattern with the EdgePatterns of a given TreePattern but removes all the edges of a matching node under pruning
static DatePattern date()
          Returns an unconstrained DatePattern.
static DatePattern date(Constraint<? super Date> c)
          Returns a DatePattern with a given constraint.
static
<T> Either<T>
either(Constraint<T> constraint1, Constraint<T> constraint2)
          Returns an Either constraint that combines two or more Constraints.
static After future()
          Returns an After constraint for the current date.
static AfterDate futureDate()
          Returns an AfterDate constraint for the current date.
static Marshaller getMarshaller()
          Returns a Marshaller for Patterns.
static Unmarshaller getUnMarshaller()
          Returns an Unmarshaller for Patterns.
static TreePattern hasLabelPath(QName... labels)
          Returns a TreePattern that matches InnerNodes with a path of one or more edge labels.
static TreePattern hasLabelPath(String... labels)
          Returns a TreePattern that matches InnerNodes with a path of one or more edge labels.
static Pattern hasPath(String... ids)
          Returns a Pattern that matches InnerNodes with a path of one or more node identifiers.
static
<T extends AbstractPattern>
T
id(LeafPattern<?,?> idp, T p)
          Adds a LeafPattern over the identifier of nodes matched by an AbstractPattern.
static
<T extends AbstractPattern>
T
id(String identifier, T pattern)
          Adds a LeafPattern for text equality over the identifier of nodes matched by a AbstractPattern.
static
<T> Same<T>
is(T v)
          Returns a Same constraint for a given value.
static Less less(double than)
          Returns a Less constraint for a given value.
static ManyPattern many(QName label, Pattern pattern)
          Returns a ManyPattern for a given label and a given Pattern.
static ManyPattern many(String label, Pattern pattern)
          Returns a ManyPattern for a given label and a given Pattern.
static Match matches(String regex)
          Returns a Match constraint for a given regular expression.
static More more(double than)
          Returns a More constraint for a given value.
static
<T> Not<T>
not(Constraint<T> constraint)
          Returns an Not constraint for a given constraint.
static NumPattern num()
          Returns an unconstrained NumPattern.
static NumPattern num(Constraint<? super Double> c)
          Returns a NumPattern with a given constraint.
static OnePattern one(QName label, Pattern pattern)
          Returns a OnePattern for a given label and a given Pattern.
static OnePattern one(String label, Pattern pattern)
          Returns a OnePattern for a given label and a given Pattern.
static OnlyPattern only(QName label, Pattern pattern)
          Returns an OnlyPattern for a given label and a given Pattern.
static OnlyPattern only(String label, Pattern pattern)
          Returns an OnlyPattern for a given label and a given Pattern.
static OptPattern opt(QName label, Pattern pattern)
          Returns an OptPattern for a given label and a given Pattern.
static OptPattern opt(String label, Pattern pattern)
          Returns an OptPattern for a given label and a given Pattern.
static Before past()
          Returns an Before constraint for the current date.
static BeforeDate pastDate()
          Returns a BeforeDate constraint for the current date.
static ManyPattern tail()
          Returns a ManyPattern that matches all the children of a node not previously matched by the EdgePatterns of a TreePattern.
static TextPattern text()
          Returns an unconstrained TextPattern.
static TextPattern text(Constraint<? super String> constraint)
          Returns a TextPattern with a given constraint.
static TreePattern tree(EdgePattern... patterns)
          Returns a TreePattern with one or more EdgePatterns.
static URIPattern uri()
          Returns an unconstrained URIPattern.
static URIPattern uri(Constraint<? super URI> c)
          Returns a URIPattern with a given constraint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

any

public static final QName any
A wildcard for labels.


C

public static final boolean C
A marker for condition edges.

See Also:
Constant Field Values

anyval

public static final AnyValue anyval
The null constraint.

Constructor Detail

Patterns

public Patterns()
Method Detail

getMarshaller

public static Marshaller getMarshaller()
                                throws JAXBException
Returns a Marshaller for Patterns.

Returns:
the Marshaller
Throws:
JAXBException - if the Marshaller could not be returned.

getUnMarshaller

public static Unmarshaller getUnMarshaller()
                                    throws JAXBException
Returns an Unmarshaller for Patterns.

Returns:
the Unmarshaller
Throws:
JAXBException - if the Unmarshaller could not be returned.

any

public static final AnyPattern any()
The AnyPattern.


clone

public static final Pattern clone(Pattern pattern)
                           throws Exception
Clones a Pattern.

Parameters:
pattern - the pattern to clone
Returns:
the pattern's clone
Throws:
Exception - if the pattern could not be cloned

clone

public static final EdgePattern clone(EdgePattern pattern)
                               throws Exception
Clones an EdgePattern.

Parameters:
pattern - the pattern to clone
Returns:
the pattern's clone
Throws:
Exception - if the pattern could not be cloned

tree

public static final TreePattern tree(EdgePattern... patterns)
Returns a TreePattern with one or more EdgePatterns.

Parameters:
patterns - the EdgePatterns
Returns:
the TreePattern

hasPath

public static final Pattern hasPath(String... ids)
                             throws IllegalArgumentException
Returns a Pattern that matches InnerNodes with a path of one or more node identifiers.

Parameters:
ids - the identifiers
Returns:
the pattern
Throws:
IllegalArgumentException - if it is invoked with null or no input

hasLabelPath

public static final TreePattern hasLabelPath(String... labels)
                                      throws IllegalArgumentException
Returns a TreePattern that matches InnerNodes with a path of one or more edge labels.

Parameters:
labels - the local names of the labels.
Returns:
the pattern.
Throws:
IllegalArgumentException - if it is invoked with null or no input.

hasLabelPath

public static final TreePattern hasLabelPath(QName... labels)
                                      throws IllegalArgumentException
Returns a TreePattern that matches InnerNodes with a path of one or more edge labels.

Parameters:
labels - the local names of the labels.
Returns:
the pattern.
Throws:
IllegalArgumentException - if it is invoked with null or no input.

cond

public static EdgePattern cond(EdgePattern p)
Marks an EdgePattern as a condition.

Parameters:
p - the pattern
Returns:
the pattern

id

public static final <T extends AbstractPattern> T id(LeafPattern<?,?> idp,
                                                     T p)
Adds a LeafPattern over the identifier of nodes matched by an AbstractPattern.

Parameters:
idp - the LeafPattern
p - the AbstractPattern
Returns:
the AbstractPattern obtained from the original AbstractPattern by adding the LeafPattern

id

public static final <T extends AbstractPattern> T id(String identifier,
                                                     T pattern)
Adds a LeafPattern for text equality over the identifier of nodes matched by a AbstractPattern.

Parameters:
identifier - the string to compare with node identifiers
pattern - the AbstractPattern
Returns:
the AbstractPattern obtained from the original TreePattern by adding the AbstractPattern

one

public static final OnePattern one(QName label,
                                   Pattern pattern)
Returns a OnePattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the pattern
Returns:
the OnePattern

one

public static final OnePattern one(String label,
                                   Pattern pattern)
Returns a OnePattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the pattern
Returns:
the OnePattern

opt

public static final OptPattern opt(QName label,
                                   Pattern pattern)
Returns an OptPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the pattern
Returns:
the OptPattern

opt

public static final OptPattern opt(String label,
                                   Pattern pattern)
Returns an OptPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the pattern
Returns:
the OptPattern

atleast

public static final AtLeastPattern atleast(QName label,
                                           Pattern pattern)
Returns an AtLeastPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the Pattern
Returns:
the AtLeastPattern

atleast

public static final AtLeastPattern atleast(String label,
                                           Pattern pattern)
Returns an AtLeastPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the Pattern
Returns:
the AtLeastPattern

many

public static final ManyPattern many(QName label,
                                     Pattern pattern)
Returns a ManyPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the Pattern.
Returns:
the ManyPattern.

many

public static final ManyPattern many(String label,
                                     Pattern pattern)
Returns a ManyPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the Pattern.
Returns:
the ManyPattern.

only

public static final OnlyPattern only(QName label,
                                     Pattern pattern)
Returns an OnlyPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the Pattern
Returns:
the OnlyPattern

only

public static final OnlyPattern only(String label,
                                     Pattern pattern)
Returns an OnlyPattern for a given label and a given Pattern.

Parameters:
label - the label
pattern - the Pattern
Returns:
the OnlyPattern

tail

public static ManyPattern tail()
Returns a ManyPattern that matches all the children of a node not previously matched by the EdgePatterns of a TreePattern.

Returns:
the pattern

cut

public static CutTreePattern cut(TreePattern pattern)
Returns a CutTreePattern with the EdgePatterns of a given TreePattern but removes all the edges of a matching node under pruning

Parameters:
pattern - the Pattern
Returns:
the CutTreePattern

text

public static TextPattern text(Constraint<? super String> constraint)
Returns a TextPattern with a given constraint.

Parameters:
constraint - the constraint
Returns:
the TextPattern

text

public static TextPattern text()
Returns an unconstrained TextPattern.

Returns:
the TextPattern

num

public static NumPattern num(Constraint<? super Double> c)
Returns a NumPattern with a given constraint.

Parameters:
c - the constraint
Returns:
the NumPattern

num

public static NumPattern num()
Returns an unconstrained NumPattern.

Returns:
the NumPattern

bool

public static BoolPattern bool(Constraint<? super Boolean> c)
Returns a BoolPattern with a given constraint.

Parameters:
c - the constraint
Returns:
the BoolPattern

bool

public static BoolPattern bool()
Returns an unconstrained BoolPattern predicate.

Returns:
the BoolPattern

date

public static DatePattern date(Constraint<? super Date> c)
Returns a DatePattern with a given constraint.

Parameters:
c - the constraint
Returns:
the DatePattern

date

public static DatePattern date()
Returns an unconstrained DatePattern.

Returns:
the DatePattern

uri

public static URIPattern uri(Constraint<? super URI> c)
Returns a URIPattern with a given constraint.

Parameters:
c - the constraint
Returns:
the URIPattern

uri

public static URIPattern uri()
Returns an unconstrained URIPattern.

Returns:
the URIPattern

calendar

public static CalendarPattern calendar(Constraint<? super Calendar> c)
Returns a CalendarPatternwith a given constraint.

Parameters:
c - the constraint
Returns:
the CalendarPattern

calendar

public static CalendarPattern calendar()
Returns an unconstrained CalendarPattern.

Returns:
the CalendarPattern

is

public static <T> Same<T> is(T v)
Returns a Same constraint for a given value.

Parameters:
v - the value
Returns:
the constraint

matches

public static Match matches(String regex)
Returns a Match constraint for a given regular expression.

Parameters:
regex - the expression
Returns:
the constraint

all

public static <T> All<T> all(Constraint<T> constraint1,
                             Constraint<T> constraint2)
Returns an All constraint that combines two or more Constraints.

Type Parameters:
T - the type of constrained values
Parameters:
constraint1 - the first constraint
constraint2 - the second constraint
Returns:
the All constraint

either

public static <T> Either<T> either(Constraint<T> constraint1,
                                   Constraint<T> constraint2)
Returns an Either constraint that combines two or more Constraints.

Type Parameters:
T - the type of constrained values
Parameters:
constraint1 - the first constraint
constraint2 - the second constraint
Returns:
the Either constraint

not

public static <T> Not<T> not(Constraint<T> constraint)
Returns an Not constraint for a given constraint.

Type Parameters:
T - the type of constrained values
Parameters:
constraint - the constraint
Returns:
the Not constraint

more

public static More more(double than)
Returns a More constraint for a given value.

Parameters:
than - the value
Returns:
the constraint

less

public static Less less(double than)
Returns a Less constraint for a given value.

Parameters:
than - the value
Returns:
the constraint

before

public static BeforeDate before(Date d)
Returns a BeforeDate constraint for a given date.

Parameters:
d - the date
Returns:
the constraint

afterDate

public static AfterDate afterDate(Date d)
Returns an AfterDate constraint for a given date.

Parameters:
d - the date
Returns:
the constraint

futureDate

public static AfterDate futureDate()
Returns an AfterDate constraint for the current date.

Returns:
the constraint

pastDate

public static BeforeDate pastDate()
Returns a BeforeDate constraint for the current date.

Returns:
the constraint.

before

public static Before before(Calendar c)
Returns a Before constraint for a given calendar.

Parameters:
c - the calendar
Returns:
the constraint

after

public static After after(Calendar c)
Returns a After constraint for a given calendar.

Parameters:
c - the calendar
Returns:
the constraint

future

public static After future()
Returns an After constraint for the current date.

Returns:
the constraint

past

public static Before past()
Returns an Before constraint for the current date.

Returns:
the constraint


Copyright © 2012. All Rights Reserved.