class AttributeSource {
/** Returns a new iterator that iterates all unique Attribute implementations.
* This iterator may contain less entries that {@link #getAttributeClassesIterator},
* if one instance implements more than one Attribute interface.
* <p>Signature for Java 1.5: <code>public Iterator<AttributeImpl> getAttributeImplsIterator()</code>
*/
public Iterator getAttributeImplsIterator() {
if (hasAttributes()) {
if (currentState == null) {
computeCurrentState();
}
final State initState = currentState;
return new Iterator() {
private State state = initState;
public void remove() {
throw new UnsupportedOperationException();
}
public Object next() {
if (state == null)
throw new NoSuchElementException();
final AttributeImpl att = state.attribute;
state = state.next;
return att;
}
public boolean hasNext() {
return state != null;
}
};
} else {
return Collections.EMPTY_SET.iterator();
}
}
}
class AttributeSource {
private void computeCurrentState() {
currentState = new State();
State c = currentState;
Iterator it = attributeImpls.values().iterator();
c.attribute = (AttributeImpl) it.next();
while (it.hasNext()) {
c.next = new State();
c = c.next;
c.attribute = (AttributeImpl) it.next();
}
}
}