01: /*
02: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: ContNodeIteratorImpl.java,v 1.12 2008/01/02 12:04:56 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.rdf.model.impl;
08:
09: import com.hp.hpl.jena.util.iterator.*;
10: import com.hp.hpl.jena.rdf.model.*;
11:
12: import java.util.*;
13:
14: /** An internal class not normally of interest to application developers.
15: * An iterator over the nodes in a container.
16: * @author bwm, kers
17: * @version Release='$Name: $' Revision='$Revision: 1.12 $' Date='$Date: 2008/01/02 12:04:56 $'
18: */
19: public class ContNodeIteratorImpl extends WrappedIterator implements
20: NodeIterator {
21:
22: protected Statement stmt = null;
23: protected Container cont;
24: protected int size;
25: protected int index = 0;
26: protected int numDeleted = 0;
27: protected Vector moved = new Vector();
28:
29: /** Creates new ContNodeIteratorImpl */
30: public ContNodeIteratorImpl(Iterator iterator, Object object,
31: Container cont) {
32: super (iterator);
33: this .cont = cont;
34: this .size = cont.size();
35: }
36:
37: public Object next() throws NoSuchElementException {
38: stmt = (Statement) super .next();
39: index += 1;
40: return stmt.getObject();
41: }
42:
43: public RDFNode nextNode() throws NoSuchElementException {
44: return (RDFNode) next();
45: }
46:
47: public void remove() throws NoSuchElementException {
48: if (stmt == null)
49: throw new NoSuchElementException();
50: super .remove();
51:
52: if (index > (size - numDeleted)) {
53: ((ContainerI) cont).remove(((Integer) moved.elementAt(size
54: - index)).intValue(), stmt.getObject());
55: } else {
56: cont.remove(stmt);
57: moved.add(new Integer(index));
58: }
59: stmt = null;
60: numDeleted++;
61: }
62:
63: }
64: /*
65: * (c) Copyright 2000, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
66: * All rights reserved.
67: *
68: * Redistribution and use in source and binary forms, with or without
69: * modification, are permitted provided that the following conditions
70: * are met:
71: * 1. Redistributions of source code must retain the above copyright
72: * notice, this list of conditions and the following disclaimer.
73: * 2. Redistributions in binary form must reproduce the above copyright
74: * notice, this list of conditions and the following disclaimer in the
75: * documentation and/or other materials provided with the distribution.
76: * 3. The name of the author may not be used to endorse or promote products
77: * derived from this software without specific prior written permission.
78:
79: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
80: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
81: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
82: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
83: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
84: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
85: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
86: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
87: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
88: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89: *
90: * ContNodeIteratorImpl.java
91: *
92: * Created on 12 August 2000, 09:57
93: */
|