Class OverrideCollection<T,C extends Collection<T>>
- Type Parameters:
T-C- Base Collection type, e.g List
- All Implemented Interfaces:
Iterable<T>,Collection<T>
- Direct Known Subclasses:
OverrideList,OverrideSet
Some cases are relatively easy to handle, if we have a master collection with entries A, B, C and we want an override with A and C we create an override collection with just those two entries.
If we want an override with A, B, C, D we just copy the master collection and add to the copy.
However, what if we want an override with an empty Collection? Here we conflict with the need to determine if there is any override at all. In the database there is no equivalent to a non-null empty Collection.
It's also the case that hibernate appears to return empty Collections for no members so we never get null Collections. (need to confirm)
To indicate the collection has been removed by the override we need a flag in the annotation. This is queried by the getOverrideIsEmpty method.
A further problem arises with collections of complex classes such as attendees. Assume we have a recurring meeting with 2 attendees. For one instance we add a third attendee. We MUST clone the objects otherwise we end up with the annotation pointing at the master properties. Then if we try to remove one of the original 2 attendees we get a foreign key constraint exception because we try to delete an object referred to by the master.
However, this leads to the situatiuon where updates to the master event don't get reflected automatically in the overrides. We have to go through each overrride and adjust the attendees manually.
- Author:
- Mike Douglass douglm - bedework.edu
-
Constructor Summary
ConstructorsConstructorDescriptionOverrideCollection(BwEvent.ProxiedFieldIndex fieldIndex, BwEventAnnotation ann, ChangeFlag cf) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends T> c) voidclear()booleanbooleancontainsAll(Collection<?> c) abstract voidCopy the master contents into the override collectionbooleanprotected Cabstract CGet a new empty override collectionabstract CGet the master collectionprotected Cabstract CGet the override collectionbooleanDetermine if the override is explicitly emptied.inthashCode()booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) abstract voidsetOverrideCollection(C val) Set the override Collectionprotected voidsetOverrideEmptyFlag(boolean val) voidsetOverrideIsEmpty(boolean val) Set the override is explicitly emptied.intsize()Object[]toArray()<T1> T1[]toArray(T1[] a) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
OverrideCollection
public OverrideCollection(BwEvent.ProxiedFieldIndex fieldIndex, BwEventAnnotation ann, ChangeFlag cf) - Parameters:
fieldIndex-ann-cf-
-
-
Method Details
-
setOverrideCollection
Set the override Collection- Parameters:
val-
-
getOverrideCollection
Get the override collection- Returns:
- Collection
-
getEmptyOverrideCollection
Get a new empty override collection- Returns:
- empty Collection
-
copyIntoOverrideCollection
public abstract void copyIntoOverrideCollection()Copy the master contents into the override collection -
setOverrideIsEmpty
public void setOverrideIsEmpty(boolean val) Set the override is explicitly emptied.- Parameters:
val- boolean true if value is explicitly emptied or null.
-
getOverrideIsEmpty
public boolean getOverrideIsEmpty()Determine if the override is explicitly emptied.- Returns:
- boolean true if collection is explicitly emptied.
-
getMasterCollection
Get the master collection- Returns:
- the master Collection
-
size
public int size()- Specified by:
sizein interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<T>
-
contains
- Specified by:
containsin interfaceCollection<T>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<T>
-
toArray
public <T1> T1[] toArray(T1[] a) - Specified by:
toArrayin interfaceCollection<T>
-
add
- Specified by:
addin interfaceCollection<T>
-
remove
- Specified by:
removein interfaceCollection<T>
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>
-
addAll
- Specified by:
addAllin interfaceCollection<T>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T>
-
retainAll
- Specified by:
retainAllin interfaceCollection<T>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T>
-
equals
- Specified by:
equalsin interfaceCollection<T>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<T>- Overrides:
hashCodein classObject
-
setOverrideEmptyFlag
protected void setOverrideEmptyFlag(boolean val) -
getCollection
-
getModCollection
-