Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
nibix committed Jun 24, 2024
1 parent 11f3763 commit e651154
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/main/java/com/selectivem/check/CheckListImpl.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright 2024 Nils Bandener
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*
* Based on code which is:
*
*
* Copyright 2022-2024 floragunn GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,11 +48,11 @@ static <E> CheckList<E> create(Set<E> elements, String elementName) {

if (size == 2) {
Iterator<E> iter = elements.iterator();
return new CheckListImpl.TwoElementCheckList<E>(iter.next(), iter.next(), elementName);
return new CheckListImpl.TwoElementCheckList<>(iter.next(), iter.next(), elementName);
} else if (size >= 800) {
return new CheckListImpl.HashMapCheckList<>(elements, elementName);
} else {
return new CheckListImpl.ArrayCheckList<E>(elements, elementName);
return new CheckListImpl.ArrayCheckList<>(elements, elementName);
}
}

Expand Down Expand Up @@ -284,9 +284,7 @@ public void uncheckIfPresent(E element) {
@Override
public boolean checkIf(Predicate<E> checkPredicate) {
for (int i = 0; i < size; i++) {
E e = this.elements.indexToElement(i);

if (!this.checked[i] && checkPredicate.test(e)) {
if (!this.checked[i] && checkPredicate.test(this.elements.indexToElement(i))) {
this.checked[i] = true;
this.uncheckedCount--;
}
Expand All @@ -298,9 +296,7 @@ public boolean checkIf(Predicate<E> checkPredicate) {
@Override
public void uncheckIf(Predicate<E> checkPredicate) {
for (int i = 0; i < size; i++) {
E e = this.elements.indexToElement(i);

if (this.checked[i] && checkPredicate.test(e)) {
if (this.checked[i] && checkPredicate.test(this.elements.indexToElement(i))) {
this.checked[i] = false;
this.uncheckedCount++;
}
Expand All @@ -309,19 +305,13 @@ public void uncheckIf(Predicate<E> checkPredicate) {

@Override
public void checkAll() {
for (int i = 0; i < size; i++) {
this.checked[i] = true;
}

Arrays.fill(this.checked, true);
this.uncheckedCount = 0;
}

@Override
public void uncheckAll() {
for (int i = 0; i < size; i++) {
this.checked[i] = false;
}

Arrays.fill(this.checked, false);
this.uncheckedCount = this.size;
}

Expand Down Expand Up @@ -405,7 +395,7 @@ public E next() {
throw new NoSuchElementException();
}

E element = (E) ArrayCheckList.this.elements.indexToElement(pos);
E element = ArrayCheckList.this.elements.indexToElement(pos);
ready = false;
return element;
}
Expand Down Expand Up @@ -470,7 +460,7 @@ public E next() {
throw new NoSuchElementException();
}

E element = (E) ArrayCheckList.this.elements.indexToElement(pos);
E element = ArrayCheckList.this.elements.indexToElement(pos);
this.pos = findNext(this.pos + 1);
return element;
}
Expand Down Expand Up @@ -523,7 +513,7 @@ public E next() {
throw new NoSuchElementException();
}

E element = (E) ArrayCheckList.this.elements.indexToElement(pos);
E element = ArrayCheckList.this.elements.indexToElement(pos);
this.pos = findNext(this.pos + 1);
return element;
}
Expand Down Expand Up @@ -573,7 +563,7 @@ public E next() {
throw new NoSuchElementException();
}

E element = (E) ArrayCheckList.this.elements.indexToElement(pos);
E element = ArrayCheckList.this.elements.indexToElement(pos);
this.pos = findNext(this.pos + 1);
return element;
}
Expand Down

0 comments on commit e651154

Please sign in to comment.