GeoSoft API

no.geosoft.cc.directory
Class Folder

Object
  |
  +--DirectoryEntry
        |
        +--Folder
All Implemented Interfaces:
Comparable

public class Folder
extends DirectoryEntry

A class representing a generic folder node within a directory structure. A folder may contain DirectoryEnty children and may have a client specified item back-end object.

Author:
GeoSoft

Constructor Summary
Folder()
          Create a namelsee and itemless folder entry.
Folder(Object item)
          Create a folder with name according to item toString().
Folder(Object item, String name)
          Create a new folder entry.
 
Method Summary
 void add(Collection entries)
          Add a set of entries to this folder.
 void add(DirectoryEntry entry)
          Add an entry to the end of this folder.
 void add(DirectoryEntry entry, int index)
          Add an entry to this folder at a specific position.
 void addSorted(Collection entries)
          Add a set of entries sorted alphabetically according to the entries' toString() method.
 void addSorted(DirectoryEntry entry)
          Add an entry sorted alphabetically according to the entrys toString() method.
 void collapse()
          Identify this folder as "collapsed".
 void collapseAll()
          Identify this folder and all sub folders as "collapsed".
 boolean contains(DirectoryEntry entry)
          Recursively check if an entry is descendant of this folder.
 void expand()
          Identify this folder as "expanded".
 void expandAll()
          Identify this folder and all sub folders as "expanded".
 DirectoryEntry find(String name)
          Find a given node among the immediate children of this folder.
 DirectoryEntry findEntry(Object item)
          Return entry based on item value.
 Folder findFolder(Object item)
          Return sub folder based on item value.
 Folder findFolder(String name)
          Find a given folder among the immediate children of this folder.
 DirectoryEntry findGlobal(String name)
          Find a given node within the entire subtree of this folder.
 List getEntries()
          Get the entries of this folder.
 DirectoryEntry getEntry(int index)
          Return the child entry at the specific position.
 DirectoryEntry getGlobalEntry(int entryNo)
          Staring from this node, return the index'th element in the tree, traversing depth first.
 int getGlobalIndexOfEntry(DirectoryEntry entry)
          Starting from here, return the entry number of the specified entry traversing depth first.
 int getIndexOfEntry(DirectoryEntry entry)
          Return position of the specified entry.
 int getNEntries()
          Return number of entries in this folder.
 boolean isEmpty()
          Check if the folder is empty (has no children).
 boolean isLeaf()
          Return true if this is a leaf node.
 boolean isRoot()
          Return true if this is a root node.
 void print(int indent)
           
 void remove(DirectoryEntry entry)
          Remove entry from this folder.
 
Methods inherited from class DirectoryEntry
compareTo, equals, getItem, getName, getParent, getPath, isFolder, setItem, setName, toString
 
Methods inherited from class Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Folder

public Folder(Object item,
              String name)
Create a new folder entry.

Parameters:
item - Client specific item of the folder.
name - Name of the folder.

Folder

public Folder(Object item)
Create a folder with name according to item toString().

Parameters:
item - Client specific item of the folder.

Folder

public Folder()
Create a namelsee and itemless folder entry.

Method Detail

add

public void add(DirectoryEntry entry,
                int index)
Add an entry to this folder at a specific position. NOTE: Entries can have one parent only.

Parameters:
entry - Entry to add.
index - Entry position, 0 is first, etc.

add

public void add(DirectoryEntry entry)
Add an entry to the end of this folder.

Parameters:
entry - Entry to add.

add

public void add(Collection entries)
Add a set of entries to this folder.

Parameters:
entries - Entries to add.

addSorted

public void addSorted(DirectoryEntry entry)
Add an entry sorted alphabetically according to the entrys toString() method.

Parameters:
entry - Entry to add.

addSorted

public void addSorted(Collection entries)
Add a set of entries sorted alphabetically according to the entries' toString() method.


remove

public void remove(DirectoryEntry entry)
Remove entry from this folder.

Parameters:
entry - Entry to remove.

isLeaf

public boolean isLeaf()
Return true if this is a leaf node. A folder is per definition not a leaf node even if empty, so this method always return false.

Specified by:
isLeaf in class DirectoryEntry
Returns:
False always.

isRoot

public boolean isRoot()
Return true if this is a root node. A node is root if it doesn't have a parent node.

Returns:
True if this is a root node, false otherwise.

getEntry

public DirectoryEntry getEntry(int index)
Return the child entry at the specific position. Return null if the entry does not exists.

Parameters:
index - Position of entry to return.
Returns:

getGlobalEntry

public DirectoryEntry getGlobalEntry(int entryNo)
Staring from this node, return the index'th element in the tree, traversing depth first.

Parameters:
entryNo - Entry number to find.
Returns:

getGlobalIndexOfEntry

public int getGlobalIndexOfEntry(DirectoryEntry entry)
Starting from here, return the entry number of the specified entry traversing depth first. Return -1 if not found.

Parameters:
entry - Entry to find entry number of.
Returns:
Entry number of specified entry (or -1 if not found).

getIndexOfEntry

public int getIndexOfEntry(DirectoryEntry entry)
Return position of the specified entry. Null if entry does not exist.

Parameters:
entry - Entry to find index of.
Returns:

isEmpty

public boolean isEmpty()
Check if the folder is empty (has no children).

Returns:
True if the folder is empty, false otherwise.

getNEntries

public int getNEntries()
Return number of entries in this folder.

Returns:
Number of entries in this folder.

getEntries

public List getEntries()
Get the entries of this folder.

Returns:
The entries of this folder (List of DirectoryEntry)

contains

public boolean contains(DirectoryEntry entry)
Recursively check if an entry is descendant of this folder.

Parameters:
entry - Entry to check.
Returns:
True if the entry is a descendant of this folder, false otherwise.

find

public DirectoryEntry find(String name)
Find a given node among the immediate children of this folder.

Parameters:
name - Name of child to find.
Returns:
Directory entry of searched node (or null if not found).

findGlobal

public DirectoryEntry findGlobal(String name)
Find a given node within the entire subtree of this folder.

Parameters:
name - Name of node to find.
Returns:
Directory entry of searched node (or null if not found).

findFolder

public Folder findFolder(String name)
Find a given folder among the immediate children of this folder.

Parameters:
name - Name of folder to find.
Returns:
The searched folder (or null if not found).

findFolder

public Folder findFolder(Object item)
Return sub folder based on item value. Search the entire sub tree from this folder.

Parameters:
item - Item of the folder to find.
Returns:
Searched folder (or null if not found).

findEntry

public DirectoryEntry findEntry(Object item)
Return entry based on item value. Search the entire sub tree from this folder.

Parameters:
item - Item of the entry to find.
Returns:
Searched entry (or null if not found).

expand

public void expand()
Identify this folder as "expanded". This setting may be used in a GUI front-end module.


expandAll

public void expandAll()
Identify this folder and all sub folders as "expanded". This setting may be used in a GUI front-end module.


collapse

public void collapse()
Identify this folder as "collapsed". This setting may be used in a GUI front-end module.


collapseAll

public void collapseAll()
Identify this folder and all sub folders as "collapsed". This setting may be used in a GUI front-end module.


print

public void print(int indent)
Specified by:
print in class DirectoryEntry

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no