@@ -40,7 +40,7 @@ public interface Opaque {
40
40
* @return The {@link Opaque} instance.
41
41
*/
42
42
static Opaque forBytes (byte [] bytes ) {
43
- return new OpaqueImpl (bytes .clone ());
43
+ return new OpaqueImmutableImpl (bytes .clone ());
44
44
}
45
45
46
46
/**
@@ -53,7 +53,7 @@ static Opaque forBytes(byte[] bytes) {
53
53
* @return The {@link Opaque} instance.
54
54
*/
55
55
static Opaque forMutableByteArray (byte [] bytes ) {
56
- return new OpaqueMutableImpl (bytes );
56
+ return new OpaqueImpl (bytes );
57
57
}
58
58
59
59
/**
@@ -68,7 +68,7 @@ static Opaque forBytes(ByteBuffer buf, int length) {
68
68
byte [] bytes = new byte [length ];
69
69
buf .get (bytes );
70
70
71
- return new OpaqueImpl (bytes );
71
+ return new OpaqueImmutableImpl (bytes );
72
72
}
73
73
74
74
/**
@@ -176,8 +176,6 @@ default void putBytes(ByteBuffer buf) {
176
176
177
177
class OpaqueImpl implements Opaque {
178
178
final byte [] _opaque ;
179
- private String base64 = null ;
180
- private int hashCode ;
181
179
182
180
OpaqueImpl (byte [] opaque ) {
183
181
_opaque = opaque ;
@@ -188,29 +186,23 @@ public byte[] toBytes() {
188
186
return _opaque .clone ();
189
187
}
190
188
191
- protected String toBase64Impl () {
192
- return Base64 .getEncoder ().withoutPadding ().encodeToString (_opaque );
189
+ @ Override
190
+ public int hashCode () {
191
+ return Arrays .hashCode (_opaque );
193
192
}
194
193
195
194
@ Override
196
195
public String toBase64 () {
197
- if (base64 == null ) {
198
- base64 = toBase64Impl ();
199
- }
200
- return base64 ;
196
+ return toBase64Impl ();
201
197
}
202
198
203
- @ Override
204
- public void putBytes (ByteBuffer buf ) {
205
- buf .put (_opaque );
199
+ protected String toBase64Impl () {
200
+ return Base64 .getEncoder ().withoutPadding ().encodeToString (_opaque );
206
201
}
207
202
208
203
@ Override
209
- public int hashCode () {
210
- if (hashCode == 0 ) {
211
- hashCode = Arrays .hashCode (_opaque );
212
- }
213
- return hashCode ;
204
+ public void putBytes (ByteBuffer buf ) {
205
+ buf .put (_opaque );
214
206
}
215
207
216
208
@ Override
@@ -259,30 +251,38 @@ public int numBytes() {
259
251
260
252
@ Override
261
253
public Opaque toImmutableOpaque () {
262
- return this ;
254
+ return Opaque . forBytes ( _opaque ) ;
263
255
}
264
256
}
265
257
266
- final class OpaqueMutableImpl extends OpaqueImpl {
267
- protected OpaqueMutableImpl (byte [] opaque ) {
258
+ final class OpaqueImmutableImpl extends OpaqueImpl {
259
+ private String base64 = null ;
260
+ private int hashCode ;
261
+
262
+ protected OpaqueImmutableImpl (byte [] opaque ) {
268
263
super (opaque );
269
264
}
270
265
271
266
@ Override
272
- public Opaque toImmutableOpaque () {
273
- return Opaque .forBytes (_opaque );
267
+ public int hashCode () {
268
+ if (hashCode == 0 ) {
269
+ hashCode = Arrays .hashCode (_opaque );
270
+ }
271
+ return hashCode ;
274
272
}
275
273
276
274
@ Override
277
275
public String toBase64 () {
278
- return toBase64Impl ();
276
+ if (base64 == null ) {
277
+ base64 = toBase64Impl ();
278
+ }
279
+ return base64 ;
279
280
}
280
281
281
282
@ Override
282
- public int hashCode () {
283
- return Arrays . hashCode ( _opaque ) ;
283
+ public Opaque toImmutableOpaque () {
284
+ return this ;
284
285
}
285
-
286
286
}
287
287
288
288
final class OpaqueBufferImpl implements Opaque {
0 commit comments