/** * Print the results. */ public SearchResults print() { if (!isEmpty()) System.out.println(toString()); return this; } }
/** * Return a string version of the object. */ @Override public String toString() { String output = ""; if (!isEmpty()) { output += headerToString() // Create a string containing indices of all the matches. + "[" + mList // Convert list to a stream. .stream() // Create a custom collector to join all the results // together. .collect(Collector.of(() -> new StringJoiner("|"), // supplier (j, r) -> j.add(r.toString()), // accumulator StringJoiner::merge, // combiner StringJoiner::toString)) // finisher + "]"; } return output; }