org.jvnet.jaxbcommons.lang.impl.DefaultVisitedObjects Maven / Gradle / Ivy
package org.jvnet.jaxbcommons.lang.impl;
import org.jvnet.jaxbcommons.lang.VisitedObjects;
public class DefaultVisitedObjects implements VisitedObjects {
private int size;
private transient Object[] elementData;
public DefaultVisitedObjects(int initialCapacity) {
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity);
this.elementData = new Object[initialCapacity];
}
public DefaultVisitedObjects() {
this(10);
}
public boolean isVisited(Object object) {
for (int i = 0; i < size; i++) {
if (object == elementData[i])
return true;
}
return false;
}
public void addVisited(Object object) {
ensureCapacity(size + 1);
elementData[size++] = object;
}
private void ensureCapacity(int minCapacity) {
int oldCapacity = elementData.length;
if (minCapacity > oldCapacity) {
Object oldData[] = elementData;
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity)
newCapacity = minCapacity;
elementData = new Object[newCapacity];
System.arraycopy(oldData, 0, elementData, 0, size);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy