Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/eclipse/jdt/util/PersistentFolder.java


1   package com.port80.eclipse.jdt.util;
2   
3   import java.sql.Timestamp;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   /**
8    * Persistent folder holds PersistentItem objects as children.
9    * 
10   * @author chrisl
11   */
12  public class PersistentFolder extends PersistentItem {
13  
14    ////////////////////////////////////////////////////////////////////////
15  
16    private List children = new ArrayList();
17  
18    ////////////////////////////////////////////////////////////////////////
19  
20    public PersistentFolder(String name) {
21      super(FOLDER, name);
22    }
23    public Object[] getChildren() {
24      return children.toArray();
25    }
26    public int getChildrenCount() {
27      return children.size();
28    }
29    public boolean hasChildren() {
30      if (children.size() == 0)
31        return false;
32      return true;
33    }
34    public void addChild(PersistentItem child) {
35      children.add(child);
36      child.setParent(this.getName());
37    }
38    public boolean removeChild(PersistentItem child) {
39      return (child != null && children.remove(child));
40    }
41    public PersistentItem removeOldestChild() {
42      Object a;
43      PersistentItem child;
44      int index = -1;
45      Timestamp atime = null;
46      for (int i = 0; i < children.size(); ++i) {
47        a = children.get(i);
48        if (a instanceof PersistentFolder)
49          continue;
50        child = (PersistentItem) a;
51        if (atime == null || child.getATime().before(atime)) {
52          atime = child.getATime();
53          index = i;
54        }
55      }
56      if (index >= 0) {
57        child = (PersistentItem) children.remove(index);
58        return child;
59      } else
60        return null;
61    }
62  
63    ////////////////////////////////////////////////////////////////////////
64  }