public static PersistentHashMap createWithCheck(Object... init){ ITransientMap ret = EMPTY.asTransient(); for(int i = 0; i < init.length; i += 2) { ret = ret.assoc(init[i], init[i + 1]); if(ret.count() != i/2 + 1) throw new IllegalArgumentException("Duplicate key: " + init[i]); } return (PersistentHashMap) ret.persistent(); }
/** * Returns the value currently associated with {@code key} in this map, or {@code null} if none * exists. */ @SuppressWarnings("unchecked") public V get(K key) { return (V) delegate.valAt(key); }
public ITransientSet disjoin(Object key) { ITransientMap m = impl.without(key); if (m != impl) this.impl = m; return this; }
public IPersistentMap invoke(IPersistentMap req) { Object resp = fn.invoke(req); if (resp instanceof IPersistentMap) { return (IPersistentMap) resp; } else { return PersistentArrayMap.EMPTY.asTransient() .assoc(STATUS, 200) .assoc(BODY_DATA, resp) .assoc(REQ_HEADERS, PersistentArrayMap.EMPTY) .persistent(); } }
@Override public RingHandler header(SelectionKey key, String name, String value) { name = name.toLowerCase(); Object v = headers.valAt(name); if (v == null) { headers = headers.assoc(name, value); } else { if (v.getClass() == String.class) { headers = headers.assoc(name, PersistentVector.create(v, value)); } else if (v instanceof PersistentVector) { PersistentVector pv = (PersistentVector) v; headers = headers.assoc(name, pv.assoc(pv.size(), value)); } } return this; }
public ITransientSet conj(Object val) { ITransientMap m = impl.assoc(val, val); if (m != impl) this.impl = m; return this; }
/** * Returns a persistent immutable version of this TransientMap. This operation is performed in * constant time. Note that after this method is called, this transient instance will no longer * be usable and attempts to modify it will fail. */ public ClojureMap<K, V> toPersistent() { return ClojureMap.wrap(delegate.persistent()); } }
/** * Returns the number of entries currently in this map. */ public int size() { return delegate.count(); }
public static PersistentHashMap create(Object... init){ ITransientMap ret = EMPTY.asTransient(); for(int i = 0; i < init.length; i += 2) { ret = ret.assoc(init[i], init[i + 1]); } return (PersistentHashMap) ret.persistent(); }
public ITransientSet conj(Object val) { ITransientMap m = impl.assoc(val, val); if (m != impl) this.impl = m; return this; }
public Object persistent() { return new PersistentHashSet(null, impl.persistent()); } }
public int count() { return impl.count(); }
public static PersistentHashMap create(Object... init){ ITransientMap ret = EMPTY.asTransient(); for(int i = 0; i < init.length; i += 2) { ret = ret.assoc(init[i], init[i + 1]); } return (PersistentHashMap) ret.persistent(); }
public static PersistentHashMap createWithCheck(Object... init){ ITransientMap ret = EMPTY.asTransient(); for(int i = 0; i < init.length; i += 2) { ret = ret.assoc(init[i], init[i + 1]); if(ret.count() != i/2 + 1) throw new IllegalArgumentException("Duplicate key: " + init[i]); } return (PersistentHashMap) ret.persistent(); }
public Object invoke(Object key, Object notFound) { return impl.valAt(key, notFound); }
/** * Add a binding from {@code key} to {@code value} to this map, overwriting any existing * binding for {@code key}. */ public void put(K key, V value) { delegate = delegate.assoc(key, value); }
public IPersistentCollection persistent() { return new PersistentHashSet(null, impl.persistent()); } }
public ITransientSet disjoin(Object key) { ITransientMap m = impl.without(key); if (m != impl) this.impl = m; return this; }
public int count() { return impl.count(); }
static public IPersistentMap create(Map other){ ITransientMap ret = EMPTY.asTransient(); for(Object o : other.entrySet()) { Map.Entry e = (Entry) o; ret = ret.assoc(e.getKey(), e.getValue()); } return ret.persistent(); }