123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import java.util.* ;
-
- public class Dossier extends Node {
- // Liste des éléments contenus
- ArrayList<Node> elements = new ArrayList<Node>();
-
- public Dossier (String path, int depth) {
- super(path, 0, depth);
- this.depth = depth;
- Iterator<String> son;
- String p;
- long s = 0;
- long sum = 0;
- try {
- son = FileInfo.getElements(path);
- }
- catch (java.io.IOException e) {
- son = null;
- }
- while (son.hasNext()) {
- p = son.next();
- try {
- s = FileInfo.size(p);
- sum += s;
- }
- catch (java.io.IOException e) {}
-
- if (this.depth + 1 <= maxDepth && nbNode <= maxNode){
- if (FileInfo.isFile(p)) {
- elements.add(new Fichier(p, s, this.depth + 1));
- }
- else
- elements.add(new Dossier(p, this.depth + 1));
- }
- }
- Collections.sort(this.elements, comparator);
- this.size = sum;
- }
-
- Comparator<Node> comparator = new Comparator<Node>() {
- @Override public int compare(Node node1, Node node2) {
- return node1.name.compareTo(node2.name);
- }
- };
-
- @Override public void afficher() {
- System.out.println("+ (DIR) " + this.name + "[total = " + size + " octets]");
- for (Node i : elements) {
- if (i.depth <= maxDepth){
- for (int j = 0; j < depth; ++j){
- System.out.print(" ");
- }
- i.afficher();
- }
- }
- }
- }
|