Skip to content

Commit 3ebf12a

Browse files
committed
not higher order function added
1 parent b284e2e commit 3ebf12a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/java/com/github/ozayduman/specificationbuilder/SpecificationOperator.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,15 @@ static SpecificationOperator le(){
122122
*/
123123
static SpecificationOperator in(){
124124
return (From<?,?> from, CriteriaBuilder cb,SingularAttribute attribute, Comparable[] values) ->
125-
from.in(values);
125+
from.get(attribute.getName()).in(values);
126126
}
127127

128128
/**
129129
* Represents not in function
130130
* @return {@link SpecificationOperator}
131131
*/
132132
static SpecificationOperator notIn(){
133-
return (From<?,?> from, CriteriaBuilder cb,SingularAttribute attribute, Comparable[] values) ->
134-
from.in(values).not();
133+
return not(in());
135134
}
136135

137136
/**
@@ -185,4 +184,14 @@ static SpecificationOperator like(){
185184
static SpecificationOperator notLike(){
186185
return (from, cb, attribute, values) -> cb.notLike(from.get(attribute.getName()), String.format("%%%s%%", values[0]));
187186
}
187+
188+
/** Represents a Higher Order Function that inverts a given {@code SpecificationOperator}
189+
* @param operator is a Specification operator
190+
* @return {@Link SpecificationOperator}
191+
*/
192+
static SpecificationOperator not(SpecificationOperator operator){
193+
return operator == null
194+
? (from, cb, attribute, values) -> null
195+
: (from, cb, attribute, values) -> cb.not(operator.apply(from, cb, attribute, values));
196+
}
188197
}

0 commit comments

Comments
 (0)