The "All you need is this" snippet at README.md lines 38-44 builds a Filtered<> predicate that calls w.id() and asks it to equal the literal string "9999888877776666". Wallet.id() is declared in src/main/java/io/zold/api/Wallet.java line 45 as long id() throws IOException, so the example has two defects.
First, the predicate body never matches. "9999888877776666".equals(w.id()) autoboxes the primitive long to a Long, and String.equals(Long) returns false for every wallet in the directory. The iterator's next() call therefore throws NoSuchElementException instead of returning a wallet.
Second, the snippet does not compile as written. Wallet.id() declares throws IOException, but org.cactoos.iterable.Filtered takes a plain Func<X, Boolean>. A lambda that calls a method throwing a checked exception needs IoCheckedFunc or a wrapper, neither of which the example uses.
Smallest fix: drop the quotes, parse the id as hex, and either use IoCheckedFunc or replace Filtered with the cactoos iterable that tolerates IOException. For example:
final long target = Long.parseUnsignedLong("9999888877776666", 16);
final Wallet wallet = new Filtered<>(
new IoCheckedFunc<>(w -> w.id() == target),
wallets
).iterator().next();
That keeps the README example honest about both the id type and the checked exception surface.
The "All you need is this" snippet at
README.mdlines 38-44 builds aFiltered<>predicate that callsw.id()and asks it to equal the literal string"9999888877776666".Wallet.id()is declared insrc/main/java/io/zold/api/Wallet.javaline 45 aslong id() throws IOException, so the example has two defects.First, the predicate body never matches.
"9999888877776666".equals(w.id())autoboxes the primitivelongto aLong, andString.equals(Long)returnsfalsefor every wallet in the directory. The iterator'snext()call therefore throwsNoSuchElementExceptioninstead of returning a wallet.Second, the snippet does not compile as written.
Wallet.id()declaresthrows IOException, butorg.cactoos.iterable.Filteredtakes a plainFunc<X, Boolean>. A lambda that calls a method throwing a checked exception needsIoCheckedFuncor a wrapper, neither of which the example uses.Smallest fix: drop the quotes, parse the id as hex, and either use
IoCheckedFuncor replaceFilteredwith the cactoos iterable that toleratesIOException. For example:That keeps the README example honest about both the id type and the checked exception surface.