0
0
Fork 0

fixed collection of results

paul
paul 5 years ago
parent 7c7590b6f1
commit a1e7429302

@ -13,4 +13,8 @@ public class ColumnChecker extends DigitBlockChecker {
return currentColumn == column; return currentColumn == column;
} }
@Override
public String toString() {
return getClass().getSimpleName() + " " + column;
}
} }

@ -35,11 +35,12 @@ public abstract class DigitBlockChecker extends SubmissionPublisher<Boolean> imp
if (digitsProcessed.contains(digit)) { if (digitsProcessed.contains(digit)) {
submit(false); submit(false);
subscription.cancel(); subscription.cancel();
} } else {
digitsProcessed.add(digit); digitsProcessed.add(digit);
if (digitsProcessed.size() == 9) { if (digitsProcessed.size() == 9) {
submit(true); submit(true);
subscription.cancel(); subscription.cancel();
}
} }
} }
} }
@ -54,7 +55,7 @@ public abstract class DigitBlockChecker extends SubmissionPublisher<Boolean> imp
@Override @Override
public void onComplete() { public void onComplete() {
close(); // not called
} }
} }

@ -13,4 +13,8 @@ public class RowChecker extends DigitBlockChecker {
return currentRow == row; return currentRow == row;
} }
@Override
public String toString() {
return getClass().getSimpleName() + " " + row;
}
} }

@ -27,4 +27,9 @@ public class SquareChecker extends DigitBlockChecker {
return currentColumn >= fromColumn && currentColumn <= toColumn; return currentColumn >= fromColumn && currentColumn <= toColumn;
} }
@Override
public String toString() {
return getClass().getSimpleName() + " " + squareRow + "/" + squareColumn;
}
} }

@ -30,13 +30,12 @@ public class SudokuVerifier implements Flow.Subscriber<Boolean> {
} }
public boolean isSolved() { public boolean isSolved() {
int subscriberCount = digitPublisher.getSubscribers().size();
// Make publisher emit each digit // Make publisher emit each digit
digitStream.forEach(digitPublisher::submit); digitStream.forEach(digitPublisher::submit);
digitPublisher.close(); digitPublisher.close();
// Wait for checking subscribers to finish // Wait for checking subscribers to finish
int subscriberCount = digitPublisher.getSubscribers().size(); while ((finished.get() < subscriberCount) && solved.get()) {
while (true) {
if (!(finished.get() < subscriberCount && solved.get())) break;
justAMoment(); justAMoment();
} }
return solved.get(); return solved.get();
@ -74,17 +73,17 @@ public class SudokuVerifier implements Flow.Subscriber<Boolean> {
if (! solved) { if (! solved) {
this.solved.compareAndSet(true, false); this.solved.compareAndSet(true, false);
} }
finished.incrementAndGet();
} }
@Override @Override
public void onError(Throwable throwable) { public void onError(Throwable throwable) {
System.err.println(throwable.fillInStackTrace()); System.err.println(throwable.fillInStackTrace());
finished.incrementAndGet(); finished.incrementAndGet();
System.exit(1);
} }
@Override @Override
public void onComplete() { public void onComplete() {
finished.incrementAndGet(); // not called
} }
} }

Loading…
Cancel
Save