1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.impl;
7   
8   import dev.metaschema.core.metapath.item.function.IMapKey;
9   import nl.talsmasoftware.lazy4j.Lazy;
10  
11  public abstract class AbstractMapKey implements IMapKey {
12    private final Lazy<Integer> hashCode = Lazy.of(this::generateHashCode);
13  
14    @Override
15    public int hashCode() {
16      return hashCode.get();
17    }
18  
19    /**
20     * Generate the hash code for the key.
21     *
22     * @return the hash code
23     */
24    protected int generateHashCode() {
25      return getKey().hashCode();
26    }
27  
28    @Override
29    public boolean equals(Object obj) {
30      return this == obj
31          || (obj instanceof IMapKey && isSameKey((IMapKey) obj));
32    }
33  
34    @Override
35    public String toString() {
36      return getKey().toSignature();
37    }
38  }