Skip to content

Commit e49655a

Browse files
committed
feat: #490 Add new methods getFirst(), clone() to AddressIterator
1 parent 973e34d commit e49655a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

core-api/src/main/java/com/bloxbean/cardano/client/api/AddressIterator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,25 @@
99
* UtxoSelectionStrategy implementation.
1010
*/
1111
public interface AddressIterator extends Iterator<Address> {
12+
13+
/**
14+
* Retrieves the first address in the iterator's list of addresses without moving the cursor.
15+
*
16+
* @return the first {@link Address} in the list, or null if the list is empty.
17+
*/
18+
Address getFirst();
19+
1220
/**
1321
* Reset the pointer to the beginning
1422
*/
1523
void reset();
1624

25+
/**
26+
* Creates and returns a copy of this AddressIterator.
27+
* The cloned instance is independent of the original and can be used separately.
28+
*
29+
* @return a new AddressIterator instance that is a copy of the current iterator.
30+
*/
31+
AddressIterator clone();
32+
1733
}

core-api/src/main/java/com/bloxbean/cardano/client/api/common/AddressIterators.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public static AddressIterator of(Address address) {
1212
return new SingleAddressIterator(address);
1313
}
1414

15+
public static AddressIterator of(String address) {
16+
return new SingleAddressIterator(new Address(address));
17+
}
18+
1519
static class SingleAddressIterator implements AddressIterator {
1620
private Address address;
1721
private Iterator<Address> iterator;
@@ -31,9 +35,19 @@ public Address next() {
3135
return iterator.next();
3236
}
3337

38+
@Override
39+
public Address getFirst() {
40+
return address;
41+
}
42+
3443
@Override
3544
public void reset() {
3645
this.iterator = List.of(address).iterator();
3746
}
47+
48+
@Override
49+
public AddressIterator clone() {
50+
return new SingleAddressIterator(address);
51+
}
3852
}
3953
}

0 commit comments

Comments
 (0)