All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sirix.index.art.LeafNode Maven / Gradle / Ivy

package io.sirix.index.art;

import java.util.Arrays;
import java.util.Map;

/*
    currently we use what the paper mentions as "Single-value" leaves
 */
class LeafNode extends Node implements Map.Entry {
	private V value;

	// we have to save the keyBytes, because leaves are lazy expanded at times
	private final byte[] keyBytes;
	private final K key;

	LeafNode(byte[] keyBytes, K key, V value) {
		this.value = value;
		// defensive copy
		this.keyBytes = Arrays.copyOf(keyBytes, keyBytes.length);
		this.key = key;
	}

	public V setValue(V value) {
		V oldValue = this.value;
		this.value = value;
		return oldValue;
	}

	public V getValue() {
		return value;
	}

	byte[] getKeyBytes() {
		return keyBytes;
	}

	public K getKey() {
		return key;
	}

	/**
	 Dev note: first() is implemented to detect end of the SortedMap.firstKey()
	 */
	@Override
	public Node first() {
		return null;
	}

	@Override
	public Node firstOrLeaf() {
		return null;
	}

	/**
	 Dev note: last() is implemented to detect end of the SortedMap.lastKey()
	 */
	@Override
	public Node last() {
		return null;
	}

	/**
	 * Compares this Map.Entry with another Map.Entry.
	 * 

* Implemented per API documentation of {@link Map.Entry#equals(Object)} * * @param obj the object to compare to * @return true if equal key and value */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof final Map.Entry other)) { return false; } return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); } /** * Gets a hashCode compatible with the equals method. *

* Implemented per API documentation of {@link Map.Entry#hashCode()} * * @return a suitable hash code */ @Override public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); } @Override public String toString() { return key + "=" + value; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy