1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.item.atomic.impl;
7   
8   import java.nio.ByteBuffer;
9   
10  import dev.metaschema.core.datatype.adapter.Base64Adapter;
11  import dev.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
12  import dev.metaschema.core.metapath.impl.AbstractMapKey;
13  import dev.metaschema.core.metapath.item.atomic.IBase64BinaryItem;
14  import dev.metaschema.core.metapath.item.function.IMapKey;
15  import dev.metaschema.core.metapath.item.function.IOpaqueMapKey;
16  import edu.umd.cs.findbugs.annotations.NonNull;
17  
18  /**
19   * An implementation of a Metapath atomic item containing a Base64 encoded data
20   * value.
21   */
22  public class Base64BinaryItemImpl
23      extends AbstractBinaryItem
24      implements IBase64BinaryItem {
25  
26    /**
27     * Construct a new item with the provided {@code value}.
28     *
29     * @param value
30     *          the value to wrap
31     */
32    public Base64BinaryItemImpl(@NonNull ByteBuffer value) {
33      super(value);
34    }
35  
36    @Override
37    public Base64Adapter getJavaTypeAdapter() {
38      return MetaschemaDataTypeProvider.BASE64;
39    }
40  
41    @Override
42    public IMapKey asMapKey() {
43      return new MapKey();
44    }
45  
46    @Override
47    public int hashCode() {
48      return asByteBuffer().hashCode();
49    }
50  
51    @Override
52    public boolean equals(Object obj) {
53      return this == obj
54          || obj instanceof IBase64BinaryItem && compareTo((IBase64BinaryItem) obj) == 0;
55    }
56  
57    private final class MapKey
58        extends AbstractMapKey
59        implements IOpaqueMapKey {
60      @Override
61      public IBase64BinaryItem getKey() {
62        return Base64BinaryItemImpl.this;
63      }
64    }
65  }