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

com.github.krukow.clj_lang.ATransientMap Maven / Gradle / Ivy

/**
 *   Copyright (c) Rich Hickey. All rights reserved.
 *   The use and distribution terms for this software are covered by the
 *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *   which can be found in the file epl-v10.html at the root of this distribution.
 *   By using this software in any fashion, you are agreeing to be bound by
 * 	 the terms of this license.
 *   You must not remove this notice, or any other, from this software.
 **/

package com.github.krukow.clj_lang;

import java.util.Map;


abstract class ATransientMap extends AFn implements ITransientMap {
	abstract void ensureEditable();
	abstract ITransientMap doAssoc(K key, V val);
	abstract ITransientMap doWithout(K key);
	abstract V doValAt(K key, V notFound);
	abstract int doCount();
	abstract IPersistentMap doPersistent();

	public ITransientMap conj(Map.Entry o) {
		ensureEditable();
		return assoc(o.getKey(), o.getValue());
	}

	public final Object invoke(Object arg1) {
		return valAt((K) arg1);
	}

	public final Object invoke(Object arg1, Object notFound) {
		return valAt((K)arg1, (V) notFound);
	}

	public final V valAt(K key) {
		return valAt(key, null);
	}

	public final ITransientMap assoc(K key, V val) {
		ensureEditable();
		return doAssoc(key, val);
	}

	public final ITransientMap without(K key) {
		ensureEditable();
		return doWithout(key);
	}

	public final IPersistentMap persistentMap() {
		ensureEditable();
		return doPersistent();
	}

	public final V valAt(K key, V notFound) {
		ensureEditable();
		return doValAt(key, notFound);
	}

	public final int count() {
		ensureEditable();
		return doCount();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy