wtanaka.praya.obj
Class NormalFolder

java.lang.Object
  |
  +--wtanaka.praya.obj.Obj
        |
        +--wtanaka.praya.obj.NormalFolder
All Implemented Interfaces:
java.io.Externalizable, Fillable, java.io.Serializable
Direct Known Subclasses:
LimitFolder, ReadOnlyFolder, SystemFolder

public class NormalFolder
extends Obj
implements Fillable, java.io.Externalizable

This is simply a folder that stores messages in some order. Objs may be added, they get put at the end of the folder. The messages may be sorted. The contents of the folder may be examined, and Objs may be removed.

Return to Sourceforge or the Praya Homepage

Version:
$Name: $ $Date: 2001/12/26 03:02:15 $
Author:
$Author: wtanaka $
See Also:
LimitFolder, ReadOnlyFolder, SystemFolder, Serialized Form

Field Summary
private  java.util.Vector folderListeners
           
private  java.util.Vector m_storage
          Container of all children of this folder.
(package private) static int MAGIC_NUMBER
          Random (/dev/urandom) magic number for serialized instances of this class.
protected  java.lang.String name
           
 NormalFolder parent
           
(package private) static long serialVersionUID
          Serial Version UID
private  int sortKey
          This member variable keeps track of which key to sort on.
 
Fields inherited from class wtanaka.praya.obj.Obj
CONTENTS, date, DATE, FROM, privThread, REVCONTENTS, REVDATE, REVFROM, REVSCORE, REVSUBJECT, SCORE, secretObject, SUBJECT
 
Constructor Summary
NormalFolder()
          Constructs a new, initially empty root folder.
NormalFolder(NormalFolder parent)
          Constructs a new, initially empty subfolder.
 
Method Summary
 void add(Obj a)
          Adds the given object to the end of this folder.
 void addFolderListener(FolderListener fl)
           
 java.util.Enumeration elements()
          Gives the contents of the folder.
private  void fireAdded(int firstIndex, int lastIndex)
          Informs folder listeners that o was added to this folder.
private  void fireRemoved(int firstIndex, int lastIndex)
          Informs folder listeners that o was removed from this folder.
 Obj getChildAt(int index)
          Gets a child of this folder.
 java.lang.String getContents()
          Used to render this folder as an obj.
 java.lang.String getName()
           
 int getNumChildren()
           
 NormalFolder getParent()
           
 int indexOf(Obj foo)
           
 boolean isTrashCanUsed()
          Whether or not removed messages should be placed in the trash.
private  void mergeSort(int start, int end, Obj[] tmp)
           
 void readExternal(java.io.ObjectInput in)
           
 void remove(FolderSelectionModel selection)
          Removes selected items from the folder.
 void remove(int i)
          Removes the object at the given index from the folder.
 void remove(Obj a)
          Removes the given object from the folder.
 void removeFolderListener(FolderListener fl)
           
private  void selectSort()
          Runs a selection sort on the folder, using sortKey as the key to sort on.
 void setName(java.lang.String name)
           
 void sort(int key)
          Sorts the contents of this folder, based on the key given by the parameter.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class wtanaka.praya.obj.Obj
getFrom, getSubject, getTimeStamp, isPrivileged, lessThan, setPrivilegedThread, setSecretObject, setTimeStamp
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
Serial Version UID

MAGIC_NUMBER

static final int MAGIC_NUMBER
Random (/dev/urandom) magic number for serialized instances of this class.

m_storage

private java.util.Vector m_storage
Container of all children of this folder. This is private to prevent a malicious user from subclassing and twiddling with system folders.

parent

public transient NormalFolder parent

folderListeners

private transient java.util.Vector folderListeners

sortKey

private int sortKey
This member variable keeps track of which key to sort on.

name

protected java.lang.String name
Constructor Detail

NormalFolder

public NormalFolder()
Constructs a new, initially empty root folder.

NormalFolder

public NormalFolder(NormalFolder parent)
Constructs a new, initially empty subfolder. The folder containing it will be passed in as parent.
Method Detail

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException - if we encounter an error reading or a corrupted stream.
java.lang.ClassNotFoundException - if we read in a class name on the input stream that we can't resolve.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable

addFolderListener

public void addFolderListener(FolderListener fl)

removeFolderListener

public void removeFolderListener(FolderListener fl)

fireRemoved

private void fireRemoved(int firstIndex,
                         int lastIndex)
Informs folder listeners that o was removed from this folder.

fireAdded

private void fireAdded(int firstIndex,
                       int lastIndex)
Informs folder listeners that o was added to this folder.

getParent

public NormalFolder getParent()

add

public void add(Obj a)
Adds the given object to the end of this folder.
Specified by:
add in interface Fillable
Parameters:
a - the object to add to the folder. It cannot be null.

remove

public void remove(Obj a)
Removes the given object from the folder.
Parameters:
a - the object to remove from the folder.

remove

public void remove(int i)
Removes the object at the given index from the folder.
Parameters:
the - index of the object to remove from the folder.

remove

public void remove(FolderSelectionModel selection)
Removes selected items from the folder. This is a way to remove a lot of elements in O(N) time instead of O(N^2)

selectSort

private void selectSort()
Runs a selection sort on the folder, using sortKey as the key to sort on.

mergeSort

private void mergeSort(int start,
                       int end,
                       Obj[] tmp)

sort

public void sort(int key)
Sorts the contents of this folder, based on the key given by the parameter. For instance, if the key is Obj.DATE, then the sort will be by date.

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

getChildAt

public Obj getChildAt(int index)
Gets a child of this folder.
Specified by:
getChildAt in interface Fillable
Returns:
the indexth child of this folder.
Throws:
ArrayIndexOutOfBoundsException - if the given child does not exist.

getNumChildren

public int getNumChildren()
Specified by:
getNumChildren in interface Fillable

indexOf

public int indexOf(Obj foo)

getContents

public java.lang.String getContents()
Used to render this folder as an obj.
Overrides:
getContents in class Obj

elements

public java.util.Enumeration elements()
Gives the contents of the folder.
Returns:
an Enumeration of Obj, the contents of this folder.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isTrashCanUsed

public boolean isTrashCanUsed()
Whether or not removed messages should be placed in the trash.
Returns:
true if we should put removed messages in the trash (for instance for most normal folders) false if we should kill them (for instance, for the trash can and protocol folders)