1
/* DirectoryNode.java -- Structure for maintaining the cache directory tree.
2
Copyright (C) 2010 Red Hat, Inc.
4
This file is part of IcedTea.
6
IcedTea is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, version 2.
10
IcedTea is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with IcedTea; see the file COPYING. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
Linking this library statically or dynamically with other modules is
21
making a combined work based on this library. Thus, the terms and
22
conditions of the GNU General Public License cover the whole
25
As a special exception, the copyright holders of this library give you
26
permission to link this library with independent modules to produce an
27
executable, regardless of the license terms of these independent
28
modules, and to copy and distribute the resulting executable under
29
terms of your choice, provided that you also meet, for each linked
30
independent module, the terms and conditions of the license of that
31
module. An independent module is a module which is not derived from
32
or based on this library. If you modify this library, you may extend
33
this exception to your version of the library, but you are not
34
obligated to do so. If you do not wish to do so, delete this
35
exception statement from your version.
37
package net.sourceforge.jnlp.cache;
40
import java.util.ArrayList;
42
public class DirectoryNode {
45
private ArrayList<DirectoryNode> childNodes;
46
private DirectoryNode parent = null;
47
private File infoFile;
50
* Create a new instance of DirectoryNode.
52
* @param name Name representing this node.
53
* @param absPathToNode Absolute path to this node given as a String.
54
* @param parent The parent node.
56
public DirectoryNode(String name, String absPathToNode, DirectoryNode parent) {
57
this(name, new File(absPathToNode), parent);
61
* Create a new instance of DirectoryNode.
63
* @param name Name representing this node.
64
* @param absPathToNode Absolute path to this node as a File.
65
* @param parent The parent node.
67
public DirectoryNode(String name, File absPathToNode, DirectoryNode parent) {
68
this(name, absPathToNode, null, parent);
72
* Create a new instance of DirectoryNode.
74
* @param name Name representing this node.
75
* @param absPathToNode Absolute path to this node given as a File.
76
* @param childNodes List of children nodes.
77
* @param parent The parent node.
79
public DirectoryNode(String name, File absPathToNode, ArrayList<DirectoryNode> childNodes, DirectoryNode parent) {
81
this.path = absPathToNode;
82
this.childNodes = childNodes;
83
if (this.childNodes == null)
84
this.childNodes = new ArrayList<DirectoryNode>();
87
this.infoFile = new File(this.getFile().getAbsolutePath().concat(".info"));
91
* Append the given node to the list of child nodes.
93
* @param node Node to be appended.
95
public void addChild(DirectoryNode node) {
98
} catch (NullPointerException e) {
99
this.childNodes = new ArrayList<DirectoryNode>();
100
this.childNodes.add(node);
105
* Removes the node specified.
107
* @param node Node to be removed from the list of children
108
* @return true if this list of children contained the specified element
110
public boolean removeChild(DirectoryNode node) {
111
return this.childNodes.remove(node);
115
* Retrieve the name of this node.
117
* @return Name of this node.
119
public String getName() {
123
public String toString() {
128
* Retrieve the file associated with this node.
130
* @return File that is associated with this node.
132
public File getFile() {
137
* Retrieve the parent node.
139
* @return DirectoryNode representing the parent of the current node.
141
public DirectoryNode getParent() {
146
* Retrieves the list of child nodes.
148
* @return ArrayList of type DirectoryNode containing all the child nodes.
150
public ArrayList<DirectoryNode> getChildren() {
151
return this.childNodes;
155
* Check if this node is a directory.
157
* @return True if node is directory.
159
public boolean isDir() {
160
return path.isDirectory();
163
public File getInfoFile() {
164
return this.infoFile;