All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.umlg.runtime.collection.persistent.UmlgSetClosableIterableImpl Maven / Gradle / Ivy

There is a newer version: 2.0.16
Show newest version
package org.umlg.runtime.collection.persistent;

import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.umlg.runtime.collection.UmlgRuntimeProperty;
import org.umlg.runtime.collection.UmlgSet;
import org.umlg.runtime.domain.UmlgMetaNode;
import org.umlg.runtime.domain.UmlgNode;

import java.lang.reflect.Method;
import java.util.Iterator;

public class UmlgSetClosableIterableImpl extends BaseSet implements UmlgSet {

	private Iterator iterator;

	public UmlgSetClosableIterableImpl(Iterator iterator, UmlgRuntimeProperty runtimeProperty) {
		super(runtimeProperty);
		this.iterator = iterator;
	}

	@Override
	protected Iterator getEdges() {
		return null;
	}

	@Override
	public boolean add(E e) {
		throw new IllegalStateException("This set is read only! It is constructed from a indexed search result");
	}

	@Override
	public boolean remove(Object o) {
		throw new IllegalStateException("This set is read only! It is constructed from a indexed search result");
	}

    @Override
    @SuppressWarnings({ "unchecked", "rawtypes" })
    protected void loadFromVertex() {
        for (Iterator iter = this.iterator; iter.hasNext(); ) {
            Vertex vertex = iter.next();
            E node;
            try {
                Class c = Class.forName((String) vertex.value("className"));
                if (c.isEnum()) {
                    throw new RuntimeException();
                } else if (UmlgMetaNode.class.isAssignableFrom(c)) {
                    Method m = c.getDeclaredMethod("getInstance", new Class[0]);
                    node = (E) m.invoke(null);
                } else if (UmlgNode.class.isAssignableFrom(c)) {
                    node = (E) c.getConstructor(Vertex.class).newInstance(vertex);
                } else {
                    throw new RuntimeException();
                }
                this.internalCollection.add(node);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy