|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fest.assertions.api.filter.Filters<E>
E
- the type of element of group to filter.public class Filters<E>
Filters the elements of a given
or array according to the specified filter criteria.
Iterable
Filter criteria can be expressed either by a Condition
or a pseudo filter language on elements properties.
Note that the given Iterable
or array is not modified, the filters are performed on a copy.
With Condition
:
List<Player> players = ...; Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP"){ public boolean matches(Player player) { return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7; }; }; // use filter static method to build Filters assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose)With pseudo filter language on element properties :
assertThat(filter(players).with("pointsPerGame").greaterThan(20) .and("assistsPerGame").greaterThan(7) .get()).containsOnly(james, rose);
Method Summary | ||
---|---|---|
Filters<E> |
and(String propertyName)
Alias of with(String) for synthetic sugar to write things like :. |
|
Filters<E> |
being(Condition<E> condition)
Filter the underlying group, keeping only elements satisfying the given Condition . |
|
Filters<E> |
equalsTo(Object propertyValue)
Filters the underlying iterable to keep object with property (specified by with(String) ) equals to
given value. |
|
static
|
filter(E[] array)
Creates a new with the array to filter. |
|
static
|
filter(Iterable<E> iterable)
Creates a new with the Iterable to filter. |
|
Iterable<E> |
get()
Returns the resulting filtered Iterable<E> (even if the constructor parameter type was an array). |
|
Filters<E> |
having(Condition<E> condition)
Filter the underlying group, keeping only elements satisfying the given Condition . |
|
Filters<E> |
in(Object... propertyValues)
Filters the underlying iterable to keep object with property (specified by with(String) ) equals to
one of the given values. |
|
Filters<E> |
notEqualsTo(Object propertyValue)
Filters the underlying iterable to keep object with property (specified by with(String) ) not equals
to given value. |
|
Filters<E> |
notIn(Object... propertyValues)
Filters the underlying iterable to keep object with property (specified by with(String) ) not in the
given values. |
|
Filters<E> |
with(String propertyName)
Sets the name of the property used for filtering, it may be a nested property like "adress.street.name" . |
|
Filters<E> |
with(String propertyName,
Object propertyValue)
Filter the underlying group, keeping only elements with a property equals to given value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <E> Filters<E> filter(Iterable<E> iterable)
Filters
with the Iterable
to filter.
Chain this call to express filter criteria either by a Condition
or a pseudo filter language on elements
properties.
Note that the given Iterable
is not modified, the filters are performed on a copy.
- With Condition
:
List<Player> players = ...; Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP"){ public boolean matches(Player player) { return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7; }; }; // use filter static method to build Filters assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose)- With pseudo filter language on element properties :
assertThat(filter(players).with("pointsPerGame").greaterThan(20) .and("assistsPerGame").greaterThan(7).get()) .containsOnly(james, rose);
iterable
- the Iterable
to filter.
Filters
.
NullPointerException
- if the given iterable is null
.public static <E> Filters<E> filter(E[] array)
Filters
with the array to filter.
Chain this call to express filter criteria either by a Condition
or a pseudo filter language on elements
properties.
Note that the given array is not modified, the filters are performed on an Iterable
copy of the array.
With Condition
:
List<Player> players = ...; Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP"){ public boolean matches(Player player) { return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7; }; }; // use filter static method to build Filters assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);With pseudo filter language on element properties :
assertThat(filter(players).with("pointsPerGame").greaterThan(20) .and("assistsPerGame").greaterThan(7) .get()).containsOnly(james, rose);
array
- the array to filter.
Filters
.
NullPointerException
- if the given array is null
.public Filters<E> being(Condition<E> condition)
Condition
.having(Condition)
- pick the method you prefer to have the most readable code.
List<Player> players = ...; Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP") { public boolean matches(Player player) { return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7; }; }; // use filter static method to build Filters assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
condition
- the filter Condition
.
Filters
to chain other filter operations.
NullPointerException
- if the given condition is null
.public Filters<E> having(Condition<E> condition)
Condition
.being(Condition)
- pick the method you prefer to have the most readable code.
List<Player> players = ...; Condition<Player> mvpStats = new Condition<Player>("is a possible MVP") { public boolean matches(Player player) { return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7; }; }; // use filter static method to build Filters assertThat(filter(players).having(mvpStats).get()).containsOnly(james, rose);
condition
- the filter Condition
.
Filters
to chain other filter operations.
NullPointerException
- if the given condition is null
.public Filters<E> with(String propertyName, Object propertyValue)
Let's, for example, filter Employees with name "Alex" :
filter(employees).with("name", "Alex").get();which is shortcut of :
filter(employees).with("name").equalsTo("Alex").get();
propertyName
- the name of the property whose value will compared to given value. It may be a nested property.propertyValue
- the expected property value.
Filters
to chain other filter operations.
org.fest.util.IntrospectionError
- if an element in the given Iterable
does not have a property with a given
propertyName.
NullPointerException
- if the given propertyName is null
.public Filters<E> with(String propertyName)
"adress.street.name"
.
The typical usage is to chain this call with a comparison method, for example :
filter(employees).with("name").equalsTo("Alex").get();
propertyName
- the name of the property used for filtering. It may be a nested property.
Filters
to chain other filter operation.
NullPointerException
- if the given propertyName is null
.public Filters<E> and(String propertyName)
with(String)
for synthetic sugar to write things like :.
filter(employees).with("name").equalsTo("Alex").and("job").notEqualsTo("lawyer").get();
propertyName
- the name of the property used for filtering. It may be a nested property.
Filters
to chain other filter operation.
NullPointerException
- if the given propertyName is null
.public Filters<E> equalsTo(Object propertyValue)
with(String)
) equals to
given value.
Typical usage :
filter(employees).with("name").equalsTo("Luke").get();
propertyValue
- the filter value.
Filters
to chain other filter operation.
NullPointerException
- if the property name to filter on has not been set.public Filters<E> notEqualsTo(Object propertyValue)
with(String)
) not equals
to given value.
Typical usage :
filter(employees).with("name").notEqualsTo("Vader").get();
propertyValue
- the filter value.
Filters
to chain other filter operation.
NullPointerException
- if the property name to filter on has not been set.public Filters<E> in(Object... propertyValues)
with(String)
) equals to
one of the given values.
Typical usage :
filter(players).with("team").in("Bulls", "Lakers").get();
propertyValues
- the filter values.
Filters
to chain other filter operation.
NullPointerException
- if the property name to filter on has not been set.public Filters<E> notIn(Object... propertyValues)
with(String)
) not in the
given values.
Typical usage :
filter(players).with("team").notIn("Heat", "Lakers").get();
propertyValues
- the filter values.
Filters
to chain other filter operation.
NullPointerException
- if the property name to filter on has not been set.public Iterable<E> get()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |