1 package org.kuali.common.util.tree; 2 3 import static org.kuali.common.util.base.Precondition.checkNotNull; 4 5 import java.util.List; 6 7 public final class ImmutableNode<T> extends MutableNode<T> { 8 9 private static final String UOE_MSG = "not supported for immutable node's"; 10 11 public static <T> ImmutableNode<T> copyOf(Node<T> node) { 12 return new ImmutableNode<T>(node); 13 } 14 15 public ImmutableNode(Node<T> node) { 16 checkNotNull(node, "node"); 17 super.setElement(node.getElement()); 18 List<Node<T>> children = node.getChildren(); 19 for (Node<T> child : children) { 20 super.add(children.size(), copyOf(child)); 21 } 22 } 23 24 @Override 25 public void setElement(T element) { 26 throw new UnsupportedOperationException(UOE_MSG); 27 } 28 29 @Override 30 public void add(List<MutableNode<T>> children) { 31 throw new UnsupportedOperationException(UOE_MSG); 32 } 33 34 @Override 35 public void add(MutableNode<T> child1, MutableNode<T> child2) { 36 throw new UnsupportedOperationException(UOE_MSG); 37 } 38 39 @Override 40 public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3) { 41 throw new UnsupportedOperationException(UOE_MSG); 42 } 43 44 @Override 45 public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3, MutableNode<T> child4) { 46 throw new UnsupportedOperationException(UOE_MSG); 47 } 48 49 @Override 50 public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3, MutableNode<T> child4, MutableNode<T> child5) { 51 throw new UnsupportedOperationException(UOE_MSG); 52 } 53 54 @Override 55 public void add(MutableNode<T> child) { 56 throw new UnsupportedOperationException(UOE_MSG); 57 } 58 59 @Override 60 public void add(int index, MutableNode<T> child) { 61 throw new UnsupportedOperationException(UOE_MSG); 62 } 63 64 @Override 65 public void remove(MutableNode<T> child) { 66 throw new UnsupportedOperationException(UOE_MSG); 67 } 68 69 @Override 70 public void remove(int index) { 71 throw new UnsupportedOperationException(UOE_MSG); 72 } 73 74 @Override 75 public void removeAllChildren() { 76 throw new UnsupportedOperationException(UOE_MSG); 77 } 78 79 @Override 80 public void removeFromParent() { 81 throw new UnsupportedOperationException(UOE_MSG); 82 } 83 84 }