RDFListImpl.java revision 16
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen// The MIT License
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen// Copyright (c) 2004 Evren Sirin
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// Permission is hereby granted, free of charge, to any person obtaining a copy
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen// of this software and associated documentation files (the "Software"), to
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// deal in the Software without restriction, including without limitation the
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// sell copies of the Software, and to permit persons to whom the Software is
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// furnished to do so, subject to the following conditions:
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// The above copyright notice and this permission notice shall be included in
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// all copies or substantial portions of the Software.
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen// IN THE SOFTWARE.
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen * Created on Dec 23, 2004
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainenimport org.mindswap.exceptions.InvalidListException;
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen * @author Evren Sirin
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen * @author Michael D�nzer, University of Zurich
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainenpublic class RDFListImpl extends WrappedIndividual implements RDFList {
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen private class RDFListIterator implements Iterator {
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen public void remove() {
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen throw new UnsupportedOperationException("Cannot remove from ObjList iterator");
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen public boolean hasNext() {
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen return (RDFList) getProperty(vocabulary.rest()).castTo(RDFList.class);
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen public void setRestToNil() {
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen setProperty(vocabulary.rest(), vocabulary.nil());
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen OWLValue value = getProperty( vocabulary.firstD() );
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen throw new RuntimeException( "Cannot modify empty list (list:nil)" );
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen setProperty(vocabulary.firstD(), vocabulary.nil());
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen setProperty(vocabulary.firstD(), (OWLDataValue) value );
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen setProperty(vocabulary.first(), (OWLIndividual) value );
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen OWLIndividualList result = OWLFactory.createIndividualList();
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen for(RDFList list = this; !list.isEmpty(); list = list.getRest())
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen for(RDFList list = this; !list.isEmpty(); list = list.getRest())
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen return (index == 0) ? getFirstValue() : getRest().getValue(index - 1);
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen RDFListImpl list = new RDFListImpl( getOntology().createInstance( vocabulary.List() ) );
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen public RDFList insertAt(int index, OWLValue value) {
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen RDFListImpl list = new RDFListImpl(getOntology().createInstance(vocabulary.List()));
6bf1543bb7af03324c04e8f9ac8e430f395989aeTimo Sirainen throw new UnsupportedOperationException( "Cannot modify empty list (list:nil)" );
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen return new RDFListIterator(this);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen public int size() {
e30b748edcef3cf3352478bf21fa8f785bdc773aTimo Sirainen public boolean isEmpty() {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return equals(vocabulary.nil()) || (getFirstValue() != null && getFirstValue().equals(vocabulary.nil()));