Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2007 Gregory A. Kick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.jvnet.jaxb2_commons.ppp;
 
 import java.util.List;

Author(s):
gk5885
 
 public class ParentTrackingArrayList<T extends Childextends ArrayList<T>
 {
 
 	private static final long serialVersionUID = 1L;
 	private Object parent;

 
 	public ParentTrackingArrayList(Object parentClass<? extends List<?>> listClass)
 	{
 		super();
 		this. = parent;
 	}

Parameters:
c
 
 	public ParentTrackingArrayList(Object parentCollection<? extends T> c)
 	{
 		super(c);
 		for (T element : this)
 		{
 			element.setParent(parent);
 		}
 	}

Parameters:
initialCapacity
 
 	public ParentTrackingArrayList(Object parentint initialCapacity)
 	{
 		super(initialCapacity);
 		this. = parent;
 	}

 
 	public void add(int index, T element)
 	{
 		element.setParent();
 		super.add(indexelement);
 	}

 
 	public boolean add(T o)
 	{
 		return super.add(o);
 	}

 
 	public boolean addAll(Collection<? extends T> c)
 	{
 		for (T element : c)
 		{
 			element.setParent();
 		}
 		return super.addAll(c);
 	}

	public boolean addAll(int indexCollection<? extends T> c)
	{
		for (T element : c)
		{
			element.setParent();
		}
		return super.addAll(indexc);
	}

	public void clear()
	{
		for (T element : this)
		{
			element.setParent(null);
		}
		super.clear();
	}

	public T remove(int index)
	{
element = super.remove(index);
		element.setParent(null);
		return element;
	}

	public boolean remove(Object o)
	{
element = super.get(super.indexOf(o));
		element.setParent(null);
		return super.remove(o);
	}

	public boolean removeAll(Collection<?> c)
	{
		for (T element : this)
		{
			if (c.contains(element))
			{
				element.setParent(null);
			}
		}
		return super.removeAll(c);
	}

	public T set(int index, T element)
	{
		element.setParent();
		return super.set(indexelement);
	}

	protected void removeRange(int fromIndexint toIndex)
	{
		for (int index = fromIndexindex < toIndexindex++)
		{
			this.get(index).setParent(null);
		}
		super.removeRange(fromIndextoIndex);
	}
New to GrepCode? Check out our FAQ X