View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.tree;
17  
18  import static org.kuali.common.util.base.Precondition.checkNotNull;
19  
20  import java.util.List;
21  
22  public final class ImmutableNode<T> extends MutableNode<T> {
23  
24  	private static final String UOE_MSG = "not supported for immutable node's";
25  
26  	public static <T> ImmutableNode<T> copyOf(Node<T> node) {
27  		return new ImmutableNode<T>(node);
28  	}
29  
30  	public ImmutableNode(Node<T> node) {
31  		checkNotNull(node, "node");
32  		super.setElement(node.getElement());
33  		List<Node<T>> children = node.getChildren();
34  		for (Node<T> child : children) {
35  			super.add(children.size(), copyOf(child));
36  		}
37  	}
38  
39  	@Override
40  	public void setElement(T element) {
41  		throw new UnsupportedOperationException(UOE_MSG);
42  	}
43  
44  	@Override
45  	public void add(List<MutableNode<T>> children) {
46  		throw new UnsupportedOperationException(UOE_MSG);
47  	}
48  
49  	@Override
50  	public void add(MutableNode<T> child1, MutableNode<T> child2) {
51  		throw new UnsupportedOperationException(UOE_MSG);
52  	}
53  
54  	@Override
55  	public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3) {
56  		throw new UnsupportedOperationException(UOE_MSG);
57  	}
58  
59  	@Override
60  	public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3, MutableNode<T> child4) {
61  		throw new UnsupportedOperationException(UOE_MSG);
62  	}
63  
64  	@Override
65  	public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3, MutableNode<T> child4, MutableNode<T> child5) {
66  		throw new UnsupportedOperationException(UOE_MSG);
67  	}
68  
69  	@Override
70  	public void add(MutableNode<T> child) {
71  		throw new UnsupportedOperationException(UOE_MSG);
72  	}
73  
74  	@Override
75  	public void add(int index, MutableNode<T> child) {
76  		throw new UnsupportedOperationException(UOE_MSG);
77  	}
78  
79  	@Override
80  	public void remove(MutableNode<T> child) {
81  		throw new UnsupportedOperationException(UOE_MSG);
82  	}
83  
84  	@Override
85  	public void remove(int index) {
86  		throw new UnsupportedOperationException(UOE_MSG);
87  	}
88  
89  	@Override
90  	public void removeAllChildren() {
91  		throw new UnsupportedOperationException(UOE_MSG);
92  	}
93  
94  	@Override
95  	public void removeFromParent() {
96  		throw new UnsupportedOperationException(UOE_MSG);
97  	}
98  
99  }