FileDocCategorySizeDatePackage
ArrayList.javaAPI DocGlassfish v2 API21677Fri May 04 22:35:12 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.sco

ArrayList

public class ArrayList extends ArrayList implements com.sun.jdo.spi.persistence.support.sqlstore.SCOCollection
A mutable 2nd class object date.
author
Marina Vatkina
version
1.0
see
java.util.ArrayList

Fields Summary
private transient com.sun.jdo.spi.persistence.support.sqlstore.PersistenceCapable
owner
private transient String
fieldName
private transient Class
elementType
private transient boolean
allowNulls
private transient Vector
added
private transient Vector
removed
private static final ResourceBundle
messages
I18N message handlers
private static final ResourceBundle
messages1
Constructors Summary
public ArrayList(Object owner, String fieldName, Class elementType, boolean allowNulls)
Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero. Assigns owning object and field name

param
owner the owning object
param
fieldName the owning field name
param
elementType the element types allowed
param
allowNulls true if nulls are allowed



                                                            
            
    
	super();
	if (owner instanceof PersistenceCapable)
        {
		this.owner = (PersistenceCapable)owner;
		this.fieldName = fieldName;
        }
	this.elementType = elementType;
	this.allowNulls = allowNulls;
    
public ArrayList(Object owner, String fieldName, Class elementType, boolean allowNulls, int initialCapacity)
Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero. Assigns owning object and field name

param
owner the owning object
param
fieldName the owning field name
param
elementType the element types allowed
param
allowNulls true if nulls are allowed
param
initialCapacity the initial capacity of the vector.
exception
IllegalArgumentException if the specified initial capacity is negative

	super(initialCapacity);
	if (owner instanceof PersistenceCapable)
        {
		this.owner = (PersistenceCapable)owner;
		this.fieldName = fieldName;
        }
	this.elementType = elementType;
	this.allowNulls = allowNulls;
    
Methods Summary
public booleanadd(java.lang.Object o)
Appends the specified element to the end of this ArrayList.

param
o element to be appended to this ArrayList.
return
true (as per the general contract of Collection.add).
see
java.util.ArrayList

	if (allowNulls == false && o == null)
        {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                        "sco.nulls_not_allowed")); // NOI18N
        }

	if (elementType == null || elementType.isAssignableFrom(o.getClass()))
        {
		// Mark the field as dirty
		StateManager stateManager = this.makeDirty();
        
                if (removed.remove(o) == false)
			added.add(o);

        	boolean modified = super.add(o);

		// Apply updates
		this.applyUpdates(stateManager, modified);

		return modified;

	} else {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                                "sco.classcastexception", elementType.getName()), // NOI18N
				 new ClassCastException(), new Object[] {o});
	}
    
public voidadd(int index, java.lang.Object element)
Inserts the specified element at the specified position in this ArrayList.

param
index index at which the specified element is to be inserted.
param
element element to be inserted.
exception
IndexOutOfBoundsException index is out of range (index < 0 || index > size()).
see
java.util.ArrayList

	if (allowNulls == false && element == null)
        {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                        "sco.nulls_not_allowed")); // NOI18N
        }

        if (elementType == null || elementType.isAssignableFrom(element.getClass()))
        {
		// Mark the field as dirty
		StateManager stateManager = this.makeDirty();
        
                super.add(index, element);
                if (removed.remove(element) == false)
                        added.add(element);

		// Apply updates
		this.applyUpdates(stateManager, true);
	
        } else {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                                "sco.classcastexception", elementType.getName()), // NOI18N
				 new ClassCastException(), new Object[] {element});
        }

    
public booleanaddAll(int index, java.util.Collection c)
Inserts all of the elements in in the specified Collection into this ArrayList at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the ArrayList in the order that they are returned by the specified Collection's iterator.

param
index index at which to insert first element from the specified collection.
param
c elements to be inserted into this ArrayList.
exception
IndexOutOfBoundsException index out of range (index < 0 || index > size()).
see
java.util.ArrayList

	if (allowNulls == false && c.contains(null))
        {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                        "sco.nulls_not_allowed")); // NOI18N
        }

	java.util.Vector errc = new java.util.Vector();  
        if (elementType != null)
        {
                // iterate the collection and make a list of wrong elements.
                Iterator i = c.iterator();
                while (i.hasNext())
                {
                        Object o = i.next(); 
                        if (!elementType.isAssignableFrom(o.getClass()))   
                                errc.add(o); 
                }
        }
        if (errc != null && errc.size() > 0)
        {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                                "sco.classcastexception", elementType.getName()), // NOI18N
				 new ClassCastException(), errc.toArray());
        }

	// Mark the field as dirty
	StateManager stateManager = this.makeDirty();
        
        removed.removeAll(c); 
        added.addAll(c); 

        boolean modified = super.addAll(index, c);

	// Apply updates
	this.applyUpdates(stateManager, modified);

        return modified;
    
