com.tinkerpop.blueprints.impls.dex.DexIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blueprints-dex-graph Show documentation
Show all versions of blueprints-dex-graph Show documentation
Blueprints property graph implementation for the DEX graph database
/**
*
*/
package com.tinkerpop.blueprints.impls.dex;
import com.tinkerpop.blueprints.CloseableIterable;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* {@link Iterable} {@link DexElement} collection implementation for Dex.
*
* It is just a wrapper for Dex Objects class.
*
* This collections are registered into the {@link DexGraph} to be automatically
* closed when the database is stopped.
*
* @param
* @author Sparsity
* Technologies
*/
class DexIterable implements CloseableIterable {
private DexGraph graph;
private com.sparsity.dex.gdb.Objects iterable;
private Class clazz;
private final List iterators = new ArrayList();
public DexIterable(final DexGraph g, final com.sparsity.dex.gdb.Objects iterable, final Class clazz) {
this.graph = g;
this.iterable = iterable;
this.clazz = clazz;
this.graph.register(this);
}
@Override
public Iterator iterator() {
final DexIterator itty = new DexIterator();
this.iterators.add(itty);
return itty;
}
/**
* Close the collection closes iterators too.
*/
public void close() {
for (final DexIterator itty : iterators) {
itty.close();
}
iterable.close();
graph.unregister(this);
iterable = null;
graph = null;
}
private class DexIterator implements Iterator {
private com.sparsity.dex.gdb.ObjectsIterator itty = iterable.iterator();
@Override
public boolean hasNext() {
return itty.hasNext();
}
@Override
public T next() {
long oid = itty.next();
if (oid == -1)
throw new NoSuchElementException();
T ret = null;
if (clazz == Vertex.class) {
ret = (T) new DexVertex(graph, oid);
} else if (clazz == Edge.class) {
ret = (T) new DexEdge(graph, oid);
} else if (clazz == Element.class) {
ret = (T) new DexElement(graph, oid);
} else {
throw new IllegalStateException();
}
return ret;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
public void close() {
itty.close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy