Class OverrideCollection<T,C extends Collection<T>>

java.lang.Object
org.bedework.calfacade.base.OverrideCollection<T,C>
Type Parameters:
T -
C - Base Collection type, e.g List
All Implemented Interfaces:
Iterable<T>, Collection<T>
Direct Known Subclasses:
OverrideList, OverrideSet

public abstract class OverrideCollection<T,C extends Collection<T>> extends Object implements Collection<T>
A class to allow operations on overridden Collection values which leave the master collection untouched. The problem is to allow an event to be annotated in some manner by a user with no access. We also use this when overriding a recurring instance.

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 Details

  • Method Details

    • setOverrideCollection

      public abstract void setOverrideCollection(C val)
      Set the override Collection
      Parameters:
      val -
    • getOverrideCollection

      public abstract C getOverrideCollection()
      Get the override collection
      Returns:
      Collection
    • getEmptyOverrideCollection

      public abstract C 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

      public abstract C getMasterCollection()
      Get the master collection
      Returns:
      the master Collection
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<T>
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
    • toArray

      public <T1> T1[] toArray(T1[] a)
      Specified by:
      toArray in interface Collection<T>
    • add

      public boolean add(T o)
      Specified by:
      add in interface Collection<T>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<T>
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Specified by:
      addAll in interface Collection<T>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<T>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<T>
      Overrides:
      hashCode in class Object
    • setOverrideEmptyFlag

      protected void setOverrideEmptyFlag(boolean val)
    • getCollection

      protected C getCollection()
    • getModCollection

      protected C getModCollection()