|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.catalog.Catalog<I,G,C>
public abstract class Catalog<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
A generic catalog. In addition to holding a collection of catalog
items
, this catalog supports the notion of
groups
of catalog items.
Version Info:
$Revision: 2204 $ |
$Date: 2009-04-16 11:58:16 -0600 (Thu, 16 Apr 2009) $ |
$Author: dharland $ (last person to modify) |
Constructor Summary | |
---|---|
Catalog()
Helps create a new catalog with a default name. |
|
Catalog(String nameOfCatalog)
Helps create a new catalog with the given name. |
Method Summary | |
---|---|
boolean |
addGroup(G newGroup)
Adds a new group to this catalog. |
boolean |
addGroup(int index,
G newGroup)
Adds a new group to this catalog at the specified position. |
boolean |
addGroups(Collection<? extends G> newGroups)
Adds newGroups to this catalog. |
boolean |
addGroups(int index,
Collection<? extends G> newGroups)
Adds newGroups to this catalog at the specified position. |
I |
addItem(I newItem)
Adds a new item to this catalog. |
I |
addItem(int index,
I newItem)
Adds a new item to this catalog at the specified position. |
I |
addItemEvenIfEqualToCurrentItem(I newItem)
Adds newItem even if this catalog already has an item to which
it is equal. |
I |
addItemEvenIfEqualToCurrentItem(int index,
I newItem)
Adds newItem even if this catalog already has an item to which
it is equal. |
Collection<I> |
addItems(Collection<? extends I> newItems)
Adds newItems to this catalog. |
Collection<I> |
addItems(int index,
Collection<? extends I> newItems)
Adds newItems to this catalog at the specified position. |
void |
addListener(CatalogListener<I,G,C> newListener)
Adds newListener to this catalog list. |
void |
clear()
Removes all groups and all items from this catalog. |
void |
clearId()
Resets this catalog's ID, and the IDs of all its groups, to a value that represents the unidentified state. |
C |
clone()
Returns a catalog that is a copy of this one. |
boolean |
contains(I item)
Returns true if this catalog holds item . |
boolean |
containsGroupNamed(String name)
Returns true if this catalog contains a group with the given name . |
abstract G |
createGroup()
Returns a group of the same type of items used by this catalog. |
protected abstract G |
createMainGroup()
Creates and returns a new group to use as the holder of items for this catalog. |
G |
decrementIndexOfGroup(G group)
Moves group to an index one lower than its current index. |
G |
decrementIndexOfGroupAt(int index)
Moves the group at index to an index of index -minus-one. |
I |
decrementIndexOfItem(I item)
Moves item to an index one lower than its current index. |
I |
decrementIndexOfItemAt(int index)
Moves the item at index to an index of index -minus-one. |
boolean |
equals(Object o)
Returns true if o is equal to this catalog. |
G |
getGroup(int index)
Returns the group at the given position. |
G |
getGroup(String groupName)
Returns a group with the given name, or null if this catalog has no such group. |
List<G> |
getGroups()
Returns a list of this catalog's groups. |
List<G> |
getGroupsThatContain(I item)
Returns a list of groups that contain item . |
Long |
getId()
Returns this catalog's ID. |
protected long |
getIdOfUnidentified()
Returns a value that represents an undefined ID. |
protected List<G> |
getInternalGroupList()
Returns the internal group list. |
protected List<I> |
getInternalItemList()
Returns the internal item list. |
I |
getItem(int index)
Returns the item at the given position. |
List<I> |
getItems()
Returns a list of this catalog's items. |
String |
getName()
Returns the name of this catalog. |
List<String> |
getNotes()
Returns a list of notes about this catalog. |
String |
getReservedGroupName()
Returns the name that this catalog uses for its special group. |
int |
hashCode()
Returns a hash code value for this catalog. |
G |
incrementIndexOfGroup(G group)
Moves group to an index one higher than its current index. |
G |
incrementIndexOfGroupAt(int index)
Moves the group at index to an index of index -plus-one. |
I |
incrementIndexOfItem(I item)
Moves item to an index one higher than its current index. |
I |
incrementIndexOfItemAt(int index)
Moves the item at index to an index of index -plus-one. |
int |
indexOf(I item)
Returns the index of the first occurence of item in this catalog. |
int |
lastIndexOf(I item)
Returns the index of the lasst occurence of item in this catalog. |
void |
memberAdded(G group,
I newMember,
int index)
Called after newMember was added to group . |
void |
memberMoved(G group,
I member,
int fromIndex,
int toIndex)
Called after member was moved from one location to another
within group . |
void |
memberRemoved(G group,
I formerMember,
int index)
Called after formerMember was removed from group . |
void |
memberReplaced(G group,
I formerMember,
I newMember,
int index)
Called after the member located at index was replaced by
another member. |
void |
membersSorted(G group)
Called after the members of this group were sorted. |
G |
moveGroup(G group,
int toIndex)
Moves group toIndex . |
G |
moveGroup(int fromIndex,
int toIndex)
Moves a group fromIndex toIndex . |
I |
moveItem(I item,
int toIndex)
Moves item toIndex . |
I |
moveItem(int fromIndex,
int toIndex)
Moves an item fromIndex toIndex . |
void |
removeAllGroups()
Removes all groups from this catalog. |
void |
removeAllItems()
Removes all items from this catalog and its groups, but does not remove the groups themselves. |
void |
removeAllListeners()
Removes all listeners from this catalog. |
G |
removeGroup(G group)
Removes group from this catalog. |
G |
removeGroup(int index)
Removes the group at index from this catalog. |
I |
removeItem(I item)
Removes item from this catalog, if present. |
I |
removeItem(int index)
Removes the item found at index . |
void |
removeListener(CatalogListener<I,G,C> listener)
Removes listener from this catalog's list. |
protected void |
setId(Long id)
Sets the ID of this catalog. |
protected void |
setInternalGroupList(List<G> replacementList)
Replaces the internal group list with replacementList . |
protected void |
setInternalItemList(List<I> replacementList)
Replaces the internal item list with replacementList . |
void |
setName(String newName)
Sets the name of this catalog. |
protected void |
setReservedGroupName(String reservedName)
Sets the name that this catalog will treat as a reserved name. |
int |
size()
Returns the number of items in this catalog. |
void |
sort(Comparator<? super I> comparator)
Uses comparator to sort the items of this catalog. |
void |
sortGroups(Comparator<? super G> comparator)
Uses comparator to sort the members of this group. |
List<G> |
swapGroups(int index1,
int index2)
Swaps the groups at the given positions. |
List<I> |
swapItems(int index1,
int index2)
Swaps the items at the given positions. |
protected void |
tellListenersAboutFormerGroup(G formerGroup,
int index)
|
protected void |
tellListenersAboutMovedGroup(G group,
int fromIndex,
int toIndex)
|
protected void |
tellListenersAboutNewGroup(G newGroup,
int index)
|
G |
toGroup()
Creates and returns a group that has the same items in the same order as this catalog. |
String |
toString()
Returns a text representation of this catalog. |
String |
toXml()
Returns an XML representation of this catalog. |
void |
writeAsXmlTo(Writer writer)
Writes an XML representation of this catalog to writer . |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Catalog()
public Catalog(String nameOfCatalog)
nameOfCatalog
- the name of this catalog. If this value is
null, this catalog will be given a
default name.Method Detail |
---|
protected abstract G createMainGroup()
public abstract G createGroup()
protected void setId(Long id)
id
is null, this catalog's
ID will be set to an unidentified ID.
id
- a new ID for this catalog.protected long getIdOfUnidentified()
public void clearId()
CatalogItem
does not implement the Identifiable
interface. Subclasses of this catalog whose items are
Identifiable should override this method, call
super.clearId(), then clear the IDs of their items.
This method is useful for preparing a catalog for storage in a database. The ID property (as of now, though this may change in the future) is used by our persistence mechanism to identify objects. If you are persisting this catalog for the first time, you may need to call this method before performing a save. This is especially true if you have created this source from XML, as the XML unmarshalling brings along the ID property.
public Long getId()
public void setName(String newName)
If newName
is null or the empty string
(""), the request to change the name will be
denied and the current name will remain in place.
newName
- the new name for this catalog.public String getName()
public List<String> getNotes()
This method returns the list actually held by this Catalog
, so
any list manipulations may be performed by first fetching the list and
then operating on it.
public I addItem(I newItem)
newItem
- a new item for this catalog.
newItem
if this
catalog contains no item equal to newItem
, or the
first item in this catalog that is equal to newItem
.public I addItem(int index, I newItem)
index
- the position at which to insert the new item.newItem
- a prospective new item in this catalog.
newItem
if this
catalog contains no item equal to newItem
, or the
first item in this catalog that is equal to newItem
.public Collection<I> addItems(Collection<? extends I> newItems)
newItems
to this catalog.
Only non-null elements of newItems
that are not
already part of this catalog are classified as new items.
newItems
- new items in this catalog.
public Collection<I> addItems(int index, Collection<? extends I> newItems)
newItems
to this catalog at the specified position.
Only non-null elements of newItems
that are not
already part of this catalog are classified as new items.
index
- the position at which to insert the first new item.
Subsequent new items are added at successive positions.newItems
- new items in this catalog.
public I addItemEvenIfEqualToCurrentItem(I newItem)
newItem
even if this catalog already has an item to which
it is equal. Contrast this with addItem(CatalogItem)
.
The only times newItem
is not added to this catalog are
when it is null and when a reference to it is already contained
in this catalog.
newItem
- a potential new item for this catalog.
newItem
.public I addItemEvenIfEqualToCurrentItem(int index, I newItem)
newItem
even if this catalog already has an item to which
it is equal. Contrast this with addItem(int, CatalogItem)
.
The only times newItem
is not added to this catalog are
when it is null and when a reference to it is already contained
in this catalog.
index
- the position at which to add newItem
.newItem
- a potential new item for this catalog.
newItem
.public boolean addGroup(G newGroup)
This catalog is now enforcing uniqueness for the names of its groups.
If newGroup
has the same name as a group that is already in
this catalog, a side effect of this add
method is
that newGroup
's name will be changed to
newGroup.getName() + " (Copy #)", where "#" is the
nth duplication of this name.
newGroup
- a new group of items for this catalog.
newGroup
is nullnewGroup
is already a part of this catalogpublic boolean addGroup(int index, G newGroup)
This catalog is now enforcing uniqueness for the names of its groups.
If newGroup
has the same name as a group that is already in
this catalog, a side effect of this add
method is
that newGroup
's name will be changed to
newGroup.getName() + " (Copy #)", where "#" is the
nth duplication of this name.
index
- the position at which to insert the new group.newGroup
- a new group of items for this catalog.
newGroup
is nullnewGroup
is already a part of this catalogpublic boolean addGroups(Collection<? extends G> newGroups)
newGroups
to this catalog.
This is a convenience method that is the equivalent of iterating over
newGroups
and calling addGroup(CatalogItemGroup)
.
newGroups
- new groups in this catalog.
public boolean addGroups(int index, Collection<? extends G> newGroups)
newGroups
to this catalog at the specified position.
This is a convenience method that is the equivalent of iterating over
newGroups
and calling addGroup(int, CatalogItemGroup)
.
index
- the position at which to insert the first new group.
Subsequent new groups are added at successive positions.newGroups
- new groups in this catalog.
protected void tellListenersAboutNewGroup(G newGroup, int index)
public I removeItem(I item)
item
from this catalog, if present.
The item
is also removed from every group of this catalog in which it is present.
item
- the item that is to be removed from this catalog.
item
if it had been an item in this catalog,
null if it had not.public I removeItem(int index)
index
.
index
- the index of the item to be removed.
public G removeGroup(G group)
group
from this catalog.
Note that the items held by group
are not removed
from this catalog.
group
- the group that is to be removed from this catalog.
group
if it had belonged to this catalog and was
able to be removed, null otherwise.public G removeGroup(int index)
index
from this catalog.
Note that the items held by group
are not removed
from this catalog.
index
- the index of the group to be removed.
index
if it was
able to be removed, null otherwise.public void removeAllGroups()
removeAllItems()
,
clear()
public void removeAllItems()
removeAllGroups()
,
clear()
public void clear()
removeAllItems()
,
removeAllGroups()
protected void tellListenersAboutFormerGroup(G formerGroup, int index)
public I incrementIndexOfItem(I item)
item
to an index one higher than its current index.
The item will not be moved if it is not in this catalog, or if
it is already in the highest position.
If item
is in this catalog in multiple positions, the instance
with the highest index will be moved.
item
- the item to be moved.
item
, or an equal item that was already part of
this catalog.public I decrementIndexOfItem(I item)
item
to an index one lower than its current index.
The item will not be moved if it is not in this catalog, or if
it is already in the lowest position.
If item
is in this catalog in multiple positions, the instance
with the lowest index will be moved.
item
- the item to be moved.
item
, or an equal item that was already part of
this catalog.public I incrementIndexOfItemAt(int index)
index
to an index of index
-plus-one.
No move will occur if index
is out of bounds, or if it is already
the highest index of this catalog.
index
- the index of the item to be moved.
public I decrementIndexOfItemAt(int index)
index
to an index of index
-minus-one.
No move will occur if index
is out of bounds, or if it is already
the lowest index of this catalog.
index
- the index of the item to be moved.
public List<I> swapItems(int index1, int index2)
If the indices are equal, no action is taken.
If one or both of the indices are not in the range
[0,size()), the underlying List
will throw
an exception.
index1
- the position of the one of the items.index2
- the position of another of the items.
public I moveItem(int fromIndex, int toIndex)
fromIndex
toIndex
.
fromIndex
- the current index of an item.toIndex
- the new index of that same item.
public I moveItem(I item, int toIndex)
item
toIndex
.
item
- the item to be moved.toIndex
- the new position for item
.
item
or,
alternatively, an item equal to item
,
if this catalog has such an item.public void sort(Comparator<? super I> comparator)
comparator
to sort the items of this catalog.
comparator
- used to order this catalog's items.public G incrementIndexOfGroup(G group)
group
to an index one higher than its current index.
The group will not be moved if it is not in this catalog, or if
it is already in the highest position.
If group
is in this catalog in multiple positions, the instance
with the highest index will be moved. (It is not generally
possible for a group to occupy multiple positions in a catalog.) Note
that the special group that holds all items of this catalog may
not be moved.
group
- the group to be moved.
group
, or an equal group that was already part of
this catalog.public G decrementIndexOfGroup(G group)
group
to an index one lower than its current index.
The group will not be moved if it is not in this catalog, or if
it is already in the lowest position.
If group
is in this catalog in multiple positions, the instance
with the lowest index will be moved. (It is not generally
possible for a group to occupy multiple positions in a catalog.) Note
that the special group that holds all items of this catalog may
not be moved.
group
- the group to be moved.
group
, or an equal group that was already part of
this catalog.public G incrementIndexOfGroupAt(int index)
index
to an index of index
-plus-one.
No move will occur if index
is out of bounds, or if it is already
the highest index of this catalog.
index
- the index of the group to be moved.
public G decrementIndexOfGroupAt(int index)
index
to an index of index
-minus-one.
No move will occur if index
is out of bounds, or if it is already
the lowest index of this catalog.
index
- the index of the group to be moved.
public List<G> swapGroups(int index1, int index2)
If the indices are equal, no action is taken.
If one or both of the indices are not in the range
[0,size()), the underlying List
will throw
an exception.
index1
- the position of the one of the groups.index2
- the position of another of the groups.
public G moveGroup(int fromIndex, int toIndex)
fromIndex
toIndex
.
fromIndex
- the current index of a group.toIndex
- the new index of that same group.
public G moveGroup(G group, int toIndex)
group
toIndex
.
group
- the group to be moved.toIndex
- the new position for group
.
public void sortGroups(Comparator<? super G> comparator)
comparator
to sort the members of this group.
comparator
- used to order this group's membersprotected void tellListenersAboutMovedGroup(G group, int fromIndex, int toIndex)
public int size()
public I getItem(int index)
index
- the position of the item to return.
index
.public List<I> getItems()
Note that the returned list is not held internally by this catalog. This means that any changes made to the returned list will not be reflected in this object. The elements of the list, though, are the actual items of this catalog, so changes made to them will be reflected in this catalog.
protected List<I> getInternalItemList()
protected
, as opposed to
private
, so that subclasses can create and annotate
methods that call this one.
protected void setInternalItemList(List<I> replacementList)
replacementList
.
This method is meant solely for use by frameworks (such
as JAXB or Hibernate) that rely on getX/setX pairs for
persisted properties. It is protected
, as opposed to
private
, so that subclasses can create and annotate
methods that call this one.
public boolean contains(I item)
item
.
item
- a possible item in this catalog.
item
.public int indexOf(I item)
item
in this catalog.
See List.indexOf(Object)
for more details.
item
- a potential item of this catalog
item
in this catalog,
or -1 if this catalog does not contain item
.public int lastIndexOf(I item)
item
in this catalog.
See List.lastIndexOf(Object)
for more details.
item
- a potential item of this catalog
item
in this catalog,
or -1 if this catalog does not contain item
.public G getGroup(int index)
index
- the position of the group to return.
index
.public G getGroup(String groupName)
groupName
- the name of group potentially in this catalog.
public List<G> getGroups()
Note that the returned list is not held internally by this catalog. This means that any changes made to the returned list will not be reflected in this object. The elements of the list, though, are the actual groups of this catalog, so changes made to them will be reflected in this catalog.
public List<G> getGroupsThatContain(I item)
item
.
item
- an item of this catalog that may be in one or more groups.
item
.public boolean containsGroupNamed(String name)
name
.
name
- potential name of a group contained by this catalog.
name
.protected List<G> getInternalGroupList()
protected
, as opposed to
private
, so that subclasses can create and annotate
methods that call this one.
protected void setInternalGroupList(List<G> replacementList)
replacementList
.
This method is meant solely for use by frameworks (such
as JAXB or Hibernate) that rely on getX/setX pairs for
persisted properties. It is protected
, as opposed to
private
, so that subclasses can create and annotate
methods that call this one.
public String getReservedGroupName()
protected void setReservedGroupName(String reservedName)
reservedName
- the name this catalog will use for its special
group. If this value is null, this catalog
will use a default name in its place.public void addListener(CatalogListener<I,G,C> newListener)
newListener
to this catalog list.
The listener will be informed whenever:
newListener
- the listener to be added to this catalog's list.public void removeListener(CatalogListener<I,G,C> listener)
listener
from this catalog's list.
listener
- the listener to be removed from this catalog's list.public void removeAllListeners()
public void memberAdded(G group, I newMember, int index)
CatalogItemGroupListener
newMember
was added to group
.
memberAdded
in interface CatalogItemGroupListener<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
group
- the group to which a new member was added.newMember
- the new member added to group
.index
- the index at which the new member was added.public void memberRemoved(G group, I formerMember, int index)
CatalogItemGroupListener
formerMember
was removed from group
.
memberRemoved
in interface CatalogItemGroupListener<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
group
- the group from which a member was removed.formerMember
- the member removed from group
.index
- the index at which the former member had been located.public void memberMoved(G group, I member, int fromIndex, int toIndex)
CatalogItemGroupListener
member
was moved from one location to another
within group
.
It is anticipated that most implementations of
CatalogItemGroup
will send this message only for the
member that instigated the change in this list. For example,
if the last member of the list was moved to the first position in
the list, only one message will be sent, even though every member
of the list is now in a new position. The message sent for this
example would be for the member now in the first position.
memberMoved
in interface CatalogItemGroupListener<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
group
- the group in which the movement occurred.member
- the member whose position changed.fromIndex
- the position at which the member had been located.toIndex
- the position at which the member is now located.public void memberReplaced(G group, I formerMember, I newMember, int index)
CatalogItemGroupListener
index
was replaced by
another member.
memberReplaced
in interface CatalogItemGroupListener<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
group
- the group in which the replacement occurred.formerMember
- the member that had been located at index
.newMember
- the member that is now located at index
.index
- the position at which the replacement occurred.public void membersSorted(G group)
CatalogItemGroupListener
membersSorted
in interface CatalogItemGroupListener<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
group
- the group whose members were sorted.public String toString()
toString
in class Object
public String toXml() throws JAXBException
JAXBException
- if anything goes wrong during the conversion to XML.public void writeAsXmlTo(Writer writer) throws JAXBException
writer
.
writer
- the device to which XML is written.
JAXBException
- if anything goes wrong during the conversion to XML.public G toGroup()
public C clone()
The returned catalog has items and groups with the same properties as those of this catalog, but those items and groups are new and distinct from those held herein.
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
public boolean equals(Object o)
o
is equal to this catalog.
equals
in class Object
public int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |