|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.catalog.CatalogItemGroup<I,G,C>
public class CatalogItemGroup<I extends CatalogItem<I>,G extends CatalogItemGroup<I,G,C>,C extends Catalog<I,G,C>>
A grouping of catalog items
.
A CatalogItemGroup
is normally contained in a
Catalog
and is a way of collecting together
items that have similar traits.
Version Info:
$Revision: 2232 $ |
$Date: 2009-04-23 13:38:46 -0600 (Thu, 23 Apr 2009) $ |
$Author: dharland $ (last person to modify) |
Constructor Summary | |
---|---|
|
CatalogItemGroup()
Creates a new group with a default name and that belongs to no catalog. |
protected |
CatalogItemGroup(C container)
Special constructor used only by Catalog for constructing its main group. |
|
CatalogItemGroup(C container,
String nameOfGroup)
Creates a new group that belongs to container . |
Method Summary | |
---|---|
I |
add(I newMember)
Adds a new member to this group. |
I |
add(int index,
I newMember)
Adds a new member to this group at the specified position. |
Collection<I> |
addAll(Collection<? extends I> newMembers)
Adds the collection of newMembers to this group. |
Collection<I> |
addAll(int index,
Collection<? extends I> newMembers)
Adds the collection of newMembers to this group at the
specified position. |
I |
addEvenIfEqualToCurrentMember(I newMember)
Adds newMember even if this group already has a member to which it
is equal. |
I |
addEvenIfEqualToCurrentMember(int index,
I newMember)
Adds newMember at the specified position
even if this group already has a member to which it
is equal. |
void |
addListener(CatalogItemGroupListener<I,G,C> newListener)
Adds newListener to this group's list. |
void |
clear()
Removes all members from this group. |
protected boolean |
clearlyNotEqualTo(Object o)
|
G |
clone()
Returns a group that is a copy of this one. |
protected G |
cloneAllExceptMembers()
Clones this group but does not add any members to the new group. |
G |
cloneIntoSameCatalog()
Clones this group and adds it to the same catalog to which it belongs. |
boolean |
contains(I member)
Returns true if member belongs to this group. |
protected void |
copyPropertiesFrom(G otherGroup)
Copies some properties of otherGroup into this one. |
I |
decrementIndexOf(I member)
Moves member to an index one lower than its current index. |
I |
decrementIndexOfMemberAt(int index)
Moves the member at index to an index of index -minus-one. |
boolean |
equals(Object o)
Returns true if o is equal to this group. |
boolean |
equalsWithoutRespectToOrder(Object o)
Returns true if o is equal to this group in all respects
with the possible exception of the ordering of the members. |
I |
get(int index)
Returns the member at the given position. |
List<I> |
getAll()
Returns a list of this group's members. |
C |
getCatalog()
Returns the catalog to which this group belongs, if any. |
Long |
getId()
Returns this group's ID. |
protected long |
getIdOfUnidentified()
Returns a value that represents an undefined ID. |
protected List<I> |
getInternalMemberList()
Returns the internal list of members. |
String |
getName()
Returns the name of this group. |
protected boolean |
getNameIsLocked()
Returns true if the ability to change this group's name is restricted. |
List<String> |
getNotes()
Returns a list of notes about this group. |
boolean |
hasCatalog()
Returns true if this group has a non-null catalog. |
int |
hashCode()
Returns a hash code value for this group. |
I |
incrementIndexOf(I member)
Moves member to an index one higher than its current index. |
I |
incrementIndexOfMemberAt(int index)
Moves the member at index to an index of index -plus-one. |
int |
indexOf(I member)
Returns the index in this group of the first occurrence of member . |
boolean |
isEmpty()
Returns true if this group has no members. |
int |
lastIndexOf(I member)
Returns the index in this group of the last occurrence of member . |
I |
move(I member,
int toIndex)
Moves member toIndex . |
I |
move(int fromIndex,
int toIndex)
Moves a member fromIndex toIndex . |
I |
remove(I member)
Removes member from this group, if present. |
I |
remove(int index)
Removes the member at index from this group. |
Collection<I> |
removeAll(Collection<? extends I> unwantedMembers)
Removes all elements of unwantedMembers that are contained in this
group. |
void |
removeAllListeners()
Removes all listeners from this group. |
void |
removeListener(CatalogItemGroupListener<I,G,C> listener)
Removes listener from this group's list. |
boolean |
setCatalog(C newCatalog)
Sets the catalog to which this group belongs. |
protected void |
setId(Long id)
Sets the ID of this group. |
protected void |
setInternalMemberList(List<I> replacementList)
Replaces the internal member list with replacementList . |
void |
setName(String newName)
Attempts to change the name of this group to newName . |
boolean |
setNameAndConfirm(String newName)
Attempts to set the name of this group and returns true if this group's name was changed. |
protected void |
simplySetCatalog(C newCatalog)
Sets this group's catalog to newCatalog without
contacting either the former or new catalog. |
int |
size()
Returns the number of members in this group. |
void |
sort(Comparator<? super I> comparator)
Uses comparator to sort the members of this group. |
List<I> |
swap(int index1,
int index2)
Swaps the members at the given positions. |
protected void |
tellListenersAboutFormerMember(I formerMember,
int index)
|
protected void |
tellListenersAboutMovedMember(I member,
int fromIndex,
int toIndex)
|
protected void |
tellListenersAboutNewMember(I newMember,
int index)
|
String |
toString()
Returns a text representation of this group. |
String |
toXml()
Returns an XML representation of this group. |
void |
writeAsXmlTo(Writer writer)
Writes an XML representation of this group to writer . |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CatalogItemGroup()
public CatalogItemGroup(C container, String nameOfGroup)
container
.
container
- the name of the one catalog to which this group belongs.
This value may be null.nameOfGroup
- the name of this group. If this value is null,
a non-null default name will be used.protected CatalogItemGroup(C container)
Method Detail |
---|
protected void setId(Long id)
id
is null, this group's ID
ID will be set to an unidentified ID.
id
- a new ID for this group.protected long getIdOfUnidentified()
public Long getId()
public void setName(String newName)
newName
.
This method exists for the use of frameworks that rely on
java-bean naming conventions and set-methods that are of
type void. The preferred method for all other clients is
setNameAndConfirm(String)
, which will let the caller
know whether or not the change of name was successful.
If this method fails to change this group's name it does so
silently.
newName
- the new name for this group.setNameAndConfirm(String)
public boolean setNameAndConfirm(String newName)
newName
- the new name for this group.
newName
. Reasons for a return value of false:
newName
is null.newName
is the empty string "".newName
.newName
. (The catalog is
now enforcing uniqueness of its groups' names.)public String getName()
protected boolean getNameIsLocked()
public List<String> getNotes()
This method returns the list actually held by this
CatalogItemGroup
, so
any list manipulations may be performed by first fetching the list and
then operating on it.
public boolean setCatalog(C newCatalog)
If this group is currently contained in a catalog
that is not the same as the newCatalog
parameter,
the current catalog will be told to remove this group
from its collection of groups. If newCatalog
is not null, it will be told to add this group
to its collection. Finally, this group's catalog
will be set to newCatalog
, even if it is null.
The current catalog has the right to deny movement of this group to a new catalog. If the request is denied, this group will remain with its current catalog.
Passing this method a newCatalog
of null has the
effect of disconnecting this group from any catalog.
newCatalog
- the catalog to which this group belongs.
newCatalog
is now the catalog for this
group. Note that this means if newCatalog
is already
the catalog of this group, the return value is true.protected void simplySetCatalog(C newCatalog)
newCatalog
without
contacting either the former or new catalog. This method is
used only by the Catalog class.
public C getCatalog()
This group may be one of several that belong to the same catalog. If this group belongs to no catalog, the value returned is null.
hasCatalog()
public boolean hasCatalog()
Catalog item groups should normally be contained within, and therefore have a non-null, catalog. However, there are some situations where this method will return false:
getCatalog()
and know that
it will return a non-null object.public I add(I newMember)
The new member is added to this group only if it is not null, and
this group currently contains no member that is equal to it.
(To bypass the equality restriction, use
addEvenIfEqualToCurrentMember(CatalogItem)
). If this
group belongs to a catalog, the catalog is also informed about the new
member.
If this group is part of a catalog, and if the catalog
has an item that is equal to newMember
, then that equivalent
item is used in place of newMember
as the new member of this
group. This ensures that an item copied from one group of a catalog
to another group of the same catalog is a single item that is a
member of the two groups. The next section shows what happens to
this group, its catalog (if it has one), and the value returned by
this method in a few situations.
A. This Group Does Not Belong to a Catalog
B. This Group Does Belong to a Catalog
In general, the return value is the newMember
parameter. However,
this is not always true when this group is part of a catalog. See the
description of the returned value, below.
1With the exception of a programming error within this class or the Catalog class, this is not expected to happen.
newMember
- a prospective new member of this group.
addEvenIfEqualToCurrentMember(CatalogItem)
public I add(int index, I newMember)
For a full description of the behavior of this method and its return
values, see add(CatalogItem)
.
index
- the position at which to insert the new member.newMember
- a prospective new member of this group.
addEvenIfEqualToCurrentMember(int, CatalogItem)
public Collection<I> addAll(Collection<? extends I> newMembers)
newMembers
to this group.
Only non-null candidates that are not already members of
this group are added.
newMembers
- a collection of prospective new members.
add(CatalogItem)
public Collection<I> addAll(int index, Collection<? extends I> newMembers)
newMembers
to this group at the
specified position.
Only non-null candidates that are not already members of
this group are added.
index
- the position at which to insert the first new member.
Subsequent new members are added at successive positions.newMembers
- a collection of prospective new members.
add(CatalogItem)
public I addEvenIfEqualToCurrentMember(I newMember)
newMember
even if this group already has a member to which it
is equal. Contrast this with add(CatalogItem)
.
The only times newMember
is not added to this group are
when it is null and when a reference to it is already contained
in this group.
newMember
- a potential new member for this group.
newMember
.public I addEvenIfEqualToCurrentMember(int index, I newMember)
newMember
at the specified position
even if this group already has a member to which it
is equal. Contrast this with add(int, CatalogItem)
.
The only times newMember
is not added to this group are
when it is null and when a reference to it is already contained
in this group.
index
- the position at which to add newMember
.newMember
- a potential new member for this group.
newMember
.protected void tellListenersAboutNewMember(I newMember, int index)
public I remove(I member)
member
from this group, if present.
The returned element is either null (if this group had no member
equal to member
) or is the removed member, which is the first
member of this group that is equal to member
.
member
- the member that is to be removed from this group.
public I remove(int index)
index
from this group.
index
- the index of the member to be removed.
index
.
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public Collection<I> removeAll(Collection<? extends I> unwantedMembers)
unwantedMembers
that are contained in this
group.
unwantedMembers
- the members that are to be removed from this group.
public void clear()
protected void tellListenersAboutFormerMember(I formerMember, int index)
public I incrementIndexOf(I member)
member
to an index one higher than its current index.
The member will not be moved if it is not in this group, or if
it is already in the highest position.
If member
is in this group in multiple positions, the instance
with the highest index will be moved.
member
- the member to be moved.
member
, or an equal member that was already part of
this group.public I decrementIndexOf(I member)
member
to an index one lower than its current index.
The member will not be moved if it is not in this group, or if
it is already in the lowest position.
If member
is in this group in multiple positions, the instance
with the lowest index will be moved.
member
- the member to be moved.
member
, or an equal member that was already part of
this group.public I incrementIndexOfMemberAt(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 group.
index
- the index of the member to be moved.
public I decrementIndexOfMemberAt(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 group.
index
- the index of the member to be moved.
public List<I> swap(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 members.index2
- the position of another of the members.
public I move(int fromIndex, int toIndex)
fromIndex
toIndex
.
fromIndex
- the current index of a member.toIndex
- the new index of that same member.
public I move(I member, int toIndex)
member
toIndex
.
member
- the member to be moved.toIndex
- the new position for member
.
member
or,
alternatively, a member equal to member
,
if this group has such a member.protected void tellListenersAboutMovedMember(I member, int fromIndex, int toIndex)
public void sort(Comparator<? super I> comparator)
comparator
to sort the members of this group.
comparator
- used to order this group's memberspublic int size()
public I get(int index)
index
- the position of the member to return.
index
.public List<I> getAll()
Note that the returned list is not held internally by this group. 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 members of this group, so changes made to them will be reflected in this group (and in all other groups of which those items are members).
protected List<I> getInternalMemberList()
protected void setInternalMemberList(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 isEmpty()
public boolean contains(I member)
member
belongs to this group.
member
- a possible member of this group.
member
belongs to this group.public int indexOf(I member)
member
. Indexing is zero-based.
member
- the member whose index is sought.
member
.
If member
does not belong to this group,
the returned value will be less than zero.public int lastIndexOf(I member)
member
. Indexing is zero-based.
member
- the member whose index is sought.
member
.
If member
does not belong to this group,
the returned value will be less than zero.public void addListener(CatalogItemGroupListener<I,G,C> newListener)
newListener
to this group's list.
The listener will be informed whenever:
newListener
- the listener to be added to this group's list.public void removeListener(CatalogItemGroupListener<I,G,C> listener)
listener
from this group's list.
listener
- the listener to be removed from this group's list.public void removeAllListeners()
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 cloneIntoSameCatalog()
clone()
.
Special Notes on Cloning Methodology
value
that indicates
that this group is currently unidentified.
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone()
public G clone()
Special Notes on Cloning Methodology
value
that indicates
that this group is currently unidentified.
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
cloneIntoSameCatalog()
protected G cloneAllExceptMembers()
protected void copyPropertiesFrom(G otherGroup)
otherGroup
into this one.
This method is used by the catalog's clone method to help copy its main group, which is not created via the normal cloning process. Subclasses should override this method and call super.copyPropertiesFrom(otherGroup). Failure to do so will result in some properties of a cloned catalog from matching that of the original.
What is not copied:
Subclasses should copy only those new properties that it creates. This list will be similar, if not identical, to the properties copied in the subclass's clone method.
The fact that this method has become necessary probably means that the way we're handling setup of a catalog's main group could probably be done better. One reason we don't just clone the main group is the main group uses a special non-public constructor. A reworking of the main group creation and cloning code should be done later on.
otherGroup
- a source of property values.public boolean equalsWithoutRespectToOrder(Object o)
o
is equal to this group in all respects
with the possible exception of the ordering of the members.
public boolean equals(Object o)
o
is equal to this group.
equals
in class Object
protected boolean clearlyNotEqualTo(Object o)
public int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |