-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add OR operator to QuerySpec constraints #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||
| /*- | ||||||||||||||||||||||||||||
| * #%L | ||||||||||||||||||||||||||||
| * Commons Backend - Model | ||||||||||||||||||||||||||||
| * %% | ||||||||||||||||||||||||||||
| * Copyright (C) 2020 - 2026 Flowing Code | ||||||||||||||||||||||||||||
| * %% | ||||||||||||||||||||||||||||
| * 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. | ||||||||||||||||||||||||||||
| * #L% | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| package com.flowingcode.backendcore.model.constraints; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import com.flowingcode.backendcore.model.Constraint; | ||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||
| import java.util.Objects; | ||||||||||||||||||||||||||||
| import lombok.AccessLevel; | ||||||||||||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||||||||||||
| import lombok.NonNull; | ||||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||
| import lombok.experimental.FieldDefaults; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** A constraint that is satisfied when any of its member constraints is satisfied (logical OR). */ | ||||||||||||||||||||||||||||
| @Getter | ||||||||||||||||||||||||||||
| @RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||||||||||||||||||||||||||||
| @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||||||||||||||||||||||||||||
| public final class DisjunctionConstraint implements Constraint { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @NonNull List<Constraint> constraints; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public static DisjunctionConstraint of(Constraint first, Constraint... rest) { | ||||||||||||||||||||||||||||
| List<Constraint> list = new java.util.ArrayList<>(); | ||||||||||||||||||||||||||||
| list.add(Objects.requireNonNull(first, "constraint must not be null")); | ||||||||||||||||||||||||||||
| for (Constraint c : rest) { | ||||||||||||||||||||||||||||
| list.add(Objects.requireNonNull(c, "constraint must not be null")); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an explicit null check for varargs container.
Suggested patch public static DisjunctionConstraint of(Constraint first, Constraint... rest) {
+ Objects.requireNonNull(rest, "constraints must not be null");
List<Constraint> list = new java.util.ArrayList<>();
list.add(Objects.requireNonNull(first, "constraint must not be null"));
for (Constraint c : rest) {
list.add(Objects.requireNonNull(c, "constraint must not be null"));
}
return new DisjunctionConstraint(List.copyOf(list));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| return new DisjunctionConstraint(List.copyOf(list)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle explicit
nullvarargs defensively inor(...).Line 43 assumes
restis non-null. A call likeor(x, (Constraint[]) null)throws an NPE inprepend(...)before constraint-level null validation runs.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents