1968N/A// The MIT License
1968N/A//
1968N/A// Copyright (c) 2004 Evren Sirin
1968N/A//
1968N/A// Permission is hereby granted, free of charge, to any person obtaining a copy
1968N/A// of this software and associated documentation files (the "Software"), to
1968N/A// deal in the Software without restriction, including without limitation the
1968N/A// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1968N/A// sell copies of the Software, and to permit persons to whom the Software is
1968N/A// furnished to do so, subject to the following conditions:
1968N/A//
1968N/A// The above copyright notice and this permission notice shall be included in
1968N/A// all copies or substantial portions of the Software.
1968N/A//
1968N/A// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1968N/A// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1968N/A// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1968N/A// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1968N/A// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1968N/A// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1968N/A// IN THE SOFTWARE.
1968N/A
1968N/A/*
1968N/A * Created on Dec 21, 2004
1968N/A */
1968N/Apackage impl.owl;
1968N/A
1968N/A
1968N/Aimport java.util.Iterator;
1968N/Aimport java.util.List;
1968N/Aimport java.util.ListIterator;
1968N/A
1968N/Aimport org.mindswap.owl.OWLIndividualList;
1968N/Aimport org.mindswap.owl.OWLObject;
1968N/A
1968N/A/**
1968N/A * @author Evren Sirin
2028N/A *
2028N/A */
2028N/Apublic class CastingList extends OWLIndividualListImpl implements OWLIndividualList {
2028N/A private Class castTarget;
2028N/A
1968N/A public CastingList(Class castTarget) {
1968N/A super();
1968N/A
1968N/A this.castTarget = castTarget;
1968N/A }
1968N/A
2028N/A public CastingList(List list, Class castTarget) {
2028N/A super(list instanceof CastingList ? ((CastingList)list).getBaseList() : list);
2028N/A
1968N/A this.castTarget = castTarget;
2028N/A }
2028N/A
1968N/A public Object get(int index) {
1968N/A return ((OWLObject) super.get(index)).castTo(castTarget);
1968N/A }
1968N/A
1968N/A
2028N/A public Iterator iterator() {
1968N/A return listIterator(0);
1968N/A }
2028N/A
2028N/A public ListIterator listIterator() {
1968N/A return listIterator(0);
1968N/A }
1968N/A
1968N/A public ListIterator listIterator(final int index) {
2028N/A return new ListIterator() {
2028N/A ListIterator i = CastingList.this.getListIterator(index);
2028N/A
2028N/A public boolean hasNext() {return i.hasNext();}
2028N/A public Object next() {
2028N/A i.next();
2028N/A return get(i.previousIndex());
1968N/A }
1968N/A public boolean hasPrevious() {return i.hasPrevious();}
1968N/A public Object previous() {
1968N/A i.previous();
1968N/A return get(i.nextIndex());
1968N/A }
1968N/A public int nextIndex() {return i.nextIndex();}
1968N/A public int previousIndex() {return i.previousIndex();}
1968N/A public void remove() { i.remove(); }
1968N/A public void set(Object o) { i.set(o); }
1968N/A public void add(Object o) { i.add(o); }
1968N/A };
1968N/A }
1968N/A
1968N/A private ListIterator getListIterator(int index) {
1968N/A return super.listIterator( index );
1968N/A }
1968N/A
1968N/A public Object[] toArray() {
1968N/A int size = size();
1968N/A Object[] result = new Object[size];
1968N/A
1968N/A for(int i = 0; i < size; i++)
1968N/A result[i] = get(i);
1968N/A
1968N/A return result;
1968N/A }
1968N/A
1968N/A public Object[] toArray(Object a[]) {
1968N/A int size = size();
1968N/A if (a.length < size)
1968N/A a = (Object[])java.lang.reflect.Array.newInstance(
1968N/A a.getClass().getComponentType(), size);
1968N/A
1968N/A for(int i = 0; i < size; i++)
1968N/A a[i] = get(i);
1968N/A
1968N/A if (a.length > size)
1968N/A a[size] = null;
1968N/A
1978N/A return a;
1968N/A }
1968N/A}
2028N/A