/* * Copyright (c) 2005,2007 Declarative Engineering LLC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Declarative Engineering LLC * verson 1 which accompanies this distribution, and is available at * http://declarativeengineering.com/legal/DE_Developer_License_v1.txt */ package com.foundation.util; import com.common.util.ICollection; public class CollectionChangeEvent implements java.io.Externalizable { private boolean hasAdds = false; //Whether there were any additions.// private Object addedObject = null; //For single item adds.// private ICollection addedObjects = null; //For multi-item adds.// private boolean hasRemoves = false; //Whether there were any removals.// private Object removedObject = null; //For single item removals.// private ICollection removedObjects = null; //For multi-item removes.// /** * CollectionChangeEvent constructor. */ public CollectionChangeEvent() { super(); }//CollectionChangeEvent()// /** * CollectionChangeEvent constructor. * @param hasAdds Whether there are added values. * @param addedObjects The added values. * @param hasRemoves Whether there are removed values. * @param removedObjects The removed values. */ public CollectionChangeEvent(boolean hasAdds, ICollection addedObjects, boolean hasRemoves, ICollection removedObjects) { this.hasAdds = hasAdds; this.addedObjects = addedObjects; this.hasRemoves = hasRemoves; this.removedObjects = removedObjects; }//CollectionChangeEvent()// /** * CollectionChangeEvent constructor. * @param hasAdds Whether there is an added value. * @param addedObject The added value. * @param hasRemoves Whether there is a removed value. * @param removedObject The removed value. */ public CollectionChangeEvent(boolean hasAdds, Object addedObject, boolean hasRemoves, Object removedObject) { this.hasAdds = hasAdds; this.addedObject = addedObject; this.hasRemoves = hasRemoves; this.removedObject = removedObject; }//CollectionChangeEvent()// /** * Gets the single object added to the collection that fired the event. *
Note: Callers should first call to get the collection of added values. If the collection is null then call this method to get the single value added. This is done to reduce memory overhead by avoiding creating unnecessary lists.
* @return The object added to the collection. */ public Object getAddedObject() { return addedObject; }//getAddedObject()// /** * Gets the collection of objects added to the collection that fired the event. This collection will be null if there was only one added object. * @return The objects added to the collection. */ public ICollection getAddedObjects() { return addedObjects; }//getAddedObjects()// /** * Gets the single object removed from the collection that fired the event. *Note: Callers should first call to get the collection of removed values. If the collection is null then call this method to get the single value removed. This is done to reduce memory overhead by avoiding creating unnecessary lists.
* @return The object removed to the collection. */ public Object getRemovedObject() { return removedObject; }//getRemovedObject()// /** * Gets the collection of objects removed from the collection that fired the event. This collection will be null if there was only one removed object. * @return The objects removed to the collection. */ public ICollection getRemovedObjects() { return removedObjects; }//getRemovedObjects()// /** * Determines whether there are any added values. * @return Whether there were any additions. */ public boolean hasAdds() { return hasAdds; }//hasAdds()// /** * Determines whether there are any removed values. * @return Whether there were any removals. */ public boolean hasRemoves() { return hasRemoves; }//hasRemoves()// /** * Reads the collection from the stream. * @param in java.io.ObjectInput The stream that the object data can be read from. */ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException { in.readByte(); hasAdds = in.readBoolean(); addedObject = in.readObject(); addedObjects = (ICollection) in.readObject(); hasRemoves = in.readBoolean(); removedObject = in.readObject(); removedObjects = (ICollection) in.readObject(); }//readExternal()// /** * Writes the collection to the stream. * @param out java.io.ObjectOutput The stream that the object data can be written to. */ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { out.writeByte(0); out.writeBoolean(hasAdds); out.writeObject(addedObject); out.writeObject(addedObjects); out.writeBoolean(hasRemoves); out.writeObject(removedObject); out.writeObject(removedObjects); }//writeExternal()// }//CollectionChangeEvent//