Skip to content

Commit

Permalink
feat: #490 Add new methods getFirst(), clone() to AddressIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Feb 17, 2025
1 parent 973e34d commit e49655a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@
* UtxoSelectionStrategy implementation.
*/
public interface AddressIterator extends Iterator<Address> {

/**
* Retrieves the first address in the iterator's list of addresses without moving the cursor.
*
* @return the first {@link Address} in the list, or null if the list is empty.
*/
Address getFirst();

/**
* Reset the pointer to the beginning
*/
void reset();

/**
* Creates and returns a copy of this AddressIterator.
* The cloned instance is independent of the original and can be used separately.
*
* @return a new AddressIterator instance that is a copy of the current iterator.
*/
AddressIterator clone();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public static AddressIterator of(Address address) {
return new SingleAddressIterator(address);
}

public static AddressIterator of(String address) {
return new SingleAddressIterator(new Address(address));
}

static class SingleAddressIterator implements AddressIterator {
private Address address;
private Iterator<Address> iterator;
Expand All @@ -31,9 +35,19 @@ public Address next() {
return iterator.next();
}

@Override
public Address getFirst() {
return address;
}

@Override
public void reset() {
this.iterator = List.of(address).iterator();
}

@Override
public AddressIterator clone() {
return new SingleAddressIterator(address);
}
}
}

0 comments on commit e49655a

Please sign in to comment.