com.koushikdutta.async.util.HashList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of androidasync Show documentation
Show all versions of androidasync Show documentation
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
package com.koushikdutta.async.util;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Set;
/**
* Created by koush on 5/27/13.
*/
public class HashList {
class TaggedList extends ArrayList {
Object tag;
}
Hashtable> internal = new Hashtable>();
public HashList() {
}
public Set keySet() {
return internal.keySet();
}
public synchronized V tag(String key) {
TaggedList list = internal.get(key);
if (list == null)
return null;
return (V)list.tag;
}
public synchronized void tag(String key, V tag) {
TaggedList list = internal.get(key);
if (list == null) {
list = new TaggedList();
internal.put(key, list);
}
list.tag = tag;
}
public synchronized ArrayList remove(String key) {
return internal.remove(key);
}
public synchronized int size() {
return internal.size();
}
public synchronized ArrayList get(String key) {
return internal.get(key);
}
synchronized public boolean contains(String key) {
ArrayList check = get(key);
return check != null && check.size() > 0;
}
synchronized public void add(String key, T value) {
ArrayList ret = get(key);
if (ret == null) {
TaggedList put = new TaggedList();
ret = put;
internal.put(key, put);
}
ret.add(value);
}
synchronized public T pop(String key) {
TaggedList values = internal.get(key);
if (values == null)
return null;
if (values.size() == 0)
return null;
return values.remove(values.size() - 1);
}
synchronized public boolean removeItem(String key, T value) {
TaggedList values = internal.get(key);
if (values == null)
return false;
values.remove(value);
return values.size() == 0;
}
}