Advertisement
Xesevi

Untitled

Jul 6th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.  
  2. public class Directory extends Elm {
  3.  private Elm[] contents;
  4.  private int idx;
  5.  public Directory (String name){
  6.      super(name);
  7.      contents = new Elm[100];
  8.  }
  9.  public void add(Elm e){
  10.      if (idx < 100){
  11.      contents[idx]=e;
  12.      idx++;
  13.       e.setParent(this);
  14.      }
  15.  }
  16. public void show() {
  17.     for (Elm e : contents)
  18.         if (e != null)
  19.             System.out.println(e.name);
  20.  }
  21. public Elm search(String name) {
  22.   if (this.name.equals(name))
  23.       return this;
  24.   for (Elm e : contents)
  25.       if (e!=null && e.name.equals(name))
  26.           return e;
  27.   for (Elm e : contents)
  28.       if (e!=null && e instanceof Directory)
  29.           if (((Directory)e).search(name)!=null)
  30.               return e;
  31.   return null;
  32.  }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement