org.nakedobjects.object.collection
Class AbstractNakedCollection

java.lang.Object
  extended byjava.util.Observable
      extended byorg.nakedobjects.object.AbstractNakedObject
          extended byorg.nakedobjects.object.collection.AbstractNakedCollection
All Implemented Interfaces:
java.io.Externalizable, Naked, NakedCollection, NakedObject, java.io.Serializable
Direct Known Subclasses:
ArbitraryCollection, TypedCollection

public abstract class AbstractNakedCollection
extends AbstractNakedObject
implements NakedCollection

This is the new type of collection for Naked Objects. It is designed to work efficiently is a distributed envirmoment by providing a window on a logical collection. This collection is therefore just a cache of a subset of the complete collection. The real collection is maintained by the ObjectStore. Within this cache there is also a viewing window, which the user is expected to be viewing. As the user pages through the cache more items will be retrieved as the bounds of the cache are hit.

See Also:
to set the size of the viewing window., to set the size of the cache. To move through the collection on a page-by-page basis, first(), next(), last(), previous(), Serialized Form

Constructor Summary
AbstractNakedCollection()
           
 
Method Summary
 void add(NakedObject object)
          adds object to the collection and notifies all views that the collection has changed.
 void addAll(NakedCollection collection)
          Add all elements from the collection.
 void added(NakedObject object)
           
abstract  Permission canAdd(NakedObject object)
          Vetos the addition to this collection if the object being added requests it.
abstract  Permission canRemove(NakedObject object)
          Vetos the removal from this collection if the object being removed requests it.
 boolean contains(NakedObject object)
          Returns true if the logical collection contains the specified object.
 java.util.Enumeration displayElements()
          Return cache to be viewed on current page
 java.util.Enumeration elements()
          Return all elements in this collection
 ArbitraryCollection extract()
          Return an ArbitraryCollection with the same elements as this collection
 void first()
          Position cursor at first element
 int getDisplaySize()
           
 int getMaxCacheSize()
          returns the maximum number of elements to hold from the logical collection.
 boolean hasNext()
          If true there is a next page to display, and 'next' and 'last' options are valid
 boolean hasPrevious()
           
 boolean isEmpty()
          Returns true if the object contains no data, eg when new
 void last()
          Position cursor at last
 void next()
          Position cursor at beginning of next page
 int position()
           
 void previous()
          Position cursor at beginning of previous page
 void remove(NakedObject object)
          removes object from the collection and notifies all views that the collection has changed.
 void removeAll()
          Removes all objects from the collection.
 void removed(NakedObject object)
           
 void reset()
           
 AbstractNakedCollection search(NakedObject pattern)
          Return a NakedCollection of objects which match the specified pattern from within the current collection
 void setDisplaySize(int displaySize)
          Set the size of the display or viewing window.
 void setMaxCacheSize(int maxCacheSize)
          Sets the maximum size of the cache providing the specified size is greater than the display size.
 int size()
          Return a NakedCollection of objects which match the specified pattern from within the current collection
 Title title()
          by default returns the collections name and its number of elements
 
Methods inherited from class org.nakedobjects.object.AbstractNakedObject
about, aboutExplorationActionClass, aboutExplorationActionClone, aboutExplorationActionMakePersistent, canClone, contextualTitle, copyObject, created, createInstance, createInstance, createTransientInstance, deleted, destroy, equals, explorationActionClass, explorationActionClone, explorationActionMakePersistent, getClassHelpText, getClassName, getCollectiveName, getFullClassName, getIconName, getIdString, getNakedClass, getObjectHelpText, getObjectStore, getOid, hashCode, iconImage, init, isFinder, isLookupElement, isPersistent, isResolved, isSameAs, isValid, makeFinder, makePersistent, objectChanged, readExternal, resolve, resolve, setChangedAndNotifyObservers, setOid, setResolved, summary, toString, writeExternal
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.nakedobjects.object.NakedCollection
copyObject
 
Methods inherited from interface org.nakedobjects.object.NakedObject
addObserver, contextualTitle, countObservers, created, deleted, deleteObserver, destroy, getCollectiveName, getIdString, getNakedClass, getObjectStore, getOid, hasChanged, iconImage, isFinder, isLookupElement, isPersistent, isResolved, makeFinder, makePersistent, objectChanged, resolve, setChangedAndNotifyObservers, setOid, setResolved
 
Methods inherited from interface org.nakedobjects.object.Naked
about, getClassName, getFullClassName, getObjectHelpText, isSameAs, isValid, summary
 

Constructor Detail

AbstractNakedCollection

public AbstractNakedCollection()
Method Detail

setDisplaySize

public void setDisplaySize(int displaySize)
Set the size of the display or viewing window. If the cache size is less than the display size the max cache size will also be set to specified size.


getDisplaySize

public int getDisplaySize()
Specified by:
getDisplaySize in interface NakedCollection
Returns:
int

isEmpty

public boolean isEmpty()
Description copied from interface: Naked
Returns true if the object contains no data, eg when new

Specified by:
isEmpty in interface Naked
Overrides:
isEmpty in class AbstractNakedObject

setMaxCacheSize

public void setMaxCacheSize(int maxCacheSize)
Sets the maximum size of the cache providing the specified size is greater than the display size.


getMaxCacheSize

public int getMaxCacheSize()
returns the maximum number of elements to hold from the logical collection.


add

public void add(NakedObject object)
Description copied from interface: NakedCollection
adds object to the collection and notifies all views that the collection has changed.

Specified by:
add in interface NakedCollection

added

public void added(NakedObject object)
Specified by:
added in interface NakedCollection

canAdd

public abstract Permission canAdd(NakedObject object)
Description copied from interface: NakedCollection
Vetos the addition to this collection if the object being added requests it. Returns the result of canAddTo() called on the object reference. Also disallows the addition of itself. By default a collection can be added to another collection (but not to itself). Any type of object which wishes to restrict its placement in a collection should override this method.

Specified by:
canAdd in interface NakedCollection

canRemove

public abstract Permission canRemove(NakedObject object)
Description copied from interface: NakedCollection
Vetos the removal from this collection if the object being removed requests it. Returns the result of canRemoveFrom() called on the object reference.

Specified by:
canRemove in interface NakedCollection

contains

public boolean contains(NakedObject object)
Returns true if the logical collection contains the specified object.

Specified by:
contains in interface NakedCollection

displayElements

public java.util.Enumeration displayElements()
Return cache to be viewed on current page

Specified by:
displayElements in interface NakedCollection

elements

public java.util.Enumeration elements()
Return all elements in this collection

Specified by:
elements in interface NakedCollection

extract

public ArbitraryCollection extract()
Return an ArbitraryCollection with the same elements as this collection


first

public void first()
Position cursor at first element

Specified by:
first in interface NakedCollection

hasNext

public boolean hasNext()
If true there is a next page to display, and 'next' and 'last' options are valid

Specified by:
hasNext in interface NakedCollection

hasPrevious

public boolean hasPrevious()
Specified by:
hasPrevious in interface NakedCollection

last

public void last()
Position cursor at last

Specified by:
last in interface NakedCollection

next

public void next()
Position cursor at beginning of next page

Specified by:
next in interface NakedCollection

position

public int position()
Specified by:
position in interface NakedCollection

previous

public void previous()
Position cursor at beginning of previous page

Specified by:
previous in interface NakedCollection

remove

public void remove(NakedObject object)
Description copied from interface: NakedCollection
removes object from the collection and notifies all views that the collection has changed.

Specified by:
remove in interface NakedCollection

removed

public void removed(NakedObject object)
Specified by:
removed in interface NakedCollection

reset

public void reset()
Specified by:
reset in interface NakedCollection

search

public AbstractNakedCollection search(NakedObject pattern)
Return a NakedCollection of objects which match the specified pattern from within the current collection


size

public int size()
Description copied from interface: NakedCollection
Return a NakedCollection of objects which match the specified pattern from within the current collection

Specified by:
size in interface NakedCollection

title

public Title title()
Description copied from interface: NakedCollection
by default returns the collections name and its number of elements

Specified by:
title in interface NakedCollection
Overrides:
title in class AbstractNakedObject
See Also:
AbstractNakedObject.contextualTitle()

addAll

public void addAll(NakedCollection collection)
Add all elements from the collection. If the reference to the collection is null, then does nothing.

Implementation note: this code is not threadsafe and does not synchronize on either itself or the collection passed in.


removeAll

public void removeAll()
Removes all objects from the collection.

Implementation note: this code is not threadsafe; it does not synchronize on itself.

Implemented by invoking remove(NakedObject) on each object