]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/expression/node/Node.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.common / src / org / simantics / spreadsheet / common / expression / node / Node.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /* This file was generated by SableCC (http://www.sablecc.org/). */
13
14 package org.simantics.spreadsheet.common.expression.node;
15
16 import java.util.*;
17
18 @SuppressWarnings("nls")
19 public abstract class Node implements Switchable, Cloneable
20 {
21     private Node parent;
22
23     @Override
24     public abstract Object clone();
25
26     public Node parent()
27     {
28         return this.parent;
29     }
30
31     void parent(@SuppressWarnings("hiding") Node parent)
32     {
33         this.parent = parent;
34     }
35
36     abstract void removeChild(Node child);
37     abstract void replaceChild(Node oldChild, Node newChild);
38
39     public void replaceBy(Node node)
40     {
41         this.parent.replaceChild(this, node);
42     }
43
44     protected String toString(Node node)
45     {
46         if(node != null)
47         {
48             return node.toString();
49         }
50
51         return "";
52     }
53
54     protected String toString(List list)
55     {
56         StringBuffer s = new StringBuffer();
57
58         for(Iterator i = list.iterator(); i.hasNext();)
59         {
60             s.append(i.next());
61         }
62
63         return s.toString();
64     }
65
66     @SuppressWarnings("unchecked")
67     protected <T extends Node> T cloneNode(T node)
68     {
69         if(node != null)
70         {
71             return (T) node.clone();
72         }
73
74         return null;
75     }
76
77     protected <T> List<T> cloneList(List<T> list)
78     {
79         List<T> clone = new LinkedList<T>();
80
81         for(T n : list)
82         {
83             clone.add(n);
84         }
85
86         return clone;
87     }
88 }