@@ -32,9 +32,6 @@ public class UserSpecifications {
32
32
33
33
/**
34
34
* A {@link Specification} to match on a {@link User}'s firstname.
35
- *
36
- * @param firstname
37
- * @return
38
35
*/
39
36
public static Specification <User > userHasFirstname (final String firstname ) {
40
37
@@ -43,9 +40,6 @@ public static Specification<User> userHasFirstname(final String firstname) {
43
40
44
41
/**
45
42
* A {@link Specification} to match on a {@link User}'s lastname.
46
- *
47
- * @param firstname
48
- * @return
49
43
*/
50
44
public static Specification <User > userHasLastname (final String lastname ) {
51
45
@@ -54,27 +48,16 @@ public static Specification<User> userHasLastname(final String lastname) {
54
48
55
49
/**
56
50
* A {@link Specification} to do a like-match on a {@link User}'s firstname.
57
- *
58
- * @param firstname
59
- * @return
60
51
*/
61
52
public static Specification <User > userHasFirstnameLike (final String expression ) {
62
53
63
- return new Specification <User >() {
64
-
65
- @ Override
66
- public Predicate toPredicate (Root <User > root , CriteriaQuery <?> query , CriteriaBuilder cb ) {
67
-
68
- return cb .like (root .get ("firstname" ).as (String .class ), String .format ("%%%s%%" , expression ));
69
- }
70
- };
54
+ return (root , query , cb ) -> cb .like (root .get ("firstname" ).as (String .class ), String .format ("%%%s%%" , expression ));
71
55
}
72
56
73
57
/**
74
58
* A {@link Specification} to do an age check.
75
59
*
76
60
* @param age upper (exclusive) bound of the age
77
- * @return
78
61
*/
79
62
public static Specification <User > userHasAgeLess (final Integer age ) {
80
63
@@ -84,33 +67,19 @@ public static Specification<User> userHasAgeLess(final Integer age) {
84
67
/**
85
68
* A {@link Specification} to do a like-match on a {@link User}'s lastname but also adding a sort order on the
86
69
* firstname.
87
- *
88
- * @param firstname
89
- * @return
90
70
*/
91
71
public static Specification <User > userHasLastnameLikeWithSort (final String expression ) {
92
72
93
- return new Specification <User >() {
94
-
95
- @ Override
96
- public Predicate toPredicate (Root <User > root , CriteriaQuery <?> query , CriteriaBuilder cb ) {
73
+ return (root , query , cb ) -> {
97
74
98
- query .orderBy (cb .asc (root .get ("firstname" )));
75
+ query .orderBy (cb .asc (root .get ("firstname" )));
99
76
100
- return cb .like (root .get ("lastname" ).as (String .class ), String .format ("%%%s%%" , expression ));
101
- }
77
+ return cb .like (root .get ("lastname" ).as (String .class ), String .format ("%%%s%%" , expression ));
102
78
};
103
79
}
104
80
105
81
private static <T > Specification <T > simplePropertySpec (final String property , final Object value ) {
106
82
107
- return new Specification <T >() {
108
-
109
- @ Override
110
- public Predicate toPredicate (Root <T > root , CriteriaQuery <?> query , CriteriaBuilder builder ) {
111
-
112
- return builder .equal (root .get (property ), value );
113
- }
114
- };
83
+ return (root , query , builder ) -> builder .equal (root .get (property ), value );
115
84
}
116
85
}
0 commit comments