Java Code Examples for com.tinkerpop.blueprints.Vertex#getClass()

The following examples show how to use com.tinkerpop.blueprints.Vertex#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DominoGraph.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public Set<IEdgeHelper> findHelpers(final Vertex in, final Vertex out) {
	Set<IEdgeHelper> result = new FastSet<IEdgeHelper>();
	if (in == null || out == null) {
		return result;
	}
	Class<?> inCls = in.getClass();
	Class<?> outCls = out.getClass();
	for (IEdgeHelper helper : edgeHelpers_.values()) {
		boolean inChk = helper.getInType().isAssignableFrom(inCls);
		boolean outChk = helper.getOutType().isAssignableFrom(outCls);
		if (inChk && outChk) {
			result.add(helper);
		}
	}
	return result;
}
 
Example 2
Source File: AbstractEdgeHelper.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public Set<? extends Vertex> getOtherVertexes(final Vertex vertex) {
	Set<Vertex> result = new LinkedHashSet<Vertex>();
	Class<?> vclass = vertex.getClass();
	Direction od = null;
	if (getInType().equals(vclass))
		od = Direction.OUT;
	if (od == null && getOutType().equals(vclass))
		od = Direction.IN;
	if (od == null && getInType().isAssignableFrom(vclass))
		od = Direction.OUT;
	if (od == null && getOutType().isAssignableFrom(vclass))
		od = Direction.IN;
	if (od == null) {
		throw new EdgeHelperException(vertex.getClass().getName() + " is not a participating type in edge " + getLabel());
	} else {
		Set<? extends Edge> edges = getEdges(vertex);
		for (Edge edge : edges) {
			result.add(edge.getVertex(od));
		}
		return Collections.unmodifiableSet(result);
	}
}
 
Example 3
Source File: AbstractEdgeHelper.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public Set<Vertex> getOtherVertexesByEdge(final Vertex vertex, final String... sortproperties) {
	Set<Vertex> result = new LinkedHashSet<Vertex>();
	Class<?> vclass = vertex.getClass();
	Direction od = null;
	if (getInType().equals(vclass))
		od = Direction.OUT;
	if (od == null && getOutType().equals(vclass))
		od = Direction.IN;
	if (od == null && getInType().isAssignableFrom(vclass))
		od = Direction.OUT;
	if (od == null && getOutType().isAssignableFrom(vclass))
		od = Direction.IN;
	if (od == null) {
		throw new EdgeHelperException(vertex.getClass().getName() + " is not a participating type in edge " + getLabel());
	} else {
		SortedSet<? extends Edge> edges = getSortedEdges(vertex, sortproperties);
		for (Edge edge : edges) {
			result.add(edge.getVertex(od));
		}
		return Collections.unmodifiableSet(result);
	}
}
 
Example 4
Source File: AbstractEdgeHelper.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
@Override
public Edge findEdge(final/*@Nonnull*/Vertex defaultOut, final/*@Nonnull*/Vertex defaultIn) {
	Edge result = null;
	Vertex inVert = null;
	Vertex outVert = null;
	boolean inExact = false;
	boolean outExact = false;
	boolean inPartial = false;
	boolean outPartial = false;
	boolean reinExact = false;
	boolean reoutExact = false;
	boolean reinPartial = false;
	boolean reoutPartial = false;
	Class<?> inClass = defaultIn.getClass();
	Class<?> outClass = defaultOut.getClass();
	Class<?> inType = getInType();
	Class<?> outType = getOutType();
	if (defaultOut == null || defaultIn == null)
		throw new EdgeHelperException("Cannot create edges with null vertex");
	if (defaultOut.getClass().equals(defaultIn.getClass()) && isSameTypes()) {
		inVert = defaultIn;
		outVert = defaultOut;
	} else {
		inExact = inType.equals(inClass);
		outExact = outType.equals(outClass);
		inPartial = inType.isAssignableFrom(inClass);
		outPartial = outType.isAssignableFrom(outClass);
		reinExact = outType.equals(inClass);
		reoutExact = inType.equals(outClass);
		reinPartial = outType.isAssignableFrom(inClass);
		reoutPartial = inType.isAssignableFrom(outClass);

		if (inExact && outExact) {	//perfect
			inVert = defaultIn;
			outVert = defaultOut;
		} else if ((inExact && outPartial) || (outExact && inPartial)) {  //good enough
			inVert = defaultIn;
			outVert = defaultOut;
		} else if (inPartial && outPartial) {
			if (reinExact || reoutExact) {	//invert
				inVert = defaultOut;
				outVert = defaultIn;
			} else {	//it'll do
				inVert = defaultIn;
				outVert = defaultOut;
			}
		}

		if (inVert == null || outVert == null) {
			if (reinExact && reoutExact) {	//perfectly backwards
				inVert = defaultOut;
				outVert = defaultIn;
			} else if ((reinExact && reoutPartial) || (reoutExact && reinPartial)) {  //backwards, with inheritance
				inVert = defaultOut;
				outVert = defaultIn;
			} else if (reinPartial && reoutPartial) {	//inversion works, so we'll settle for it.
				inVert = defaultOut;
				outVert = defaultIn;
			}
		}

		if (inVert == null || outVert == null) {
			StringBuilder sb = new StringBuilder();
			sb.append("Label: ");
			sb.append(getLabel());
			sb.append(" intype: ");
			sb.append(inType.getSimpleName());
			sb.append(" outtype: ");
			sb.append(outType.getSimpleName());
			sb.append(" invert: ");
			sb.append(inClass.getSimpleName());
			sb.append(" outvert: ");
			sb.append(outClass.getSimpleName());
			sb.append(" inE: ");
			sb.append(inExact);
			sb.append(" outE: ");
			sb.append(outExact);
			sb.append(" inP: ");
			sb.append(inPartial);
			sb.append(" outP: ");
			sb.append(outPartial);
			sb.append(" reinE: ");
			sb.append(reinExact);
			sb.append(" reoutE: ");
			sb.append(reoutExact);
			sb.append(" reinP: ");
			sb.append(reinPartial);
			sb.append(" reoutP: ");
			sb.append(reoutPartial);
			throw new EdgeHelperException("Cannot create an edge - " + sb.toString());
		}
	}
	result = parent_.getEdge(outVert, inVert, getLabel());
	return result;
}