The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

erjablow (9) [Avatar] Offline
Listing 4.7 describes a class that can search through any Java collection of Strings in various ways, but it is not as as general as it should be. I have often written code where a class exposes a collection it holds internally, not as a Collection, but as an Iterable:

public class Node {
private List<Node> children;
public Iterable<Node> children() {
// From Google Collections
return Iterables.unmodifiableIterator(children.iterator());
// ...

This way, no one can muckaround with the internals of Node. Should StringSearch use Iterable<String> instead of Collection<String>?