@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Location other = (Location) obj; if (getId() == null) { if (other.getId() != null) return false; } else if (!getId().equals(other.getId())) return false; return true; }
private void buildTree(Location root, TreeNode attach) { if (root != null && root.getChildren() != null) { for (Location child : root.getChildren()) { TreeNode node = new DefaultTreeNode(child, attach); if (logger.isDebugEnabled()) { logger.debug(String.format("Tree node created to bind %s with %s", root, attach)); } buildTree(child, node); } } }
public Location findLocationById(Long id) { if (this.getId() != null && this.getId().equals(id)) { return this; } if (hasChildren()) { for (Location child : children) { Location found = child.findLocationById(id); if (found != null) { return found; } } } return null; }
public void removeLocation() { while (hasChildren()) { for (Location child : children) { child.removeLocation(); child = null; } } if (parent != null) { parent.children.remove(this); if (parent.children.isEmpty()) { parent.children = null; } parent = null; } }
public void updateLocation(Location newLoc) { Location loc = findLocationById(newLoc.getId()); if (loc != null) { if (loc.parent != null) { loc.parent.children.remove(loc); loc.parent.children.add(newLoc); } if (loc.children != null) { for (Location child : children) { child.parent = newLoc; } } newLoc.parent = loc.parent; newLoc.children = loc.children; } }