Skip to content

Commit 6e64d78

Browse files
committed
finish off javadoc for Restriction and Range
1 parent 142d969 commit 6e64d78

File tree

2 files changed

+267
-0
lines changed

2 files changed

+267
-0
lines changed

hibernate-core/src/main/java/org/hibernate/query/range/Range.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @param <U> The type of the value being restricted
2323
*
2424
* @see org.hibernate.query.restriction.Restriction
25+
* @see org.hibernate.query.restriction.Restriction#restrict(jakarta.persistence.metamodel.SingularAttribute, Range)
2526
*
2627
* @author Gavin King
2728
*
@@ -30,6 +31,9 @@
3031
@Incubating
3132
public interface Range<U> {
3233

34+
/**
35+
* The Java class of the values belonging to this range.
36+
*/
3337
Class<? extends U> getType();
3438

3539
/**
@@ -40,92 +44,189 @@ public interface Range<U> {
4044
@Internal
4145
Predicate toPredicate(Path<? extends U> path, CriteriaBuilder builder);
4246

47+
/**
48+
* A range containing a single value.
49+
*/
4350
static <U> Range<U> singleValue(U value) {
4451
return new Value<>( value );
4552
}
4653

54+
/**
55+
* A range containing all strings which are equal to the given string,
56+
* ignoring case.
57+
*/
4758
static Range<String> singleCaseInsensitiveValue(String value) {
4859
return new CaseInsensitiveValue( value );
4960
}
5061

62+
/**
63+
* A range containing all values belonging to the given list.
64+
*/
5165
static <U> Range<U> valueList(List<U> values) {
5266
return new ValueList<>( values );
5367
}
5468

69+
/**
70+
* A range containing all values strictly greater than the given
71+
* lower bound.
72+
*/
5573
static <U extends Comparable<U>> Range<U> greaterThan(U bound) {
5674
return new LowerBound<>( bound, true );
5775
}
5876

77+
/**
78+
* A range containing all values greater than or equal to the given
79+
* lower bound.
80+
*/
5981
static <U extends Comparable<U>> Range<U> greaterThanOrEqualTo(U bound) {
6082
return new LowerBound<>( bound, false );
6183
}
6284

85+
/**
86+
* A range containing all values strictly less than the given
87+
* upper bound.
88+
*/
6389
static <U extends Comparable<U>> Range<U> lessThan(U bound) {
6490
return new UpperBound<>( bound, true );
6591
}
6692

93+
/**
94+
* A range containing all values less than or equal to the given
95+
* upper bound.
96+
*/
6797
static <U extends Comparable<U>> Range<U> lessThanOrEqualTo(U bound) {
6898
return new UpperBound<>( bound, false );
6999
}
70100

101+
/**
102+
* An open range containing all values strictly greater than the
103+
* given lower bound, and strictly less than the given upper bound.
104+
*/
71105
static <U extends Comparable<U>> Range<U> open(U lowerBound, U upperBound) {
72106
return new Interval<>( new LowerBound<>( lowerBound, true ),
73107
new UpperBound<>( upperBound, true ) );
74108
}
75109

110+
/**
111+
* A closed range containing all values greater than or equal to the
112+
* given lower bound, and less than or equal to the given upper bound.
113+
*/
76114
static <U extends Comparable<U>> Range<U> closed(U lowerBound, U upperBound) {
77115
return new Interval<>( new LowerBound<>( lowerBound, false ),
78116
new UpperBound<>( upperBound, false ) );
79117
}
80118

119+
/**
120+
* A range containing all strings which match the given pattern,
121+
* with case-sensitivity specified explicitly. The pattern must
122+
* be expressed in terms of the default wildcard characters
123+
* {@code _} and {@code %}.
124+
*
125+
* @param pattern A pattern involving the default wildcard characters
126+
* @param caseSensitive {@code true} if matching is case-sensitive
127+
*/
81128
static Range<String> pattern(String pattern, boolean caseSensitive) {
82129
return new Pattern( pattern, caseSensitive );
83130
}
84131

132+
/**
133+
* A range containing all strings which match the given pattern,
134+
* with case-sensitivity specified explicitly. The pattern must
135+
* be expressed in terms of the given single-character and
136+
* multi-character wildcards.
137+
*
138+
* @param pattern A pattern involving the given wildcard characters
139+
* @param caseSensitive {@code true} if matching is case-sensitive
140+
* @param charWildcard A wildcard character which matches any single character
141+
* @param stringWildcard A wildcard character which matches any string of characters
142+
*/
85143
static Range<String> pattern(String pattern, boolean caseSensitive, char charWildcard, char stringWildcard) {
86144
return new Pattern( pattern, caseSensitive, charWildcard, stringWildcard );
87145
}
88146

147+
/**
148+
* A range containing all strings which match the given pattern,
149+
* with case-sensitivity. The pattern must be expressed in terms
150+
* of the default wildcard characters {@code _} and {@code %}.
151+
*/
89152
static Range<String> pattern(String pattern) {
90153
return pattern( pattern, true );
91154
}
92155

156+
/**
157+
* A range containing all strings which begin with the given prefix,
158+
* with case-sensitivity specified explicitly.
159+
*/
93160
static Range<String> prefix(String prefix, boolean caseSensitive) {
94161
return pattern( escape( prefix ) + '%', caseSensitive );
95162
}
96163

164+
/**
165+
* A range containing all strings which end with the given suffix,
166+
* with case-sensitivity specified explicitly.
167+
*/
97168
static Range<String> suffix(String suffix, boolean caseSensitive) {
98169
return pattern( '%' + escape( suffix ), caseSensitive );
99170
}
100171

172+
/**
173+
* A range containing all strings which contain the given substring,
174+
* with case-sensitivity specified explicitly.
175+
*/
101176
static Range<String> containing(String substring, boolean caseSensitive) {
102177
return pattern( '%' + escape( substring ) + '%', caseSensitive );
103178
}
104179

180+
/**
181+
* A range containing all strings which begin with the given prefix,
182+
* with case-sensitivity.
183+
*/
105184
static Range<String> prefix(String prefix) {
106185
return prefix( prefix, true );
107186
}
108187

188+
/**
189+
* A range containing all strings which end with the given suffix,
190+
* with case-sensitivity.
191+
*/
109192
static Range<String> suffix(String suffix) {
110193
return pattern( suffix, true );
111194
}
112195

196+
/**
197+
* A range containing all strings which contain the given substring,
198+
* with case-sensitivity.
199+
*/
113200
static Range<String> containing(String substring) {
114201
return pattern( substring, true );
115202
}
116203

204+
/**
205+
* An empty range containing no values.
206+
*/
117207
static <U> Range<U> empty(Class<U> type) {
118208
return new EmptyRange<>( type );
119209
}
120210

211+
/**
212+
* A complete range containing all values of the given type.
213+
*/
121214
static <U> Range<U> full(Class<U> type) {
122215
return new FullRange<>( type );
123216
}
124217

218+
/**
219+
* A range containing all allowed values of the given type
220+
* except {@code null}.
221+
*/
125222
static <U> Range<U> notNull(Class<U> type) {
126223
return new NotNull<>( type );
127224
}
128225

226+
/**
227+
* Escape occurrences of the default wildcard characters in the
228+
* given literal string.
229+
*/
129230
private static String escape(String literal) {
130231
final var result = new StringBuilder();
131232
for ( int i = 0; i < literal.length(); i++ ) {

0 commit comments

Comments
 (0)