Skip to content

Commit 4884913

Browse files
committed
code cleanup
1 parent 5d588a7 commit 4884913

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

  • core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/ArrayBindingSet.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ private int getIndex(String bindingName) {
185185

186186
@Override
187187
public Set<String> getBindingNames() {
188+
if (isEmpty()) {
189+
return Collections.emptySet();
190+
}
191+
188192
if (bindingNamesSetCache == null) {
189193
int size = size();
190194
if (size == 0) {
@@ -213,6 +217,10 @@ public Set<String> getBindingNames() {
213217

214218
@Override
215219
public Value getValue(String bindingName) {
220+
if (isEmpty()) {
221+
return null;
222+
}
223+
216224
for (int i = 0; i < bindingNames.length; i++) {
217225
if (bindingNames[i] == bindingName && whichBindingsHaveBeenSet[i]) {
218226
return values[i];
@@ -229,6 +237,10 @@ public Value getValue(String bindingName) {
229237

230238
@Override
231239
public Binding getBinding(String bindingName) {
240+
if (isEmpty()) {
241+
return null;
242+
}
243+
232244
Value value = getValue(bindingName);
233245

234246
if (value != null) {
@@ -240,6 +252,10 @@ public Binding getBinding(String bindingName) {
240252

241253
@Override
242254
public boolean hasBinding(String bindingName) {
255+
if (isEmpty()) {
256+
return false;
257+
}
258+
243259
int index = getIndex(bindingName);
244260
if (index == -1) {
245261
return false;
@@ -249,6 +265,10 @@ public boolean hasBinding(String bindingName) {
249265

250266
@Override
251267
public Iterator<Binding> iterator() {
268+
if (isEmpty()) {
269+
return Collections.emptyIterator();
270+
}
271+
252272
return new ArrayBindingSetIterator();
253273
}
254274

@@ -257,6 +277,7 @@ public int size() {
257277
if (isEmpty()) {
258278
return 0;
259279
}
280+
260281
int size = 0;
261282

262283
for (boolean value : whichBindingsHaveBeenSet) {
@@ -271,6 +292,7 @@ public int size() {
271292
List<String> sortedBindingNames = null;
272293

273294
public List<String> getSortedBindingNames() {
295+
274296
if (sortedBindingNames == null) {
275297
int size = size();
276298

@@ -350,21 +372,6 @@ public void setBinding(String name, Value value) {
350372

351373
@Override
352374
public boolean isEmpty() {
353-
if (empty) {
354-
for (boolean b : whichBindingsHaveBeenSet) {
355-
if (b) {
356-
assert false : "empty should be false";
357-
}
358-
}
359-
} else {
360-
var tempEmpty = true;
361-
for (boolean b : whichBindingsHaveBeenSet) {
362-
if (b) {
363-
tempEmpty = false;
364-
}
365-
}
366-
assert tempEmpty == empty;
367-
}
368375
return empty;
369376
}
370377

0 commit comments

Comments
 (0)