org.ujoframework.criterion
Class Criterion<UJO extends Ujo>

java.lang.Object
  extended by org.ujoframework.criterion.Criterion<UJO>
Direct Known Subclasses:
BinaryCriterion, ValueCriterion

public abstract class Criterion<UJO extends Ujo>
extends java.lang.Object

An abstract immutable criterion provides a basic interface and static factory methods. You can use it:

There is allowed to join two instances (based on the same BO) to a binary tree by a new Criterion. Some common operators (and, or, not) are implemeted into a special join method of the Criteron class.

Example of use

// Make a criterion:
 Criterion<Person> crn1, crn2, criterion;
 crn1 = Criterion.where(CASH, Operator.GT, 10.0);
 crn2 = Criterion.where(CASH, Operator.LE, 20.0);
 criterion = crn1.and(crn2);

 // Use a criterion (1):
 CriteriaTool<Person> ct = CriteriaTool.where();
 List<Person> result = ct.select(persons, criterion);
 assertEquals(1, result.size());
 assertEquals(20.0, CASH.of(result.get(0)));

 // Use a criterion (2):
 Person person = result.get(0);
 boolean validation = criterion.evaluate(person);
 assertTrue(validation);
 

Using the parentheses

A Criterion instance composed from another criterions works as an expression separated by parentheses. See the next two examples:
// Consider instances:
 Criterion<Person> a, b, c, result;
 a = Criterion.where(CASH, Operator.GT, 10.0);
 b = Criterion.where(CASH, Operator.LE, 20.0);
 c = Criterion.where(NAME, Operator.STARTS, "P");

 // Expression #1: (a OR b) AND c :
 result = (a.or(b)).and(c); // or simply:
 result = a.or(b).and(c);

 // Expression #2: a AND (b OR c) :
 result = a.and(b.or(c));
 

Since:
0.90
Author:
Pavel Ponec

Constructor Summary
Criterion()
           
 
Method Summary
 Criterion<UJO> and(Criterion<UJO> criterion)
           
static
<UJO extends Ujo>
Criterion<UJO>
constant(UjoProperty<UJO,?> property, boolean constant)
          This is a special constant criterion independed on the property or the ujo entity.
abstract  boolean evaluate(UJO ujo)
           
abstract  java.lang.Object getLeftNode()
          Returns the left node of the parrent
abstract  AbstractOperator getOperator()
          Returns an operator
abstract  java.lang.Object getRightNode()
          Returns the right node of the parrent
 boolean isBinary()
          Is the class a Binary criterion?
 Criterion<UJO> join(BinaryOperator operator, Criterion<UJO> criterion)
           
static
<UJO extends Ujo>
Criterion<UJO>
newInstance(boolean value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, Operator operator, TYPE value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, Operator operator, UjoProperty<?,TYPE> value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, TYPE value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, UjoProperty<UJO,TYPE> value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo>
Criterion<UJO>
newInstanceFalse(UjoProperty<UJO,?> property)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo>
Criterion<UJO>
newInstanceTrue(UjoProperty<UJO,?> property)
          Deprecated. See the where(...) method.
 Criterion<UJO> not()
           
 Criterion<UJO> or(Criterion<UJO> criterion)
           
static
<UJO extends Ujo>
Criterion<UJO>
where(boolean value)
          This is an constane criterion independed on an entity.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, Operator operator, TYPE value)
          New criterion instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, Operator operator, UjoProperty<?,TYPE> value)
          New criterion instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, TYPE value)
          New equals instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, UjoProperty<UJO,TYPE> value)
          New equals instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereIn(UjoProperty<UJO,TYPE> property, java.util.Collection<TYPE> list)
          Create new Criterion for operator IN to compare value to a list of constants.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereIn(UjoProperty<UJO,TYPE> property, TYPE... list)
          Create new Criterion for operator IN to compare value to a list of constants
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNotIn(UjoProperty<UJO,TYPE> property, java.util.Collection<TYPE> list)
          Create new Criterion for operator IN to compare value to a list of constants.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNotIn(UjoProperty<UJO,TYPE> property, TYPE... list)
          Create new Criterion for operator IN to compare value to a list of constants.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNotNull(UjoProperty<UJO,TYPE> property)
          Criterion where property not equals to NULL.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNull(UjoProperty<UJO,TYPE> property)
          Criterion where property equals to NULL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Criterion

public Criterion()
Method Detail

evaluate

public abstract boolean evaluate(UJO ujo)

join

public Criterion<UJO> join(BinaryOperator operator,
                           Criterion<UJO> criterion)

and

