@@ -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 *
@@ -98,4 +118,32 @@ public byte[] decode(final String encoded) {
98118 .map (base -> base .decode (encoded ))
99119 .orElseThrow (() -> new IllegalArgumentException ("Unsupported multibase encoding [" + encoded .charAt (0 ) + "]." ));
100120 }
121+
122+ /**
123+ * Returns an unmodifiable view of the registered multibase encodings.
124+ *
125+ * <p>
126+ * The returned map associates each multibase prefix character with its
127+ * corresponding {@link Multibase} instance. Attempts to modify the map (e.g.
128+ * {@code put}, {@code remove}) will result in an
129+ * {@link UnsupportedOperationException}.
130+ * </p>
131+ *
132+ * @return an unmodifiable map of prefix characters to {@link Multibase}
133+ * instances
134+ */
135+ public Map <Character , Multibase > bases () {
136+ return bases ;
137+ }
138+
139+ /**
140+ * Returns the number of multibase encodings currently registered with this
141+ * decoder.
142+ *
143+ * @return the count of registered encodings
144+ */
145+ public long size () {
146+ return bases .size ();
147+ }
148+
101149}
0 commit comments