first commit

This commit is contained in:
2025-07-28 13:56:49 +05:30
commit e9eb805edb
3438 changed files with 520990 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
package org.apache.commons.collections;
import java.util.ArrayList;
import java.util.EmptyStackException;
public class ArrayStack extends ArrayList implements Buffer {
private static final long serialVersionUID = 2130079159931574599L;
public ArrayStack() {}
public ArrayStack(int paramInt) {
super(paramInt);
}
public boolean empty() {
return isEmpty();
}
public Object get() {
int i = size();
if (i == 0)
throw new BufferUnderflowException();
return get(i - 1);
}
public Object peek() throws EmptyStackException {
int i = size();
if (i <= 0)
throw new EmptyStackException();
return get(i - 1);
}
public Object peek(int paramInt) throws EmptyStackException {
int i = size() - paramInt - 1;
if (i < 0)
throw new EmptyStackException();
return get(i);
}
public Object pop() throws EmptyStackException {
int i = size();
if (i <= 0)
throw new EmptyStackException();
return remove(i - 1);
}
public Object push(Object paramObject) {
add((E)paramObject);
return paramObject;
}
public Object remove() {
int i = size();
if (i == 0)
throw new BufferUnderflowException();
return remove(i - 1);
}
public int search(Object paramObject) {
int i = size() - 1;
for (byte b = 1; i >= 0; b++) {
E e = get(i);
if ((paramObject == null && e == null) || (paramObject != null && paramObject.equals(e)))
return b;
i--;
}
return -1;
}
}

View File

@@ -0,0 +1,9 @@
package org.apache.commons.collections;
import java.util.Collection;
public interface Buffer extends Collection {
Object get();
Object remove();
}

View File

@@ -0,0 +1,19 @@
package org.apache.commons.collections;
public class BufferUnderflowException extends RuntimeException {
private final Throwable m_throwable = null;
public BufferUnderflowException() {}
public BufferUnderflowException(String paramString) {
this(paramString, null);
}
public BufferUnderflowException(String paramString, Throwable paramThrowable) {
super(paramString);
}
public final Throwable getCause() {
return this.m_throwable;
}
}

View File

@@ -0,0 +1,49 @@
package org.apache.commons.collections;
import java.util.Map;
public class DefaultMapEntry implements Map.Entry {
private Object key;
private Object value;
public DefaultMapEntry() {}
public DefaultMapEntry(Object paramObject1, Object paramObject2) {
this.key = paramObject1;
this.value = paramObject2;
}
public boolean equals(Object paramObject) {
if (paramObject == null)
return false;
if (paramObject == this)
return true;
if (!(paramObject instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry)paramObject;
return !(!((getKey() == null) ? (entry.getKey() == null) : getKey().equals(entry.getKey())) || !((getValue() == null) ? (entry.getValue() == null) : getValue().equals(entry.getValue())));
}
public Object getKey() {
return this.key;
}
public Object getValue() {
return this.value;
}
public int hashCode() {
return ((getKey() == null) ? 0 : getKey().hashCode()) ^ ((getValue() == null) ? 0 : getValue().hashCode());
}
public void setKey(Object paramObject) {
this.key = paramObject;
}
public Object setValue(Object paramObject) {
Object object = this.value;
this.value = paramObject;
return object;
}
}

View File

@@ -0,0 +1,455 @@
package org.apache.commons.collections;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class FastHashMap extends HashMap {
protected HashMap map = null;
protected boolean fast = false;
public FastHashMap() {
this.map = new HashMap();
}
public FastHashMap(int paramInt) {
this.map = new HashMap(paramInt);
}
public FastHashMap(int paramInt, float paramFloat) {
this.map = new HashMap(paramInt, paramFloat);
}
public FastHashMap(Map paramMap) {
this.map = new HashMap(paramMap);
}
public void clear() {
if (this.fast) {
synchronized (this) {
HashMap hashMap = (HashMap)this.map.clone();
hashMap.clear();
this.map = hashMap;
}
} else {
synchronized (this.map) {
this.map.clear();
}
}
}
public Object clone() {
FastHashMap fastHashMap = null;
if (this.fast) {
fastHashMap = new FastHashMap(this.map);
} else {
synchronized (this.map) {
fastHashMap = new FastHashMap(this.map);
}
}
fastHashMap.setFast(getFast());
return fastHashMap;
}
public boolean containsKey(Object paramObject) {
if (this.fast)
return this.map.containsKey(paramObject);
synchronized (this.map) {
return this.map.containsKey(paramObject);
}
}
public boolean containsValue(Object paramObject) {
if (this.fast)
return this.map.containsValue(paramObject);
synchronized (this.map) {
return this.map.containsValue(paramObject);
}
}
public Set entrySet() {
return new EntrySet(this);
}
public boolean equals(Object paramObject) {
if (paramObject == this)
return true;
if (!(paramObject instanceof Map))
return false;
Map map = (Map)paramObject;
if (this.fast) {
if (map.size() != this.map.size())
return false;
for (Map.Entry entry : this.map.entrySet()) {
Object object1 = entry.getKey();
Object object2 = entry.getValue();
if (object2 == null) {
if (map.get(object1) != null || !map.containsKey(object1))
return false;
continue;
}
if (!object2.equals(map.get(object1)))
return false;
}
return true;
}
synchronized (this.map) {
if (map.size() != this.map.size())
return false;
for (Map.Entry entry : this.map.entrySet()) {
Object object1 = entry.getKey();
Object object2 = entry.getValue();
if (object2 == null) {
if (map.get(object1) != null || !map.containsKey(object1))
return false;
continue;
}
if (!object2.equals(map.get(object1)))
return false;
}
return true;
}
}
public Object get(Object paramObject) {
if (this.fast)
return this.map.get(paramObject);
synchronized (this.map) {
return this.map.get(paramObject);
}
}
public boolean getFast() {
return this.fast;
}
public int hashCode() {
if (this.fast) {
int i = 0;
Iterator iterator = this.map.entrySet().iterator();
while (iterator.hasNext())
i += iterator.next().hashCode();
return i;
}
synchronized (this.map) {
int i = 0;
Iterator iterator = this.map.entrySet().iterator();
while (iterator.hasNext())
i += iterator.next().hashCode();
return i;
}
}
public boolean isEmpty() {
if (this.fast)
return this.map.isEmpty();
synchronized (this.map) {
return this.map.isEmpty();
}
}
public Set keySet() {
return new KeySet(this);
}
public Object put(Object paramObject1, Object paramObject2) {
if (this.fast)
synchronized (this) {
HashMap hashMap = (HashMap)this.map.clone();
Object object = hashMap.put(paramObject1, paramObject2);
this.map = hashMap;
return object;
}
synchronized (this.map) {
return this.map.put(paramObject1, paramObject2);
}
}
public void putAll(Map paramMap) {
if (this.fast) {
synchronized (this) {
HashMap hashMap = (HashMap)this.map.clone();
hashMap.putAll(paramMap);
this.map = hashMap;
}
} else {
synchronized (this.map) {
this.map.putAll(paramMap);
}
}
}
public Object remove(Object paramObject) {
if (this.fast)
synchronized (this) {
HashMap hashMap = (HashMap)this.map.clone();
Object object = hashMap.remove(paramObject);
this.map = hashMap;
return object;
}
synchronized (this.map) {
return this.map.remove(paramObject);
}
}
public void setFast(boolean paramBoolean) {
this.fast = paramBoolean;
}
public int size() {
if (this.fast)
return this.map.size();
synchronized (this.map) {
return this.map.size();
}
}
public Collection values() {
return new Values(this);
}
private abstract class CollectionView implements Collection {
private final FastHashMap this$0;
public CollectionView(FastHashMap this$0) {
this.this$0 = this$0;
}
public boolean add(Object param1Object) {
throw new UnsupportedOperationException();
}
public boolean addAll(Collection param1Collection) {
throw new UnsupportedOperationException();
}
public void clear() {
if (this.this$0.fast) {
synchronized (this.this$0) {
HashMap hashMap = (HashMap)this.this$0.map.clone();
get(hashMap).clear();
this.this$0.map = hashMap;
}
} else {
synchronized (this.this$0.map) {
get(this.this$0.map).clear();
}
}
}
public boolean contains(Object param1Object) {
if (this.this$0.fast)
return get(this.this$0.map).contains(param1Object);
synchronized (this.this$0.map) {
return get(this.this$0.map).contains(param1Object);
}
}
public boolean containsAll(Collection param1Collection) {
if (this.this$0.fast)
return get(this.this$0.map).containsAll(param1Collection);
synchronized (this.this$0.map) {
return get(this.this$0.map).containsAll(param1Collection);
}
}
public boolean equals(Object param1Object) {
if (param1Object == this)
return true;
if (this.this$0.fast)
return get(this.this$0.map).equals(param1Object);
synchronized (this.this$0.map) {
return get(this.this$0.map).equals(param1Object);
}
}
protected abstract Collection get(Map param1Map);
public int hashCode() {
if (this.this$0.fast)
return get(this.this$0.map).hashCode();
synchronized (this.this$0.map) {
return get(this.this$0.map).hashCode();
}
}
public boolean isEmpty() {
if (this.this$0.fast)
return get(this.this$0.map).isEmpty();
synchronized (this.this$0.map) {
return get(this.this$0.map).isEmpty();
}
}
public Iterator iterator() {
return new CollectionViewIterator(this);
}
protected abstract Object iteratorNext(Map.Entry param1Entry);
public boolean remove(Object param1Object) {
if (this.this$0.fast)
synchronized (this.this$0) {
HashMap hashMap = (HashMap)this.this$0.map.clone();
boolean bool = get(hashMap).remove(param1Object);
this.this$0.map = hashMap;
return bool;
}
synchronized (this.this$0.map) {
return get(this.this$0.map).remove(param1Object);
}
}
public boolean removeAll(Collection param1Collection) {
if (this.this$0.fast)
synchronized (this.this$0) {
HashMap hashMap = (HashMap)this.this$0.map.clone();
boolean bool = get(hashMap).removeAll(param1Collection);
this.this$0.map = hashMap;
return bool;
}
synchronized (this.this$0.map) {
return get(this.this$0.map).removeAll(param1Collection);
}
}
public boolean retainAll(Collection param1Collection) {
if (this.this$0.fast)
synchronized (this.this$0) {
HashMap hashMap = (HashMap)this.this$0.map.clone();
boolean bool = get(hashMap).retainAll(param1Collection);
this.this$0.map = hashMap;
return bool;
}
synchronized (this.this$0.map) {
return get(this.this$0.map).retainAll(param1Collection);
}
}
public int size() {
if (this.this$0.fast)
return get(this.this$0.map).size();
synchronized (this.this$0.map) {
return get(this.this$0.map).size();
}
}
public Object[] toArray() {
if (this.this$0.fast)
return get(this.this$0.map).toArray();
synchronized (this.this$0.map) {
return get(this.this$0.map).toArray();
}
}
public Object[] toArray(Object[] param1ArrayOfObject) {
if (this.this$0.fast)
return get(this.this$0.map).toArray(param1ArrayOfObject);
synchronized (this.this$0.map) {
return get(this.this$0.map).toArray(param1ArrayOfObject);
}
}
private class CollectionViewIterator implements Iterator {
private final FastHashMap.CollectionView this$1;
private Map expected;
private Map.Entry lastReturned;
private Iterator iterator;
public CollectionViewIterator(FastHashMap.CollectionView this$0) {
this.this$1 = this$0;
this.lastReturned = null;
this.expected = this$0.this$0.map;
this.iterator = this.expected.entrySet().iterator();
}
public boolean hasNext() {
if (this.expected != this.this$1.this$0.map)
throw new ConcurrentModificationException();
return this.iterator.hasNext();
}
public Object next() {
if (this.expected != this.this$1.this$0.map)
throw new ConcurrentModificationException();
this.lastReturned = this.iterator.next();
return this.this$1.iteratorNext(this.lastReturned);
}
public void remove() {
if (this.lastReturned == null)
throw new IllegalStateException();
if (this.this$1.this$0.fast) {
synchronized (this.this$1.this$0) {
if (this.expected != this.this$1.this$0.map)
throw new ConcurrentModificationException();
this.this$1.this$0.remove(this.lastReturned.getKey());
this.lastReturned = null;
this.expected = this.this$1.this$0.map;
}
} else {
this.iterator.remove();
this.lastReturned = null;
}
}
}
}
private class KeySet extends CollectionView implements Set {
private final FastHashMap this$0;
KeySet(FastHashMap this$0) {
super(this$0);
this.this$0 = this$0;
}
protected Collection get(Map param1Map) {
return param1Map.keySet();
}
protected Object iteratorNext(Map.Entry param1Entry) {
return param1Entry.getKey();
}
}
private class Values extends CollectionView {
private final FastHashMap this$0;
Values(FastHashMap this$0) {
super(this$0);
this.this$0 = this$0;
}
protected Collection get(Map param1Map) {
return param1Map.values();
}
protected Object iteratorNext(Map.Entry param1Entry) {
return param1Entry.getValue();
}
}
private class EntrySet extends CollectionView implements Set {
private final FastHashMap this$0;
EntrySet(FastHashMap this$0) {
super(this$0);
this.this$0 = this$0;
}
protected Collection get(Map param1Map) {
return param1Map.entrySet();
}
protected Object iteratorNext(Map.Entry param1Entry) {
return param1Entry;
}
}
}

View File

@@ -0,0 +1,563 @@
package org.apache.commons.collections;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
public class ReferenceMap extends AbstractMap {
private static final long serialVersionUID = -3370601314380922368L;
public static final int HARD = 0;
public static final int SOFT = 1;
public static final int WEAK = 2;
private int keyType;
private int valueType;
private float loadFactor;
private transient ReferenceQueue queue = new ReferenceQueue();
private transient Entry[] table;
private transient int size;
private transient int threshold;
private volatile transient int modCount;
private transient Set keySet;
private transient Set entrySet;
private transient Collection values;
public ReferenceMap() {
this(0, 1);
}
public ReferenceMap(int paramInt1, int paramInt2) {
this(paramInt1, paramInt2, 16, 0.75F);
}
public ReferenceMap(int paramInt1, int paramInt2, int paramInt3, float paramFloat) {
verify("keyType", paramInt1);
verify("valueType", paramInt2);
if (paramInt3 <= 0)
throw new IllegalArgumentException("capacity must be positive");
if (paramFloat <= 0.0F || paramFloat >= 1.0F)
throw new IllegalArgumentException("Load factor must be greater than 0 and less than 1.");
this.keyType = paramInt1;
this.valueType = paramInt2;
int i;
for (i = 1; i < paramInt3; i *= 2);
this.table = new Entry[i];
this.loadFactor = paramFloat;
this.threshold = (int)(i * paramFloat);
}
public void clear() {
Arrays.fill((Object[])this.table, (Object)null);
this.size = 0;
do {
} while (this.queue.poll() != null);
}
public boolean containsKey(Object paramObject) {
purge();
Entry entry = getEntry(paramObject);
return (entry == null) ? false : (!(entry.getValue() == null));
}
public Set entrySet() {
if (this.entrySet != null)
return this.entrySet;
this.entrySet = new AbstractSet(this) {
private final ReferenceMap this$0;
public void clear() {
this.this$0.clear();
}
public boolean contains(Object param1Object) {
if (param1Object == null)
return false;
if (!(param1Object instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry)param1Object;
ReferenceMap.Entry entry1 = this.this$0.getEntry(entry.getKey());
return !(entry1 == null || !entry.equals(entry1));
}
public Iterator iterator() {
return new ReferenceMap.EntryIterator(this.this$0);
}
public boolean remove(Object param1Object) {
boolean bool = contains(param1Object);
if (bool) {
Map.Entry entry = (Map.Entry)param1Object;
this.this$0.remove(entry.getKey());
}
return bool;
}
public int size() {
return this.this$0.size();
}
public Object[] toArray() {
return toArray(new Object[0]);
}
public Object[] toArray(Object[] param1ArrayOfObject) {
ArrayList arrayList = new ArrayList();
for (ReferenceMap.Entry entry : this)
arrayList.add(new DefaultMapEntry(entry.getKey(), entry.getValue()));
return arrayList.toArray(param1ArrayOfObject);
}
};
return this.entrySet;
}
public Object get(Object paramObject) {
purge();
Entry entry = getEntry(paramObject);
return (entry == null) ? null : entry.getValue();
}
private Entry getEntry(Object paramObject) {
if (paramObject == null)
return null;
int i = paramObject.hashCode();
int j = indexFor(i);
for (Entry entry = this.table[j]; entry != null; entry = entry.next) {
if (entry.hash == i && paramObject.equals(entry.getKey()))
return entry;
}
return null;
}
private int indexFor(int paramInt) {
paramInt += paramInt << 15 ^ 0xFFFFFFFF;
paramInt ^= paramInt >>> 10;
paramInt += paramInt << 3;
paramInt ^= paramInt >>> 6;
paramInt += paramInt << 11 ^ 0xFFFFFFFF;
paramInt ^= paramInt >>> 16;
return paramInt & this.table.length - 1;
}
public boolean isEmpty() {
purge();
return !(this.size != 0);
}
public Set keySet() {
if (this.keySet != null)
return this.keySet;
this.keySet = new AbstractSet(this) {
private final ReferenceMap this$0;
public void clear() {
this.this$0.clear();
}
public boolean contains(Object param1Object) {
return this.this$0.containsKey(param1Object);
}
public Iterator iterator() {
return new ReferenceMap.KeyIterator(this.this$0);
}
public boolean remove(Object param1Object) {
Object object = this.this$0.remove(param1Object);
return !(object == null);
}
public int size() {
return this.this$0.size;
}
};
return this.keySet;
}
private void purge() {
for (Reference reference = this.queue.poll(); reference != null; reference = this.queue.poll())
purge(reference);
}
private void purge(Reference paramReference) {
int i = paramReference.hashCode();
int j = indexFor(i);
Entry entry1 = null;
for (Entry entry2 = this.table[j]; entry2 != null; entry2 = entry2.next) {
if (entry2.purge(paramReference)) {
if (entry1 == null) {
this.table[j] = entry2.next;
} else {
entry1.next = entry2.next;
}
this.size--;
return;
}
entry1 = entry2;
}
}
public Object put(Object paramObject1, Object paramObject2) {
if (paramObject1 == null)
throw new NullPointerException("null keys not allowed");
if (paramObject2 == null)
throw new NullPointerException("null values not allowed");
purge();
if (this.size + 1 > this.threshold)
resize();
int i = paramObject1.hashCode();
int j = indexFor(i);
for (Entry entry = this.table[j]; entry != null; entry = entry.next) {
if (i == entry.hash && paramObject1.equals(entry.getKey())) {
Object object = entry.getValue();
entry.setValue(paramObject2);
return object;
}
}
this.size++;
this.modCount++;
paramObject1 = toReference(this.keyType, paramObject1, i);
paramObject2 = toReference(this.valueType, paramObject2, i);
this.table[j] = new Entry(this, paramObject1, i, paramObject2, this.table[j]);
return null;
}
private void readObject(ObjectInputStream paramObjectInputStream) throws IOException, ClassNotFoundException {
paramObjectInputStream.defaultReadObject();
this.table = new Entry[paramObjectInputStream.readInt()];
this.threshold = (int)(this.table.length * this.loadFactor);
this.queue = new ReferenceQueue();
for (Object object = paramObjectInputStream.readObject(); object != null; object = paramObjectInputStream.readObject()) {
Object object1 = paramObjectInputStream.readObject();
put(object, object1);
}
}
public Object remove(Object paramObject) {
if (paramObject == null)
return null;
purge();
int i = paramObject.hashCode();
int j = indexFor(i);
Entry entry1 = null;
for (Entry entry2 = this.table[j]; entry2 != null; entry2 = entry2.next) {
if (i == entry2.hash && paramObject.equals(entry2.getKey())) {
if (entry1 == null) {
this.table[j] = entry2.next;
} else {
entry1.next = entry2.next;
}
this.size--;
this.modCount++;
return entry2.getValue();
}
entry1 = entry2;
}
return null;
}
private void resize() {
Entry[] arrayOfEntry = this.table;
this.table = new Entry[arrayOfEntry.length * 2];
for (byte b = 0; b < arrayOfEntry.length; b++) {
Entry entry = arrayOfEntry[b];
while (entry != null) {
Entry entry1 = entry;
entry = entry.next;
int i = indexFor(entry1.hash);
entry1.next = this.table[i];
this.table[i] = entry1;
}
arrayOfEntry[b] = null;
}
this.threshold = (int)(this.table.length * this.loadFactor);
}
public int size() {
purge();
return this.size;
}
private Object toReference(int paramInt1, Object paramObject, int paramInt2) {
switch (paramInt1) {
case 0:
return paramObject;
case 1:
return new SoftRef(paramInt2, paramObject, this.queue);
case 2:
return new WeakRef(paramInt2, paramObject, this.queue);
}
throw new Error();
}
public Collection values() {
if (this.values != null)
return this.values;
this.values = new AbstractCollection(this) {
private final ReferenceMap this$0;
public void clear() {
this.this$0.clear();
}
public Iterator iterator() {
return new ReferenceMap.ValueIterator(this.this$0);
}
public int size() {
return this.this$0.size;
}
};
return this.values;
}
private static void verify(String paramString, int paramInt) {
if (paramInt < 0 || paramInt > 2)
throw new IllegalArgumentException(String.valueOf(paramString) + " must be HARD, SOFT, WEAK.");
}
private void writeObject(ObjectOutputStream paramObjectOutputStream) throws IOException {
paramObjectOutputStream.defaultWriteObject();
paramObjectOutputStream.writeInt(this.table.length);
for (Map.Entry entry : entrySet()) {
paramObjectOutputStream.writeObject(entry.getKey());
paramObjectOutputStream.writeObject(entry.getValue());
}
paramObjectOutputStream.writeObject(null);
}
private class Entry implements Map.Entry {
private final ReferenceMap this$0;
Object key;
Object value;
int hash;
Entry next;
public Entry(ReferenceMap this$0, Object param1Object1, int param1Int, Object param1Object2, Entry param1Entry) {
this.this$0 = this$0;
this.key = param1Object1;
this.hash = param1Int;
this.value = param1Object2;
this.next = param1Entry;
}
public boolean equals(Object param1Object) {
if (param1Object == null)
return false;
if (param1Object == this)
return true;
if (!(param1Object instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry)param1Object;
Object object1 = entry.getKey();
Object object2 = entry.getValue();
return (object1 == null || object2 == null) ? false : (!(!object1.equals(getKey()) || !object2.equals(getValue())));
}
public Object getKey() {
return (this.this$0.keyType > 0) ? ((Reference)this.key).get() : this.key;
}
public Object getValue() {
return (this.this$0.valueType > 0) ? ((Reference)this.value).get() : this.value;
}
public int hashCode() {
Object object = getValue();
return this.hash ^ ((object == null) ? 0 : object.hashCode());
}
boolean purge(Reference param1Reference) {
boolean bool = (this.this$0.keyType <= 0 || this.key != param1Reference) ? false : true;
bool = (!bool && (this.this$0.valueType <= 0 || this.value != param1Reference)) ? false : true;
if (bool) {
if (this.this$0.keyType > 0)
((Reference)this.key).clear();
if (this.this$0.valueType > 0)
((Reference)this.value).clear();
}
return bool;
}
public Object setValue(Object param1Object) {
Object object = getValue();
if (this.this$0.valueType > 0)
((Reference)this.value).clear();
this.value = this.this$0.toReference(this.this$0.valueType, param1Object, this.hash);
return object;
}
public String toString() {
return String.valueOf(String.valueOf(getKey())) + "=" + getValue();
}
}
private class EntryIterator implements Iterator {
private final ReferenceMap this$0;
int index;
ReferenceMap.Entry entry;
ReferenceMap.Entry previous;
Object nextKey;
Object nextValue;
Object currentKey;
Object currentValue;
int expectedModCount;
public EntryIterator(ReferenceMap this$0) {
this.this$0 = this$0;
this.index = (this$0.size() != 0) ? this$0.table.length : 0;
this.expectedModCount = this$0.modCount;
}
private void checkMod() {
if (this.this$0.modCount != this.expectedModCount)
throw new ConcurrentModificationException();
}
public boolean hasNext() {
checkMod();
while (nextNull()) {
ReferenceMap.Entry entry = this.entry;
int i = this.index;
while (entry == null && i > 0)
entry = this.this$0.table[--i];
this.entry = entry;
this.index = i;
if (entry == null) {
this.currentKey = null;
this.currentValue = null;
return false;
}
this.nextKey = entry.getKey();
this.nextValue = entry.getValue();
if (nextNull())
this.entry = this.entry.next;
}
return true;
}
public Object next() {
return nextEntry();
}
protected ReferenceMap.Entry nextEntry() {
checkMod();
if (nextNull() && !hasNext())
throw new NoSuchElementException();
this.previous = this.entry;
this.entry = this.entry.next;
this.currentKey = this.nextKey;
this.currentValue = this.nextValue;
this.nextKey = null;
this.nextValue = null;
return this.previous;
}
private boolean nextNull() {
return !(this.nextKey != null && this.nextValue != null);
}
public void remove() {
checkMod();
if (this.previous == null)
throw new IllegalStateException();
this.this$0.remove(this.currentKey);
this.previous = null;
this.currentKey = null;
this.currentValue = null;
this.expectedModCount = this.this$0.modCount;
}
}
private class ValueIterator extends EntryIterator {
private final ReferenceMap this$0;
ValueIterator(ReferenceMap this$0) {
super(this$0);
this.this$0 = this$0;
}
public Object next() {
return nextEntry().getValue();
}
}
private class KeyIterator extends EntryIterator {
private final ReferenceMap this$0;
KeyIterator(ReferenceMap this$0) {
super(this$0);
this.this$0 = this$0;
}
public Object next() {
return nextEntry().getKey();
}
}
private static class SoftRef extends SoftReference {
private int hash;
public SoftRef(int param1Int, Object param1Object, ReferenceQueue param1ReferenceQueue) {
super((T)param1Object, param1ReferenceQueue);
this.hash = param1Int;
}
public int hashCode() {
return this.hash;
}
}
private static class WeakRef extends WeakReference {
private int hash;
public WeakRef(int param1Int, Object param1Object, ReferenceQueue param1ReferenceQueue) {
super((T)param1Object, param1ReferenceQueue);
this.hash = param1Int;
}
public int hashCode() {
return this.hash;
}
}
}

View File

@@ -0,0 +1,476 @@
package org.apache.commons.collections;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.AbstractCollection;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
public class SequencedHashMap implements Map, Cloneable, Externalizable {
private Entry sentinel = createSentinel();
private HashMap entries = new HashMap();
private transient long modCount = 0L;
private static final int KEY = 0;
private static final int VALUE = 1;
private static final int ENTRY = 2;
private static final int REMOVED_MASK = -2147483648;
private static final long serialVersionUID = 3380552487888102930L;
public SequencedHashMap() {}
public SequencedHashMap(int paramInt) {}
public SequencedHashMap(int paramInt, float paramFloat) {}
public SequencedHashMap(Map paramMap) {
this();
putAll(paramMap);
}
public void clear() {
this.modCount++;
this.entries.clear();
this.sentinel.next = this.sentinel;
this.sentinel.prev = this.sentinel;
}
public Object clone() throws CloneNotSupportedException {
SequencedHashMap sequencedHashMap = (SequencedHashMap)super.clone();
sequencedHashMap.sentinel = createSentinel();
sequencedHashMap.entries = new HashMap();
sequencedHashMap.putAll(this);
return sequencedHashMap;
}
public boolean containsKey(Object paramObject) {
return this.entries.containsKey(paramObject);
}
public boolean containsValue(Object paramObject) {
if (paramObject == null) {
for (Entry entry = this.sentinel.next; entry != this.sentinel; entry = entry.next) {
if (entry.getValue() == null)
return true;
}
} else {
for (Entry entry = this.sentinel.next; entry != this.sentinel; entry = entry.next) {
if (paramObject.equals(entry.getValue()))
return true;
}
}
return false;
}
private static final Entry createSentinel() {
Entry entry = new Entry(null, null);
entry.prev = entry;
entry.next = entry;
return entry;
}
public Set entrySet() {
return new AbstractSet(this) {
private final SequencedHashMap this$0;
public void clear() {
this.this$0.clear();
}
public boolean contains(Object param1Object) {
return !(findEntry(param1Object) == null);
}
private SequencedHashMap.Entry findEntry(Object param1Object) {
if (param1Object == null)
return null;
if (!(param1Object instanceof Map.Entry))
return null;
Map.Entry entry = (Map.Entry)param1Object;
SequencedHashMap.Entry entry1 = (SequencedHashMap.Entry)this.this$0.entries.get(entry.getKey());
return (entry1 != null && entry1.equals(entry)) ? entry1 : null;
}
public boolean isEmpty() {
return this.this$0.isEmpty();
}
public Iterator iterator() {
return new SequencedHashMap.OrderedIterator(this.this$0, 2);
}
public boolean remove(Object param1Object) {
SequencedHashMap.Entry entry = findEntry(param1Object);
return (entry == null) ? false : (!(this.this$0.removeImpl(entry.getKey()) == null));
}
public int size() {
return this.this$0.size();
}
};
}
public boolean equals(Object paramObject) {
return (paramObject == null) ? false : ((paramObject == this) ? true : (!(paramObject instanceof Map) ? false : entrySet().equals(((Map)paramObject).entrySet())));
}
public Object get(int paramInt) {
return getEntry(paramInt).getKey();
}
public Object get(Object paramObject) {
Entry entry = (Entry)this.entries.get(paramObject);
return (entry == null) ? null : entry.getValue();
}
private Map.Entry getEntry(int paramInt) {
Entry entry = this.sentinel;
if (paramInt < 0)
throw new ArrayIndexOutOfBoundsException(String.valueOf(paramInt) + " < 0");
byte b = -1;
while (b < paramInt - 1 && entry.next != this.sentinel) {
b++;
entry = entry.next;
}
if (entry.next == this.sentinel)
throw new ArrayIndexOutOfBoundsException(String.valueOf(paramInt) + " >= " + (b + 1));
return entry.next;
}
public Map.Entry getFirst() {
return isEmpty() ? null : this.sentinel.next;
}
public Object getFirstKey() {
return this.sentinel.next.getKey();
}
public Object getFirstValue() {
return this.sentinel.next.getValue();
}
public Map.Entry getLast() {
return isEmpty() ? null : this.sentinel.prev;
}
public Object getLastKey() {
return this.sentinel.prev.getKey();
}
public Object getLastValue() {
return this.sentinel.prev.getValue();
}
public Object getValue(int paramInt) {
return getEntry(paramInt).getValue();
}
public int hashCode() {
return entrySet().hashCode();
}
public int indexOf(Object paramObject) {
Entry entry = (Entry)this.entries.get(paramObject);
byte b = 0;
while (entry.prev != this.sentinel) {
b++;
entry = entry.prev;
}
return b;
}
private void insertEntry(Entry paramEntry) {
paramEntry.next = this.sentinel;
paramEntry.prev = this.sentinel.prev;
this.sentinel.prev.next = paramEntry;
this.sentinel.prev = paramEntry;
}
public boolean isEmpty() {
return !(this.sentinel.next != this.sentinel);
}
public Iterator iterator() {
return keySet().iterator();
}
public Set keySet() {
return new AbstractSet(this) {
private final SequencedHashMap this$0;
public void clear() {
this.this$0.clear();
}
public boolean contains(Object param1Object) {
return this.this$0.containsKey(param1Object);
}
public boolean isEmpty() {
return this.this$0.isEmpty();
}
public Iterator iterator() {
return new SequencedHashMap.OrderedIterator(this.this$0, 0);
}
public boolean remove(Object param1Object) {
SequencedHashMap.Entry entry = this.this$0.removeImpl(param1Object);
return !(entry == null);
}
public int size() {
return this.this$0.size();
}
};
}
public int lastIndexOf(Object paramObject) {
return indexOf(paramObject);
}
public Object put(Object paramObject1, Object paramObject2) {
this.modCount++;
Object object = null;
Entry entry = (Entry)this.entries.get(paramObject1);
if (entry != null) {
removeEntry(entry);
object = entry.setValue(paramObject2);
} else {
entry = new Entry(paramObject1, paramObject2);
this.entries.put(paramObject1, entry);
}
insertEntry(entry);
return object;
}
public void putAll(Map paramMap) {
for (Map.Entry entry : paramMap.entrySet())
put(entry.getKey(), entry.getValue());
}
public void readExternal(ObjectInput paramObjectInput) throws IOException, ClassNotFoundException {
int i = paramObjectInput.readInt();
for (byte b = 0; b < i; b++) {
Object object1 = paramObjectInput.readObject();
Object object2 = paramObjectInput.readObject();
put(object1, object2);
}
}
public Object remove(int paramInt) {
return remove(get(paramInt));
}
public Object remove(Object paramObject) {
Entry entry = removeImpl(paramObject);
return (entry == null) ? null : entry.getValue();
}
private void removeEntry(Entry paramEntry) {
paramEntry.next.prev = paramEntry.prev;
paramEntry.prev.next = paramEntry.next;
}
private Entry removeImpl(Object paramObject) {
Entry entry = (Entry)this.entries.remove(paramObject);
if (entry == null)
return null;
this.modCount++;
removeEntry(entry);
return entry;
}
public List sequence() {
ArrayList arrayList = new ArrayList(size());
Iterator iterator = keySet().iterator();
while (iterator.hasNext())
arrayList.add(iterator.next());
return Collections.unmodifiableList(arrayList);
}
public int size() {
return this.entries.size();
}
public String toString() {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append('[');
for (Entry entry = this.sentinel.next; entry != this.sentinel; entry = entry.next) {
stringBuffer.append(entry.getKey());
stringBuffer.append('=');
stringBuffer.append(entry.getValue());
if (entry.next != this.sentinel)
stringBuffer.append(',');
}
stringBuffer.append(']');
return stringBuffer.toString();
}
public Collection values() {
return new AbstractCollection(this) {
private final SequencedHashMap this$0;
public void clear() {
this.this$0.clear();
}
public boolean contains(Object param1Object) {
return this.this$0.containsValue(param1Object);
}
public boolean isEmpty() {
return this.this$0.isEmpty();
}
public Iterator iterator() {
return new SequencedHashMap.OrderedIterator(this.this$0, 1);
}
public boolean remove(Object param1Object) {
if (param1Object == null) {
for (SequencedHashMap.Entry entry = this.this$0.sentinel.next; entry != this.this$0.sentinel; entry = entry.next) {
if (entry.getValue() == null) {
this.this$0.removeImpl(entry.getKey());
return true;
}
}
} else {
for (SequencedHashMap.Entry entry = this.this$0.sentinel.next; entry != this.this$0.sentinel; entry = entry.next) {
if (param1Object.equals(entry.getValue())) {
this.this$0.removeImpl(entry.getKey());
return true;
}
}
}
return false;
}
public int size() {
return this.this$0.size();
}
};
}
public void writeExternal(ObjectOutput paramObjectOutput) throws IOException {
paramObjectOutput.writeInt(size());
for (Entry entry = this.sentinel.next; entry != this.sentinel; entry = entry.next) {
paramObjectOutput.writeObject(entry.getKey());
paramObjectOutput.writeObject(entry.getValue());
}
}
private static class Entry implements Map.Entry {
private final Object key;
private Object value;
Entry next = null;
Entry prev = null;
public Entry(Object param1Object1, Object param1Object2) {
this.key = param1Object1;
this.value = param1Object2;
}
public boolean equals(Object param1Object) {
if (param1Object == null)
return false;
if (param1Object == this)
return true;
if (!(param1Object instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry)param1Object;
return !(!((getKey() == null) ? (entry.getKey() == null) : getKey().equals(entry.getKey())) || !((getValue() == null) ? (entry.getValue() == null) : getValue().equals(entry.getValue())));
}
public Object getKey() {
return this.key;
}
public Object getValue() {
return this.value;
}
public int hashCode() {
return ((getKey() == null) ? 0 : getKey().hashCode()) ^ ((getValue() == null) ? 0 : getValue().hashCode());
}
public Object setValue(Object param1Object) {
Object object = this.value;
this.value = param1Object;
return object;
}
public String toString() {
return "[" + getKey() + "=" + getValue() + "]";
}
}
private class OrderedIterator implements Iterator {
private final SequencedHashMap this$0;
private int returnType;
private SequencedHashMap.Entry pos;
private transient long expectedModCount;
public OrderedIterator(SequencedHashMap this$0, int param1Int) {
this.this$0 = this$0;
this.pos = this.this$0.sentinel;
this.expectedModCount = this.this$0.modCount;
this.returnType = param1Int | Integer.MIN_VALUE;
}
public boolean hasNext() {
return !(this.pos.next == this.this$0.sentinel);
}
public Object next() {
if (this.this$0.modCount != this.expectedModCount)
throw new ConcurrentModificationException();
if (this.pos.next == this.this$0.sentinel)
throw new NoSuchElementException();
this.returnType &= Integer.MAX_VALUE;
this.pos = this.pos.next;
switch (this.returnType) {
case 0:
return this.pos.getKey();
case 1:
return this.pos.getValue();
case 2:
return this.pos;
}
throw new Error("bad iterator type: " + this.returnType);
}
public void remove() {
if ((this.returnType & Integer.MIN_VALUE) != 0)
throw new IllegalStateException("remove() must follow next()");
if (this.this$0.modCount != this.expectedModCount)
throw new ConcurrentModificationException();
this.this$0.removeImpl(this.pos.getKey());
this.expectedModCount++;
this.returnType |= Integer.MIN_VALUE;
}
}
}

View File

@@ -0,0 +1,36 @@
package org.apache.commons.collections.comparators;
import java.io.Serializable;
import java.util.Comparator;
public class ComparableComparator implements Comparator, Serializable {
private static final ComparableComparator instance = new ComparableComparator();
private static final long serialVersionUID = -291439688585137865L;
public int compare(Object paramObject1, Object paramObject2) {
if (paramObject1 == null || paramObject2 == null)
throw new ClassCastException("There were nulls in the arguments for this method: compare(" + paramObject1 + ", " + paramObject2 + ")");
if (paramObject1 instanceof Comparable) {
if (paramObject2 instanceof Comparable) {
int i = ((Comparable)paramObject1).compareTo(paramObject2);
int j = ((Comparable)paramObject2).compareTo(paramObject1);
if (i == 0 && j == 0)
return 0;
if (i < 0 && j > 0)
return i;
if (i > 0 && j < 0)
return i;
throw new ClassCastException("o1 not comparable to o2");
}
throw new ClassCastException("The first argument of this method was not a Comparable: " + paramObject2.getClass().getName());
}
if (paramObject2 instanceof Comparable)
throw new ClassCastException("The second argument of this method was not a Comparable: " + paramObject1.getClass().getName());
throw new ClassCastException("Both arguments of this method were not Comparables: " + paramObject1.getClass().getName() + " and " + paramObject2.getClass().getName());
}
public static ComparableComparator getInstance() {
return instance;
}
}

View File

@@ -0,0 +1,24 @@
package org.apache.commons.collections.comparators;
import java.io.Serializable;
import java.util.Comparator;
public class ReverseComparator implements Comparator, Serializable {
private Comparator comparator;
public ReverseComparator() {
this(null);
}
public ReverseComparator(Comparator paramComparator) {
if (paramComparator != null) {
this.comparator = paramComparator;
} else {
this.comparator = ComparableComparator.getInstance();
}
}
public int compare(Object paramObject1, Object paramObject2) {
return this.comparator.compare(paramObject2, paramObject1);
}
}