OWLSObjListImpl.java revision 18
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// The MIT License
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield//
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// Copyright (c) 2004 Evren Sirin
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield//
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// Permission is hereby granted, free of charge, to any person obtaining a copy
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// of this software and associated documentation files (the "Software"), to
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// deal in the Software without restriction, including without limitation the
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// sell copies of the Software, and to permit persons to whom the Software is
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// furnished to do so, subject to the following conditions:
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield//
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// The above copyright notice and this permission notice shall be included in
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// all copies or substantial portions of the Software.
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield//
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield// IN THE SOFTWARE.
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield/*
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield * Created on Dec 23, 2004
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield */
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfieldpackage impl.owls.generic.list;
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfieldimport impl.owl.list.RDFListImpl;
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfieldimport org.mindswap.owl.OWLIndividual;
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfieldimport org.mindswap.owl.OWLValue;
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfieldimport org.mindswap.owl.list.RDFList;
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfieldimport org.mindswap.owls.generic.list.OWLSObjList;
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfieldimport org.mindswap.owls.vocabulary.OWLS;
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield/**
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield * @author Evren Sirin
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield * @author Michael D�nzer, University of Zurich
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos */
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfieldpublic class OWLSObjListImpl extends RDFListImpl implements OWLSObjList {
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield public OWLSObjListImpl(OWLIndividual ind) {
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield super(ind);
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield setVocabulary(OWLS.ObjList);
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield }
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfield
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfield public RDFList getRest() {
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield return (OWLSObjList) getProperty(vocabulary.rest()).castTo(OWLSObjList.class);
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield }
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield // TODO returning an instance of the superclass as replacement for the instance this operation was called is really bad.
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield public RDFList insert(OWLValue item) {
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield OWLSObjListImpl list = new OWLSObjListImpl(getOntology().createInstance( vocabulary.List()));
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield list.setVocabulary(vocabulary);
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield list.setFirst( item );
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield list.setRest( this );
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield return list;
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield }
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield public RDFList remove() {
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield OWLSObjList bag = (OWLSObjList) getRest();
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfield
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfield if (size() > 1) {
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfield bag.setFirst(getRest().getFirstValue());
826cde7c2100e1f4419a54b5c930c0854e01e87eMichael H. Warfield bag.setRest((OWLSObjList) getRest().getRest());
b4f7af7a520b23c873e404562ec518a576e63d4cMichael H. Warfield } else {
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield bag = (OWLSObjList) vocabulary.nil().castTo(OWLSObjList.class);
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield }
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield if (hasProperty(vocabulary.first()))
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield removeProperties(vocabulary.first());
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield if (hasProperty(vocabulary.rest()))
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield removeProperties(vocabulary.rest());
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield individual.delete();
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield return bag;
164105f6563d98b832f603e28e506dbabed22cf3Michael H. Warfield }
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber
c63c04fcaf1c3a78c70500eae253d72fa9c8358aTAMUKI Shoichi public RDFList removeAll() {
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber OWLSObjList list = this;
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber while (list.size() > 0)
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber list = (OWLSObjList) list.remove();
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber return list;
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber }
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber}
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber