Skip to content

Commit

Permalink
add getCurrentIndex method for QueryHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
nck-mlcnv committed Sep 21, 2023
1 parent 2f0d94b commit abe29cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/main/java/org/aksw/iguana/cc/query/handler/QueryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,15 @@ public QueryStreamWrapper getNextQueryStream() throws IOException {
return new QueryStreamWrapper(queryIndex, this.queryList.getQueryStream(queryIndex));
}

public QueryStreamSupplierWrapper getNextQueryStreamSupplier() {
final var queryIndex = this.querySelector.getNextIndex();
return new QueryStreamSupplierWrapper(queryIndex, () -> {
try {
return this.queryList.getQueryStream(queryIndex);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}

@Override
public int hashCode() {
return hashCode;
}

public int getCurrentQueryID() {
return this.querySelector.getCurrentIndex();
}

public int getQueryCount() {
return this.queryList.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public QuerySelector(int size) {
* @return the next query index
*/
public abstract int getNextIndex();

public abstract int getCurrentIndex();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public int getNextIndex() {
this.threadLocalIndex.set(index + 1);
return index;
}

@Override
public int getCurrentIndex() {
return threadLocalIndex.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class RandomQuerySelector extends QuerySelector {

final protected Random indexGenerator;

int currentIndex;

public RandomQuerySelector(int size, long seed) {
super(size);
Expand All @@ -23,6 +23,11 @@ public RandomQuerySelector(int size, long seed) {

@Override
public int getNextIndex() {
return this.indexGenerator.nextInt(this.size);
return currentIndex = this.indexGenerator.nextInt(this.size);
}

@Override
public int getCurrentIndex() {
return currentIndex;
}
}

0 comments on commit abe29cc

Please sign in to comment.