From e6511543c07ecfd804892449e56f47a17c52fed3 Mon Sep 17 00:00:00 2001 From: Nils Bandener Date: Tue, 25 Jun 2024 00:18:41 +0200 Subject: [PATCH] Optimizations --- .../com/selectivem/check/CheckListImpl.java | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/selectivem/check/CheckListImpl.java b/src/main/java/com/selectivem/check/CheckListImpl.java index e4031c9..9a9e858 100644 --- a/src/main/java/com/selectivem/check/CheckListImpl.java +++ b/src/main/java/com/selectivem/check/CheckListImpl.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2024 Nils Bandener * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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"); @@ -48,11 +48,11 @@ static CheckList create(Set elements, String elementName) { if (size == 2) { Iterator iter = elements.iterator(); - return new CheckListImpl.TwoElementCheckList(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(elements, elementName); + return new CheckListImpl.ArrayCheckList<>(elements, elementName); } } @@ -284,9 +284,7 @@ public void uncheckIfPresent(E element) { @Override public boolean checkIf(Predicate 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--; } @@ -298,9 +296,7 @@ public boolean checkIf(Predicate checkPredicate) { @Override public void uncheckIf(Predicate 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++; } @@ -309,19 +305,13 @@ public void uncheckIf(Predicate 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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; }