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

com.alterioncorp.jpa.entitygraphbuilder.RelationshipTree Maven / Gradle / Ivy

The newest version!
package com.alterioncorp.jpa.entitygraphbuilder;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.EntityGraph;

class RelationshipTree {
	
	private final Set rootNodes = new HashSet<>();

	public void addToGraph(EntityGraph entityGraph) {
		for (RelationshipNode root : rootNodes) {
			root.addToGraph(entityGraph);
		}
	}
	
	public Set getRootNodes() {
		return rootNodes;
	}
	
	public RelationshipNode getRootNode(String value) {
		for (RelationshipNode root : rootNodes) {
			if (root.getValue().equals(value)) {
				return root;
			}
		}
		return null;
	}
	
	public void addNode(RelationshipNode node) {
		boolean merged = false;
		for (RelationshipNode root : rootNodes) {
			if (root.merge(node)) {
				merged = true;
				break;
			}
		}
		if (! merged) {
			rootNodes.add(node);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy