-
Notifications
You must be signed in to change notification settings - Fork 4
feat(and-constraint): allow more than two children #24
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
Open
JuliaCoolia
wants to merge
8
commits into
main
Choose a base branch
from
issue-19
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c2ec8b
feat(and-constraint): allow more than two children
a7daa3a
feat: added getLeft and getRight for backwards compatibility
d5155b7
fix: implemented OrConstraint like AndConstraint allowing multiple ch…
ccd4b14
fix: throw ParseError in getLeft/getRight, also added setLeft/setRigh…
c4506eb
style: fix indentation
dee7d9d
fix: resolved merge conflict between issue-19 branch and main
c6cdc8e
refactor: replaced MultiOr with Or, also returning the actual list in…
295f842
fix: resolved merge conflict
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 0 additions & 99 deletions
99
src/main/java/de/vill/model/constraint/MultiOrConstraint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,99 +0,0 @@ | ||
| package de.vill.model.constraint; | ||
|
|
||
| import de.vill.model.building.AutomaticBrackets; | ||
| import de.vill.model.building.VariableReference; | ||
| import de.vill.util.ConstantSymbols; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
|
|
||
| public class MultiOrConstraint extends Constraint{ | ||
|
|
||
| private List<Constraint> sub_parts; | ||
|
|
||
| public MultiOrConstraint() { | ||
| sub_parts = new LinkedList<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(boolean withSubmodels, String currentAlias) { | ||
| StringBuilder result = new StringBuilder(); | ||
| for (Constraint part : sub_parts) { | ||
| result.append(AutomaticBrackets.enforceConstraintBracketsIfNecessary(this, part, withSubmodels, currentAlias)); | ||
| result.append(" "+ ConstantSymbols.OR + " "); | ||
| } | ||
| result.delete(result.length() -3, result.length()); | ||
| return result.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Constraint> getConstraintSubParts() { | ||
| return sub_parts; | ||
| } | ||
|
|
||
| public void add_sub_part(Constraint constraint) { | ||
| sub_parts.add(constraint); | ||
| } | ||
|
|
||
| @Override | ||
| public void replaceConstraintSubPart(Constraint oldSubConstraint, Constraint newSubConstraint) { | ||
| for (int i=0;i<sub_parts.size();i++) { | ||
| if (sub_parts.get(i) == oldSubConstraint) { | ||
| sub_parts.set(i, newSubConstraint); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Constraint clone() { | ||
| MultiOrConstraint multiOrConstraint = new MultiOrConstraint(); | ||
| for (Constraint part : sub_parts) { | ||
| multiOrConstraint.add_sub_part(part.clone()); | ||
| } | ||
| return multiOrConstraint; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode(int level) { | ||
| final int prime = 31; | ||
| int result = 1; | ||
| for (Constraint part : sub_parts) { | ||
| result = prime * result + part.hashCode(1 + level); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| MultiOrConstraint other = (MultiOrConstraint) obj; | ||
|
|
||
| if (this.sub_parts.size() != other.sub_parts.size()) { | ||
| return false; | ||
| } | ||
| boolean same = true; | ||
| for (int i=0;i<sub_parts.size();i++) { | ||
| if (sub_parts.get(i) != other.sub_parts.get(i)) { | ||
| same = false; | ||
| break; | ||
| } | ||
| } | ||
| return same; | ||
| } | ||
|
|
||
| @Override | ||
| public List<VariableReference> getReferences() { | ||
| List<VariableReference> references = new ArrayList<>(); | ||
| for (int i=0;i<sub_parts.size();i++) { | ||
| references.addAll(sub_parts.get(i).getReferences()); | ||
| } | ||
| return references; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For backwards compatibility, it may make sense to leave those and make them return the first and last element of the list respectively (same behavior as before when using the left/right constructor)