Skip to content

Commit 28671c0

Browse files
committed
Add findBase(name) method (#97)
1 parent 83aef25 commit 28671c0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/main/java/com/apicatalog/multibase/MultibaseDecoder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ public Optional<Multibase> getBase(final String encoded) {
8585
return getBase(encoded.charAt(0));
8686
}
8787

88+
/**
89+
* Finds a registered {@link Multibase} encoding by its name.
90+
*
91+
* <p>
92+
* This method searches through all multibases registered with this decoder and
93+
* returns the first whose {@link Multibase#name()} matches the given name
94+
* exactly.
95+
* </p>
96+
*
97+
* @param name the name of the multibase encoding (must not be {@code null})
98+
* @return an {@code Optional} containing the matching {@link Multibase}, or an
99+
* empty {@code Optional} if no encoding with the given name is found
100+
* @throws NullPointerException if {@code name} is {@code null}
101+
*/
102+
public final Optional<Multibase> findBase(final String name) {
103+
return bases.values().stream()
104+
.filter(base -> base.name().equals(name))
105+
.findFirst();
106+
}
107+
88108
/**
89109
* Decodes a multibase-encoded string into a byte array.
90110
*

0 commit comments

Comments
 (0)