Skip to content

Commit

Permalink
Review comments on Comparable, notEqualTo, and Operator
Browse files Browse the repository at this point in the history
  • Loading branch information
njr-11 committed Nov 21, 2024
1 parent 2b2ab75 commit d4ebd0b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
28 changes: 28 additions & 0 deletions api/src/main/java/jakarta/data/Operator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

public enum Operator {
EQUAL,
GREATER_THAN,
GREATER_THAN_EQUAL,
IN,
LESS_THAN,
LESS_THAN_EQUAL,
LIKE
}
20 changes: 9 additions & 11 deletions api/src/main/java/jakarta/data/Restrict.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.List;
import java.util.Set;

import jakarta.data.Restriction.Operator;

// TODO document
// This is one of two places from which to obtain restrictions.
// The other place is from static metamodel attributes.
Expand Down Expand Up @@ -53,9 +51,9 @@ public static <T> Restriction<T> any(Restriction<T>... restrictions) {
List.of(restrictions));
}

public static <T> Restriction<T> between(Comparable<Object> min,
Comparable<Object> max,
String field) {
public static <T, V extends Comparable<V>> Restriction<T> between(V min,
V max,
String field) {
return all(greaterThanEqual(min, field),
lessThanEqual(max, field));
}
Expand All @@ -81,15 +79,15 @@ public static <T> TextRestriction<T> equalTo(String value, String field) {
return new TextRestrictionRecord<>(field, Operator.EQUAL, value);
}

public static <T> Restriction<T> greaterThan(Comparable<Object> value, String field) {
public static <T, V extends Comparable<V>> Restriction<T> greaterThan(V value, String field) {
return new BasicRestrictionRecord<>(field, Operator.GREATER_THAN, value);
}

public static <T> TextRestriction<T> greaterThan(String value, String field) {
return new TextRestrictionRecord<>(field, Operator.GREATER_THAN, value);
}

public static <T extends Comparable<T>> Restriction<T> greaterThanEqual(T value, String field) {
public static <T, V extends Comparable<V>> Restriction<T> greaterThanEqual(V value, String field) {
return new BasicRestrictionRecord<>(field, Operator.GREATER_THAN_EQUAL, value);
}

Expand All @@ -101,15 +99,15 @@ public static <T> Restriction<T> in(Set<Object> values, String field) {
return new BasicRestrictionRecord<>(field, Operator.IN, values);
}

public static <T> Restriction<T> lessThan(Comparable<Object> value, String field) {
public static <T, V extends Comparable<V>> Restriction<T> lessThan(V value, String field) {
return new BasicRestrictionRecord<>(field, Operator.LESS_THAN, value);
}

public static <T> TextRestriction<T> lessThan(String value, String field) {
return new TextRestrictionRecord<>(field, Operator.LESS_THAN, value);
}

public static <T> Restriction<T> lessThanEqual(Comparable<Object> value, String field) {
public static <T, V extends Comparable<V>> Restriction<T> lessThanEqual(V value, String field) {
return new BasicRestrictionRecord<>(field, Operator.LESS_THAN_EQUAL, value);
}

Expand All @@ -134,11 +132,11 @@ public static <T> TextRestriction<T> like(String pattern,
return new TextRestrictionRecord<>(field, Operator.LIKE, ESCAPED, p);
}

public static <T> Restriction<T> not(Object value, String field) {
public static <T> Restriction<T> notEqualTo(Object value, String field) {
return new BasicRestrictionRecord<>(field, NOT, Operator.EQUAL, value);
}

public static <T> TextRestriction<T> not(String value, String field) {
public static <T> TextRestriction<T> notEqualTo(String value, String field) {
return new TextRestrictionRecord<>(field, NOT, Operator.EQUAL, value);
}

Expand Down
10 changes: 0 additions & 10 deletions api/src/main/java/jakarta/data/Restriction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,4 @@

public interface Restriction<T> {
boolean isNegated();

enum Operator {
EQUAL,
GREATER_THAN,
GREATER_THAN_EQUAL,
IN,
LESS_THAN,
LESS_THAN_EQUAL,
LIKE
}
}
6 changes: 3 additions & 3 deletions api/src/main/java/jakarta/data/metamodel/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ default Restriction<T> isNull() {
*/
String name();

default Restriction<T> not(Object value) {
return Restrict.not(value, name());
default Restriction<T> notEqualTo(Object value) {
return Restrict.notEqualTo(value, name());
}

default Restriction<T> notIn(Object... values) {
Expand All @@ -64,6 +64,6 @@ default Restriction<T> notIn(Object... values) {
}

default Restriction<T> notNull() {
return Restrict.not(null, name());
return Restrict.notEqualTo(null, name());
}
}
10 changes: 5 additions & 5 deletions api/src/main/java/jakarta/data/metamodel/SortableAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface SortableAttribute<T> extends Attribute<T> {
*/
Sort<T> asc();

default Restriction<T> between(Comparable<Object> min, Comparable<Object> max) {
default <V extends Comparable<V>> Restriction<T> between(V min, V max) {
return Restrict.between(min, max, name());
}

Expand All @@ -55,19 +55,19 @@ default Restriction<T> between(Comparable<Object> min, Comparable<Object> max) {
*/
Sort<T> desc();

default Restriction<T> greaterThan(Comparable<Object> value) {
default <V extends Comparable<V>> Restriction<T> greaterThan(V value) {
return Restrict.greaterThan(value, name());
}

default Restriction<T> greaterThanEqual(Comparable<Object> value) {
default <V extends Comparable<V>> Restriction<T> greaterThanEqual(V value) {
return Restrict.greaterThanEqual(value, name());
}

default Restriction<T> lessThan(Comparable<Object> value) {
default <V extends Comparable<V>> Restriction<T> lessThan(V value) {
return Restrict.lessThan(value, name());
}

default Restriction<T> lessThanEqual(Comparable<Object> value) {
default <V extends Comparable<V>> Restriction<T> lessThanEqual(V value) {
return Restrict.lessThanEqual(value, name());
}
}
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/data/metamodel/TextAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ default TextRestriction<T> like(String pattern,
return Restrict.like(pattern, charWildcard, stringWildcard, name());
}

default TextRestriction<T> not(String value) {
return Restrict.not(value, name());
default TextRestriction<T> notEqualTo(String value) {
return Restrict.notEqualTo(value, name());
}

default TextRestriction<T> notContains(String substring) {
Expand Down

0 comments on commit d4ebd0b

Please sign in to comment.