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

js.util.collections.KeyValue Maven / Gradle / Ivy

package js.util.collections;

import js.lang.Any;
import js.lang.JsObject;
import org.teavm.jso.JSBody;

import java.util.Map;


public abstract class KeyValue implements Any, Map.Entry {
    @JSBody(params = {"key", "value"}, script = "return [key, value]")
    public static  KeyValue of(K key, V value) {
        throw new UnsupportedOperationException("Available only in JavaScript");
    }

    @JSBody(script = "return this[0]")
    @Override
    public native K getKey();

    @JSBody(script = "return this[1]")
    @Override
    public native V getValue();

    @JSBody(params = "value", script = "var old = this[1]; this[1] = value; return old;")
    @Override
    public native V setValue(V value);

    @SuppressWarnings("unchecked")
    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        KeyValue other = (KeyValue) o;

        boolean result = (other.getKey() == null && getKey() == null) || JsObject.is(other.getKey(), getKey());
        result &= (other.getValue() == null && getValue() == null) || JsObject.is(other.getValue(), getValue());

        return result;
    }

    @Override
    public int hashCode() {
        throw new UnsupportedOperationException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy