throw new IllegalStateException("Unable to identify screen because previous screen "
+ previousScreen + " has no nextScreens parameter");
}
}
Screen match = null;
// Try to perform and exact match on the screen we were last on -- it's the
// most likely one to match, of course!
if (previousScreen != null) {
if (checkForExactMatch(image, previousScreen)) {
// This screen matches
log.trace("Exact match on previous screen {}", previousScreen);
match = previousScreen;
}
}
// Try to find an exact match for the screens, based on the primary pixels
// only
if (match == null) {
for (Screen screen : possibleScreens) {
if (checkForExactMatch(image, screen)) {
// This screen matches
if (log.isDebugEnabled()) {
if (match == null) {
log.trace("Exact match on new screen {}", screen);
} else {
log.warn(
"More that one screen matched! Matched screen {}, but have already matched {}",
screen, match);
}
}
match = screen;
// If not running in debug mode, we can skip the rest of the loop for
// efficiency
if (!log.isDebugEnabled())
break;
}
}
}
if (match == null) {
// A check of the primary pixels did not find an exact match, so try for a
// partial match
log.debug("Did not find exact screen match, attempting partial match");
Map<Screen, PartialResult> screenMatchesMap = new HashMap<>();
int maxMatchedCount = 0;
int maxUnmatchedCount = 0;
Screen bestMatch = null;
EnumSet<Screen> possibleScreensIncludingPrevious = EnumSet.copyOf(possibleScreens);
if (previousScreen != null) {
possibleScreensIncludingPrevious.add(previousScreen);
}