ControlConstructBagImpl.java revision 18
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen// The MIT License
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch//
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// Copyright (c) 2004 Evren Sirin
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch//
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// Permission is hereby granted, free of charge, to any person obtaining a copy
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// of this software and associated documentation files (the "Software"), to
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// deal in the Software without restriction, including without limitation the
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// sell copies of the Software, and to permit persons to whom the Software is
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// furnished to do so, subject to the following conditions:
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch//
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// The above copyright notice and this permission notice shall be included in
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// all copies or substantial portions of the Software.
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch//
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch// IN THE SOFTWARE.
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/*
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch * Created on Dec 27, 2003
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch *
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschpackage impl.owls.process;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschimport impl.owls.generic.list.OWLSObjListImpl;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschimport org.mindswap.owl.OWLIndividual;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschimport org.mindswap.owl.OWLValue;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschimport org.mindswap.owl.list.RDFList;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschimport org.mindswap.owls.process.ControlConstruct;
47fee1a942e4797548b1232354f6676b8ff809f4Stephan Boschimport org.mindswap.owls.process.ControlConstructBag;
47fee1a942e4797548b1232354f6676b8ff809f4Stephan Boschimport org.mindswap.owls.vocabulary.OWLS;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/**
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch * @author Evren Sirin
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch *
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschpublic class ControlConstructBagImpl extends OWLSObjListImpl implements ControlConstructBag {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch public ControlConstructBagImpl(OWLIndividual ind) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch super(ind);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch setVocabulary(OWLS.CCBag);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen public RDFList insert(OWLValue item) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch ControlConstructBagImpl list = new ControlConstructBagImpl( getOntology().createInstance( vocabulary.List() ) );
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch list.setVocabulary(vocabulary);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch list.setFirst( item );
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch list.setRest( this );
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return list;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch public OWLValue getFirstValue() {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch OWLIndividual cc = getProperty(vocabulary.first());
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (cc != null && !cc.equals(vocabulary.nil()))
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return (ControlConstruct) cc.castTo(ControlConstruct.class);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch else
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return null;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch public RDFList getRest() {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return (ControlConstructBag) getProperty(vocabulary.rest()).castTo(ControlConstructBag.class);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch public ControlConstruct constructAt(int index) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return (ControlConstruct) get(index);
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch }
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch public RDFList remove() {
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch ControlConstructBag bag = (ControlConstructBag) getRest();
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch if (size() > 1) {
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch bag.setFirst(getRest().getFirstValue());
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch bag.setRest((ControlConstructBag) getRest().getRest());
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch } else {
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch bag = (ControlConstructBag) vocabulary.nil().castTo(ControlConstructBag.class);
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch }
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch if (hasProperty(vocabulary.first()))
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch removeProperties(vocabulary.first());
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch if (hasProperty(vocabulary.rest()))
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch removeProperties(vocabulary.rest());
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Bosch individual.delete();
return bag;
}
public RDFList removeAll() {
ControlConstructBag bag = this;
while (bag.size() > 0)
bag = (ControlConstructBag) bag.remove();
return bag;
}
}