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