Regalamiunsorriso/decompiled-libs/www/acxent-videoj-1.0.0/org/jcodec/common/IntObjectMap.java

61 lines
1.4 KiB
Java

package org.jcodec.common;
import java.lang.reflect.Array;
import org.jcodec.platform.Platform;
public class IntObjectMap<T> {
private static final int GROW_BY = 128;
private Object[] storage = new Object[128];
private int _size;
public void put(int key, T val) {
if (this.storage.length <= key) {
Object[] ns = new Object[key + 128];
System.arraycopy(this.storage, 0, ns, 0, this.storage.length);
this.storage = ns;
}
if (this.storage[key] == null)
this._size++;
this.storage[key] = val;
}
public T get(int key) {
return (key >= this.storage.length) ? null : (T)this.storage[key];
}
public int[] keys() {
int[] result = new int[this._size];
for (int i = 0, r = 0; i < this.storage.length; i++) {
if (this.storage[i] != null)
result[r++] = i;
}
return result;
}
public void clear() {
for (int i = 0; i < this.storage.length; i++)
this.storage[i] = null;
this._size = 0;
}
public int size() {
return this._size;
}
public void remove(int key) {
if (this.storage[key] != null)
this._size--;
this.storage[key] = null;
}
public T[] values(T[] runtime) {
T[] result = (T[])Array.newInstance(Platform.arrayComponentType(runtime), this._size);
for (int i = 0, r = 0; i < this.storage.length; i++) {
if (this.storage[i] != null)
result[r++] = (T)this.storage[i];
}
return result;
}
}