public booleanaddAll(java.util.Collection c)
Appends all of the elements in the specified Collection to the end of this ArrayList, in the order that they are returned by the specified Collection's Iterator.

param
c elements to be inserted into this ArrayList.
exception
IndexOutOfBoundsException index out of range (index < 0 || index > size()).
see
java.util.ArrayList

	if (allowNulls == false && c.contains(null))
        {
                throw new JDOUserException(I18NHelper.getMessage(messages,
                        "sco.nulls_not_allowed")); // NOI18N
        }

	java.util.Vector errc = new java.util.Vector();
	if (elementType != null)
	{
		// iterate the collection and make a list of wrong elements.
		Iterator i = c.iterator();
		while (i.hasNext())
		{
			Object o = i.next();
			if (!elementType.isAssignableFrom(o.getClass()))
				errc.add(o);
		}
	}
	if (errc != null && errc.size() > 0) 
	{
		throw new JDOUserException(I18NHelper.getMessage(messages,
                                "sco.classcastexception", elementType.getName()), // NOI18N
				 new ClassCastException(), errc.toArray());
	}

	// Mark the field as dirty
	StateManager stateManager = this.makeDirty();
        
        removed.removeAll(c);
	added.addAll(c);

	boolean modified = super.addAll(c);

	// Apply updates
	this.applyUpdates(stateManager, modified);

	return modified;
    
public voidaddAllInternal(java.util.Collection c)
Adds a Collection to the list without recording changes

 
        super.addAll(c); 
    
public voidaddInternal(java.lang.Object o)
Adds an object to the list without recording changes

        super.add(o);
    
public voidaddToBaseCollection(java.lang.Object o)

inheritDoc

        super.add(o);
    
public voidapplyDeferredUpdates(java.util.Collection c)

		super.addAll(c);
	
public voidapplyUpdates(com.sun.jdo.spi.persistence.support.sqlstore.StateManager sm, boolean modified)
Apply changes (can be a no-op)


    	if (modified && sm != null)
        {
                sm.applyUpdates(fieldName, this);
        }
    
public voidclear()
Removes all of the elements from this ArrayList. The ArrayList will be empty after this call returns (unless it throws an exception).

see
java.util.ArrayList

	// Mark the field as dirty
	StateManager stateManager = this.makeDirty();
        
        for (Iterator iter = super.iterator(); iter.hasNext();) {
                Object o = iter.next();
                if (added.remove(o) == false)
                        removed.add(o);
        }
        added.clear();
        super.clear();

	// Apply updates
	this.applyUpdates(stateManager, true);
    
public voidclearInternal()
Clears Collection without notifing the owner

    
        super.clear(); 
        this.reset(); 
    
public java.lang.Objectclone()
Creates and returns a copy of this object.

Mutable Second Class Objects are required to provide a public clone method in order to allow for copying PersistenceCapable objects. In contrast to Object.clone(), this method must not throw a CloneNotSupportedException.

        ArrayList obj = (ArrayList)super.clone();
	obj.unsetOwner();

        return obj;
    
public java.lang.ObjectcloneInternal()
Creates and returns a copy of this object without resetting the owner and field value.

        return super.clone();
    
public java.util.CollectiongetAdded()
Returns added collection

return
added collection of added elements

        return (Collection)added;
    
public java.lang.StringgetFieldName()
Returns the field name

return
field name as java.lang.String

	return this.fieldName;
    
public java.lang.ObjectgetOwner()
Returns the owner object of the SCO instance

return
owner object

	return this.owner;
    
public java.util.CollectiongetRemoved()
Returns removed collection

return
removed collection of removed elements

 
        return (Collection)removed; 
    
public booleanisDeferred()

		return false;
	
public com.sun.jdo.spi.persistence.support.sqlstore.StateManagermakeDirty()
Marks object dirty

	if (owner != null) 
        {
                StateManager stateManager = owner.jdoGetStateManager(); 
                if (stateManager != null) 
                { 
                        stateManager.makeDirty(fieldName); 
                } 
                  
                return stateManager; 
	} 
        return null;
     
public voidmarkDeferred()

	
public booleanremove(java.lang.Object o)
Removes the first occurrence of the specified element in this ArrayList If the ArrayList does not contain the element, it is unchanged.

param
o element to be removed from this ArrayList, if present.
return
true if the ArrayList contained the specified element.
see
java.util.ArrayList


	// Because java.util.AbstractCollection.remove(Object) delegates remove() to remove(int)
	// which is not supported, we cannot rely on jdk. We need to process remove here.

        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();

	int i = super.indexOf(o);
        Object obj = null;
	if (i > -1) {
		obj = super.remove(i);

        	if (added.remove(obj) == false)
                	removed.add(obj);

        	// Apply updates
        	this.applyUpdates(stateManager, true);
		return true;
	}
	return false;
    
