Skip to content

Commit

Permalink
Issue jakartaee#829 empty restriction
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rauh <[email protected]>
  • Loading branch information
njr-11 committed Jan 23, 2025
1 parent 171e940 commit fbfe515
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2025 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.metamodel.restrict;

import java.util.List;

class EmptyRestriction<T> implements CompositeRestriction<T> {
static final EmptyRestriction<?> INSTANCE = new EmptyRestriction<>();

// prevent instantiation by others
private EmptyRestriction() {
}

@Override
public boolean isNegated() {
return false;
}

@Override
public CompositeRestriction<T> negate() {
throw new UnsupportedOperationException("Empty restriction cannot be negated.");
}

@Override
public List<Restriction<T>> restrictions() {
return List.of();
}

@Override
public Type type() {
return Type.ALL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public static <T> TextRestriction<T> like(String pattern,
return new TextRestrictionRecord<>(attribute, Operator.LIKE, ESCAPED, p);
}

@SuppressWarnings("unchecked")
public static final <T> Restriction<T> none() {
return (Restriction<T>) EmptyRestriction.INSTANCE;
}

// convenience method for those who would prefer to avoid .negate()
public static <T> Restriction<T> not(Restriction<T> restriction) {
Objects.requireNonNull(restriction, "Restriction must not be null");
Expand Down

0 comments on commit fbfe515

Please sign in to comment.