Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Reusable Analysis
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
Reusable Analysis
Commits
d6611357
Commit
d6611357
authored
5 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
extract helper class to own aspect
parent
2184c802
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
reusablecfg/src/main/jastadd/IdentityTupleSet.jadd
+102
-0
102 additions, 0 deletions
reusablecfg/src/main/jastadd/IdentityTupleSet.jadd
with
102 additions
and
0 deletions
reusablecfg/src/main/jastadd/IdentityTupleSet.jadd
0 → 100644
+
102
−
0
View file @
d6611357
aspect IdentityTupleSet {
/**
* Set that contains either one or two unique objects. The objects are
* compared with reference equality.
*/
class IdentityTupleSet<E> implements Set<E> {
final E a, b;
public IdentityTupleSet(E a, E b) {
this.a = a;
this.b = b;
}
@Override
public boolean add(E e) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> e) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean contains(Object o) {
return o == a || o == b;
}
@Override
public boolean containsAll(Collection<?> c) {
for (Object o : c) {
if (!contains(o)) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
return a.hashCode() + b.hashCode();
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public Iterator<E> iterator() {
return new Iterator<E>() {
int index = 0;
@Override
public boolean hasNext() {
return (a == b && index < 1)
|| (a != b && index < 2);
}
@Override
public E next() {
return ++index == 1 ? a : b;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
return a == b ? 1 : 2;
}
@Override
public Object[] toArray() {
return new Object[] { a, b };
}
@Override
public <T> T[] toArray(T[] array) {
array[0] = (T) a;
array[1] = (T) b;
return array;
}
@Override
public String toString() {
if (a == b) {
return "[" + a + "]";
} else {
return "[" + a + ", " + b + "]";
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment