一、前言
关于jini-core(2.0.1)源码包中net.jini.core.constraint.ArraySet自定有序类集,实现java.util.Set接口,详情参见源码说明。
二、源码说明
package net.jini.core.constraint;@b@@b@import java.lang.reflect.Array;@b@import java.util.Collection;@b@import java.util.Iterator;@b@import java.util.NoSuchElementException;@b@import java.util.Set;@b@@b@final class ArraySet@b@ implements Set@b@{@b@ private final Object[] elements;@b@@b@ ArraySet(Object[] paramArrayOfObject)@b@ {@b@ this.elements = paramArrayOfObject;@b@ }@b@@b@ public int size()@b@ {@b@ return this.elements.length;@b@ }@b@@b@ public boolean isEmpty()@b@ {@b@ return (this.elements.length == 0);@b@ }@b@@b@ public boolean contains(Object paramObject)@b@ {@b@ for (int i = this.elements.length; --i >= 0; ) {@b@ if (!(this.elements[i].equals(paramObject))) break label24;@b@ label24: return true;@b@ }@b@@b@ return false;@b@ }@b@@b@ public Iterator iterator()@b@ {@b@ return new Iter(this);@b@ }@b@@b@ public Object[] toArray()@b@ {@b@ Object[] arrayOfObject = new Object[this.elements.length];@b@ System.arraycopy(this.elements, 0, arrayOfObject, 0, this.elements.length);@b@ return arrayOfObject;@b@ }@b@@b@ public Object[] toArray(Object[] paramArrayOfObject)@b@ {@b@ if (paramArrayOfObject.length < this.elements.length) {@b@ paramArrayOfObject = (Object[])Array.newInstance(paramArrayOfObject.getClass().getComponentType(), this.elements.length);@b@ }@b@@b@ System.arraycopy(this.elements, 0, paramArrayOfObject, 0, this.elements.length);@b@ if (paramArrayOfObject.length > this.elements.length)@b@ paramArrayOfObject[this.elements.length] = null;@b@@b@ return paramArrayOfObject;@b@ }@b@@b@ public boolean add(Object paramObject)@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public boolean remove(Object paramObject)@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public boolean containsAll(Collection paramCollection)@b@ {@b@ Iterator localIterator = paramCollection.iterator();@b@ while (localIterator.hasNext())@b@ if (!(contains(localIterator.next())))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public boolean addAll(Collection paramCollection)@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public boolean retainAll(Collection paramCollection)@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public boolean removeAll(Collection paramCollection)@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public void clear()@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public boolean equals(Object paramObject)@b@ {@b@ return ((this == paramObject) || ((paramObject instanceof Set) && (((Collection)paramObject).size() == this.elements.length) && (containsAll((Collection)paramObject))));@b@ }@b@@b@ public int hashCode()@b@ {@b@ return Constraint.hash(this.elements);@b@ }@b@@b@ public String toString()@b@ {@b@ return Constraint.toString(this.elements);@b@ }@b@@b@ static Object[] access$000(ArraySet paramArraySet)@b@ {@b@ return paramArraySet.elements;@b@ }@b@@b@ private final class Iter@b@ implements Iterator@b@ {@b@ private int idx = 0;@b@ private final ArraySet this$0;@b@@b@ public boolean hasNext()@b@ {@b@ return (this.idx < ArraySet.access$000(this.this$0).length);@b@ }@b@@b@ public Object next()@b@ {@b@ if (this.idx < ArraySet.access$000(this.this$0).length)@b@ return ArraySet.access$000(this.this$0)[(this.idx++)];@b@@b@ throw new NoSuchElementException();@b@ }@b@@b@ public void remove()@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@ }@b@}