@Test void testSuggestionWithShortDistance() { Optional<String> moves = MisspelledKeywordDistance.calculateDistance("MOVES"); assertEquals("MOVE", moves.orElse("")); }
Optional<String> calculateDistance(String wrongToken) { return KEYWORDS.getSuggestions().stream() .map(item -> new Object[] {item, DISTANCE.apply(wrongToken, item)}) .sorted(comparingInt(o -> (int) o[1])) .filter(item -> !wrongToken.equals(item[0])) .filter(item -> (int) item[1] < 2) .map(item -> item[0].toString()) .findFirst(); }
MisspelledKeywordDistance { Optional<String> calculateDistance(String wrongToken) { return KEYWORDS.getSuggestions().stream() .map(item -> new Object[] {item, DISTANCE.apply(wrongToken, item)}) .sorted(comparingInt(o -> (int) o[1])) .filter(item -> !wrongToken.equals(item[0])) .filter(item -> (int) item[1] < 2) .map(item -> item[0].toString()) .findFirst(); } }
MisspelledKeywordDistance { Optional<String> calculateDistance(String wrongToken) { return KEYWORDS.getSuggestions().stream() .map(item -> new Object[] {item, DISTANCE.apply(wrongToken, item)}) .sorted(comparingInt(o -> (int) o[1])) .filter(item -> !wrongToken.equals(item[0])) .filter(item -> (int) item[1] < 2) .map(item -> item[0].toString()) .findFirst(); }  }
MisspelledKeywordDistance { Optional<String> calculateDistance(String wrongToken) { return KEYWORDS.getSuggestions().stream() .map(item -> new Object[] {item, DISTANCE.apply(wrongToken, item)}) .sorted(comparingInt(o -> (int) o[1])) .filter(item -> !wrongToken.equals(item[0])) .filter(item -> (int) item[1] < 2) .map(item -> item[0].toString()) .findFirst(); }   }
MisspelledKeywordDistance { Optional<String> calculateDistance(String wrongToken) { return KEYWORDS.getSuggestions().stream() .map(item -> new Object[] {item, DISTANCE.apply(wrongToken, item)}) .sorted(comparingInt(o -> (int) o[1])) .filter(item -> !wrongToken.equals(item[0])) .filter(item -> (int) item[1] < 2) .map(item -> item[0].toString()) .findFirst(); }    }