33import java .util .ArrayList ;
44import java .util .List ;
55
6- import org .baeldung .persistence .model .User ;
76import org .springframework .data .jpa .domain .Specifications ;
87
98import cz .jirutka .rsql .parser .ast .ComparisonNode ;
109import cz .jirutka .rsql .parser .ast .LogicalNode ;
1110import cz .jirutka .rsql .parser .ast .LogicalOperator ;
1211import cz .jirutka .rsql .parser .ast .Node ;
1312
14- public class UserRsqlSpecBuilder {
13+ public class GenericRsqlSpecBuilder < T > {
1514
16- public Specifications <User > createSpecification (final Node node ) {
15+ public Specifications <T > createSpecification (final Node node ) {
1716 if (node instanceof LogicalNode ) {
1817 return createSpecification ((LogicalNode ) node );
1918 }
@@ -23,17 +22,17 @@ public Specifications<User> createSpecification(final Node node) {
2322 return null ;
2423 }
2524
26- public Specifications <User > createSpecification (final LogicalNode logicalNode ) {
27- final List <Specifications <User >> specs = new ArrayList <Specifications <User >>();
28- Specifications <User > temp ;
25+ public Specifications <T > createSpecification (final LogicalNode logicalNode ) {
26+ final List <Specifications <T >> specs = new ArrayList <Specifications <T >>();
27+ Specifications <T > temp ;
2928 for (final Node node : logicalNode .getChildren ()) {
3029 temp = createSpecification (node );
3130 if (temp != null ) {
3231 specs .add (temp );
3332 }
3433 }
3534
36- Specifications <User > result = specs .get (0 );
35+ Specifications <T > result = specs .get (0 );
3736
3837 if (logicalNode .getOperator () == LogicalOperator .AND ) {
3938 for (int i = 1 ; i < specs .size (); i ++) {
@@ -50,8 +49,8 @@ else if (logicalNode.getOperator() == LogicalOperator.OR) {
5049 return result ;
5150 }
5251
53- public Specifications <User > createSpecification (final ComparisonNode comparisonNode ) {
54- final Specifications <User > result = Specifications .where (new GenericRsqlSpecification <User >(comparisonNode .getSelector (), comparisonNode .getOperator (), comparisonNode .getArguments ()));
52+ public Specifications <T > createSpecification (final ComparisonNode comparisonNode ) {
53+ final Specifications <T > result = Specifications .where (new GenericRsqlSpecification <T >(comparisonNode .getSelector (), comparisonNode .getOperator (), comparisonNode .getArguments ()));
5554 return result ;
5655 }
5756
0 commit comments