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;
}
@Override
public String toString() {
return getClass().getSimpleName() + " " + column;
}
}

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

@ -13,4 +13,8 @@ public class RowChecker extends DigitBlockChecker {
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;
}
@Override
public String toString() {
return getClass().getSimpleName() + " " + squareRow + "/" + squareColumn;
}
}

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

Loading…
Cancel
Save