-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
147 lines (130 loc) · 2.95 KB
/
Copy pathNode.java
File metadata and controls
147 lines (130 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Created on 18-10-2003 by jesper
* This class should
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.JarEntry;
/**
* @author jesper
*/
public class Node implements Comparable {
public String name;
private Node parent;
TreeSet children = null;
private boolean isPackage, isFile;
public int level;
public boolean isAdded = false;
public JarEntry jarEntry = null;
public String fullPath ="";
public String fileType = "";
public String content = "";
public Node(){
children = new TreeSet();
}
public Node(String name, Node parent, boolean isPackage){
children = new TreeSet();
this.name = name;
this.parent = parent;
this.isPackage = isPackage;
this.isFile = !isPackage;
this.fileType = FileTypes.getFileType(name);
}
public int getChildCount(){
return children.size();
}
public void addChild(Node n){
children.add(n);
}
public boolean isFile() {
return isFile;
}
public boolean isPackage() {
return isPackage;
}
public String getName() {
return name;
}
public Node getParent() {
return parent;
}
public String getAllInfo(){
String s =
(isPackage() ? "Package " : "File ")+ "name="
+ getName()
+ " Parent=";
if(getParent()== null){
s+= "TOP";
}else{
s+= getParent().getName();
}
s+= " ChildCount="
+ children.size();
return s;
}
public String toString(){
return this.name;
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
* Compares this object with the specified object for order.
* Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than
* the specified object.
*/
public int compareTo(Object arg0) {
Node toCompare = (Node)arg0;
if(toCompare.name.equals(this.name)){
return 0;
}else{
return -1;
}
}
public boolean equals(Object arg0){
Node toCompare = (Node)arg0;
if(toCompare.name.equals(this.name) && toCompare.fullPath.equals(this.fullPath) ){
return true;
}else{
return false;
}
}
/**
* @param b
*/
public void setFile(boolean b) {
isFile = b;
isPackage = !b;
}
/**
* @param b
*/
public void setPackage(boolean b) {
isPackage = b;
isFile = !b;
}
/**
* @param node
*/
public void setParent(Node node) {
parent = node;
}
public Node getChild(Node n){
for (Iterator iter = children.iterator(); iter.hasNext();) {
Node element = (Node) iter.next();
if(element.getName().equals(n.getName())){
return element;
}
}
return null;
}
public boolean hasChild(Node n){
for (Iterator iter = children.iterator(); iter.hasNext();) {
Node element = (Node) iter.next();
if(element.getName().equals(n.getName())){
return true;
}
}
return false;
}
}