public Criterion<UJO> and(Criterion<UJO> criterion)

or

public Criterion<UJO> or(Criterion<UJO> criterion)

not

public Criterion<UJO> not()

getLeftNode

public abstract java.lang.Object getLeftNode()
Returns the left node of the parrent


getRightNode

public abstract java.lang.Object getRightNode()
Returns the right node of the parrent


getOperator

public abstract AbstractOperator getOperator()
Returns an operator


isBinary

public boolean isBinary()
Is the class a Binary criterion?


where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          Operator operator,
                                                          TYPE value)
New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          Operator operator,
                                                          UjoProperty<?,TYPE> value)
New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          TYPE value)
New equals instance

Parameters:
property - UjoProperty
  • TYPE - parameter value
  • List<TYPE> - list of values
  • UjoProperty - reference to a related entity
Returns:
A the new immutable Criterion

whereIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereIn(UjoProperty<UJO,TYPE> property,
                                                            java.util.Collection<TYPE> list)
Create new Criterion for operator IN to compare value to a list of constants.

Parameters:
property - A direct or indeirect Ujo property
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be FALSE in this case.
Returns:
A the new immutable Criterion.

whereNotIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNotIn(UjoProperty<UJO,TYPE> property,
                                                               java.util.Collection<TYPE> list)
Create new Criterion for operator IN to compare value to a list of constants.

Parameters:
property - A direct or indeirect Ujo property
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be TRUE in this case.
Returns:
A the new immutable Criterion.

whereIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereIn(UjoProperty<UJO,TYPE> property,
                                                            TYPE... list)
Create new Criterion for operator IN to compare value to a list of constants

Parameters:
property - A reference to a related entity
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be FALSE in this case.
Returns:
A the new immutable Criterion

whereNotIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNotIn(UjoProperty<UJO,TYPE> property,
                                                               TYPE... list)
Create new Criterion for operator IN to compare value to a list of constants.

Parameters:
A - property direct or indeirect Ujo property
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be TRUE in this case.
Returns:
A the new immutable Criterion.

where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          UjoProperty<UJO,TYPE> value)
New equals instance

Parameters:
property - UjoProperty
value - Value or UjoProperty can be type a direct of indirect (for a relation) property
Returns:
A the new immutable Criterion

whereNull

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNull(UjoProperty<UJO,TYPE> property)
Criterion where property equals to NULL.

Parameters:
property - UjoProperty

whereNotNull

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNotNull(UjoProperty<UJO,TYPE> property)
Criterion where property not equals to NULL.

Parameters:
property - UjoProperty

where

public static <UJO extends Ujo> Criterion<UJO> where(boolean value)
This is an constane criterion independed on an entity. It is recommended not to use this solution in ORM.


constant

public static <UJO extends Ujo> Criterion<UJO> constant(UjoProperty<UJO,?> property,
                                                        boolean constant)
This is a special constant criterion independed on the property or the ujo entity. A result is the same like the parameter constant allways.

See Also:
Operator#X_FIXED

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           Operator operator,
                                                                           TYPE value)
Deprecated. See the where(...) method.

New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           Operator operator,
                                                                           UjoProperty<?,TYPE> value)
Deprecated. See the where(...) method.

New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           TYPE value)
Deprecated. See the where(...) method.

New equals instance

Parameters:
property - UjoProperty
  • TYPE - parameter value
  • List<TYPE> - list of values
  • UjoProperty - reference to a related entity
Returns:
A the new immutable Criterion

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           UjoProperty<UJO,TYPE> value)
Deprecated. See the where(...) method.

New equals instance

Parameters:
property - UjoProperty
value - Value or UjoProperty can be type a direct of indirect (for a relation) property
Returns:
A the new immutable Criterion

newInstance

@Deprecated
public static <UJO extends Ujo> Criterion<UJO> newInstance(boolean value)
Deprecated. See the where(...) method.

This is an constane criterion independed on an entity. It is recommended not to use this solution in ORM.


newInstanceTrue

@Deprecated
public static <UJO extends Ujo> Criterion<UJO> newInstanceTrue(UjoProperty<UJO,?> property)
Deprecated. See the where(...) method.

This is a constant criterion independed on the property and the ujo entity. A result is the constantTrue always.


newInstanceFalse

@Deprecated
public static <UJO extends Ujo> Criterion<UJO> newInstanceFalse(UjoProperty<UJO,?> property)
Deprecated. See the where(...) method.

This is a constant criterion independed on the property and the ujo entity. A result is the constantFalse always.

Type Parameters:
UJO -
Parameters:
property -
Returns:


Copyright © 2010. All Rights Reserved.