README quickstart `Filtered<>` snippet compares `String.equals(long)` and ignores `Wallet.id() throws IOException`

Open Beginner friendly
#138 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java
Domain
documentation

Research direction

Start with the README.md quickstart snippet at lines 38-44 and compare it with Wallet.id() in src/main/java/io/zold/api/Wallet.java at line 45. Verify the example handles the numeric id and declared IOException correctly, then confirm the iterator returns the matching wallet rather than failing; done means the documented snippet compiles and behaves as described.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
22
Forks
14
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zold-io/java-api

All issues in zold-io/java-api

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.