Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Directory extends Elm {
- private Elm[] contents;
- private int idx;
- public Directory (String name){
- super(name);
- contents = new Elm[100];
- }
- public void add(Elm e){
- if (idx < 100){
- contents[idx]=e;
- idx++;
- e.setParent(this);
- }
- }
- public void show() {
- for (Elm e : contents)
- if (e != null)
- System.out.println(e.name);
- }
- public Elm search(String name) {
- if (this.name.equals(name))
- return this;
- for (Elm e : contents)
- if (e!=null && e.name.equals(name))
- return e;
- for (Elm e : contents)
- if (e!=null && e instanceof Directory)
- if (((Directory)e).search(name)!=null)
- return e;
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement