@@ -32,9 +32,6 @@ public class UserSpecifications {
3232
3333 /**
3434 * A {@link Specification} to match on a {@link User}'s firstname.
35- *
36- * @param firstname
37- * @return
3835 */
3936 public static Specification <User > userHasFirstname (final String firstname ) {
4037
@@ -43,9 +40,6 @@ public static Specification<User> userHasFirstname(final String firstname) {
4340
4441 /**
4542 * A {@link Specification} to match on a {@link User}'s lastname.
46- *
47- * @param firstname
48- * @return
4943 */
5044 public static Specification <User > userHasLastname (final String lastname ) {
5145
@@ -54,27 +48,16 @@ public static Specification<User> userHasLastname(final String lastname) {
5448
5549 /**
5650 * A {@link Specification} to do a like-match on a {@link User}'s firstname.
57- *
58- * @param firstname
59- * @return
6051 */
6152 public static Specification <User > userHasFirstnameLike (final String expression ) {
6253
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 ));
7155 }
7256
7357 /**
7458 * A {@link Specification} to do an age check.
7559 *
7660 * @param age upper (exclusive) bound of the age
77- * @return
7861 */
7962 public static Specification <User > userHasAgeLess (final Integer age ) {
8063
@@ -84,33 +67,19 @@ public static Specification<User> userHasAgeLess(final Integer age) {
8467 /**
8568 * A {@link Specification} to do a like-match on a {@link User}'s lastname but also adding a sort order on the
8669 * firstname.
87- *
88- * @param firstname
89- * @return
9070 */
9171 public static Specification <User > userHasLastnameLikeWithSort (final String expression ) {
9272
93- return new Specification <User >() {
94-
95- @ Override
96- public Predicate toPredicate (Root <User > root , CriteriaQuery <?> query , CriteriaBuilder cb ) {
73+ return (root , query , cb ) -> {
9774
98- query .orderBy (cb .asc (root .get ("firstname" )));
75+ query .orderBy (cb .asc (root .get ("firstname" )));
9976
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 ));
10278 };
10379 }
10480
10581 private static <T > Specification <T > simplePropertySpec (final String property , final Object value ) {
10682
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 );
11584 }
11685}
0 commit comments