public java.lang.Objectremove(int index)
Removes the element at the specified position in this ArrayList. shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the ArrayList.

param
index the index of the element to removed.
exception
IndexOutOfBoundsException index out of range (index < 0 || index >= size()).
see
java.util.ArrayList


	throwUnsupportedOption();

	// Mark the field as dirty
	StateManager stateManager = this.makeDirty();
        
        Object obj = super.remove(index);

        if (added.remove(obj) == false)
		removed.add(obj);

	// Apply updates
	this.applyUpdates(stateManager, true);

        return obj;
    
public booleanremoveAll(java.util.Collection c)
Removes from this ArrayList all of its elements that are contained in the specified Collection.

return
true if this ArrayList changed as a result of the call.
see
java.util.ArrayList

	boolean modified = false;
	// Mark the field as dirty
	StateManager stateManager = this.makeDirty();
        
        Iterator e = c.iterator();
        while (e.hasNext()) {
		Object o = e.next();
            	if(super.contains(o)) {
                	removeInternal(o);
			if (added.remove(o) == false)
                		removed.add(o);
                	modified = true;
            	}
        }

	// Apply updates
	this.applyUpdates(stateManager, modified);

        return modified;
    
public voidremoveAllInternal(java.util.Collection c)
Removes from this collection without recording changes

 
        super.removeAll(c); 
    
public voidremoveInternal(java.lang.Object o)
Removes an element without notifing the owner

    
	int i = super.indexOf(o);
        super.remove(i); 
    
public voidreset()
Cleans removed and added lists

        added.clear();
        removed.clear();
    
public booleanretainAll(java.util.Collection c)
Retains only the elements in this ArrayList that are contained in the specified Collection.

return
true if this ArrayList changed as a result of the call.
see
java.util.ArrayList

	boolean modified = false;
	java.util.Vector v = new java.util.Vector();

	// Mark the field as dirty
	StateManager stateManager = this.makeDirty();
        
        for (Iterator iter = super.iterator(); iter.hasNext();) 
        { 
                Object o = iter.next(); 
                if (!c.contains(o))  
                {   
			v.add(o);
                 	if (added.remove(o) == false)
				removed.add(o);  

			modified = true;
		} 
        } 

	// Now remove the rest (stored in "v")
	for (Iterator iter = v.iterator(); iter.hasNext();)
        {
			removeInternal(iter.next());
	}

	// Apply updates
	this.applyUpdates(stateManager, modified);

        return modified;
    
public java.lang.Objectset(int index, java.lang.Object element)
Replaces the element at the specified position in this ArrayList with the specified element.

param
index index of element to replace.
param
element element to be stored at the specified position.
return
the element previously at the specified position.
exception
IndexOutOfBoundsException index out of range (index < 0 || index >= size()).
exception
IllegalArgumentException fromIndex > toIndex.
see
java.util.ArrayList


	throwUnsupportedOption();

        if (element == null)
        {
                if (allowNulls == false)
                {
                        throw new JDOUserException(I18NHelper.getMessage(messages,
                                "sco.nulls_not_allowed")); // NOI18N
                }
                // It is actualy remove
                return this.remove(index);
        }

        if (elementType == null || elementType.isAssignableFrom(element.getClass()))
        { 
		// Mark the field as dirty
		StateManager stateManager = this.makeDirty();
        
		Object o = super.set(index, element);

                if (added.remove(o) == false)
                        removed.add(o);

                if (removed.remove(element) == false)
                        added.add(element);

		// Apply updates
		this.applyUpdates(stateManager, true);
        
        	return o;
	} else {
		throw new JDOUserException(I18NHelper.getMessage(messages,
                                "sco.classcastexception", elementType.getName()), // NOI18N
				 new ClassCastException(), new Object[] {element});
	}

    
public voidsetOwner(java.lang.Object owner, java.lang.String fieldName, java.lang.Class elementType)
Set the owner if this instance is not owned.

see
SCOCollection#setOwner
param
owner the new owner.
param
fieldName the new field name.
param
elementType the new element type as Class, or null if type is not to be checked.


        if (this.owner != null) {
            throw new JDOUserException(I18NHelper.getMessage(
                messages1, "core.statemanager.anotherowner"), // NOI18N
                new Object[]{this.owner, this.fieldName});
        }
        if (owner instanceof PersistenceCapable) {
                this.owner = (PersistenceCapable)owner;
                this.fieldName = fieldName;
                this.elementType = elementType;
        }
    
private voidthrowUnsupportedOption()
Throw JDOUnsupportedOptionException

	// Index operation that changes the underline collection
	// is not supported in 2_beta. Bug 4370474
	throw new JDOUnsupportedOptionException(I18NHelper.getMessage(messages,
                                "sco.not_supported")); //NOI18N
    
public voidunsetOwner()
Nullifies references to the owner Object and Field

	this.owner = null;
	this.fieldName = null;
	this.elementType = null;
        added.clear();
        removed.clear();