KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > impl > SeqImpl


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: SeqImpl.java,v 1.18 2005/02/21 12:14:54 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.rdf.model.impl;
8
9 import com.hp.hpl.jena.rdf.model.*;
10 import com.hp.hpl.jena.vocabulary.RDF;
11 import com.hp.hpl.jena.graph.*;
12
13 import com.hp.hpl.jena.enhanced.*;
14
15 /** An implementation of Seq
16  *
17  * @author bwm
18  * @version Release='$Name: $' Revision='$Revision: 1.18 $' Date='$Date: 2005/02/21 12:14:54 $'
19 */

20
21 public class SeqImpl extends ContainerImpl implements Seq {
22
23     final static public Implementation factory = new Implementation() {
24         public boolean canWrap( Node n, EnhGraph eg )
25             { return true; }
26         public EnhNode wrap(Node n,EnhGraph eg) {
27             return new SeqImpl(n,eg);
28         }
29     };
30     
31     static NodeIteratorFactory seqIteratorFactory = new SeqNodeIteratorFactoryImpl();
32
33     /** Creates new SeqMem */
34     public SeqImpl( ModelCom model ) {
35         super( model );
36     }
37     
38     public SeqImpl( String JavaDoc uri, ModelCom model ) {
39         super( uri, model );
40     }
41     
42     public SeqImpl( Resource r, ModelCom m ) {
43         super( r, m );
44     }
45
46     public SeqImpl(Node n, EnhGraph g) {
47         super(n,g);
48     }
49     
50     public Resource getResource(int index) {
51         return getRequiredProperty(RDF.li(index)).getResource();
52     }
53     
54     public Literal getLiteral(int index) {
55         return getRequiredProperty(RDF.li(index)).getLiteral();
56     }
57     
58     public RDFNode getObject(int index) {
59         return getRequiredProperty(RDF.li(index)).getObject();
60     }
61     
62     public boolean getBoolean(int index) {
63         checkIndex(index);
64         return getRequiredProperty(RDF.li(index)).getBoolean();
65     }
66     
67     public byte getByte(int index) {
68         checkIndex(index);
69         return getRequiredProperty(RDF.li(index)).getByte();
70     }
71     
72     public short getShort(int index) {
73         checkIndex(index);
74         return getRequiredProperty(RDF.li(index)).getShort();
75     }
76     
77     public int getInt(int index) {
78         checkIndex(index);
79         return getRequiredProperty(RDF.li(index)).getInt();
80     }
81     
82     public long getLong(int index) {
83         checkIndex(index);
84         return getRequiredProperty(RDF.li(index)).getLong();
85     }
86     
87     public char getChar(int index) {
88         checkIndex(index);
89         return getRequiredProperty(RDF.li(index)).getChar();
90     }
91     
92     public float getFloat(int index) {
93         checkIndex(index);
94         return getRequiredProperty(RDF.li(index)).getFloat();
95     }
96     
97     public double getDouble(int index) {
98         checkIndex(index);
99         return getRequiredProperty(RDF.li(index)).getDouble();
100     }
101     
102     public String JavaDoc getString(int index) {
103         checkIndex(index);
104         return getRequiredProperty(RDF.li(index)).getString();
105     }
106     
107     public String JavaDoc getLanguage(int index) {
108         checkIndex(index);
109         return getRequiredProperty(RDF.li(index)).getLanguage();
110     }
111     
112     public Object JavaDoc getObject(int index, ObjectF f) {
113         return getRequiredProperty(RDF.li(index)).getObject(f);
114     }
115     
116     public Resource getResource(int index, ResourceF f) {
117         return getRequiredProperty(RDF.li(index)).getResource(f);
118     }
119     
120     public Bag getBag(int index) {
121         checkIndex(index);
122         return getRequiredProperty(RDF.li(index)).getBag();
123     }
124     
125     public Alt getAlt(int index) {
126         checkIndex(index);
127         return getRequiredProperty(RDF.li(index)).getAlt();
128     }
129     
130     public Seq getSeq(int index) {
131         checkIndex(index);
132         return getRequiredProperty(RDF.li(index)).getSeq();
133     }
134
135     public Seq set(int index, RDFNode o) {
136         checkIndex(index);
137         getRequiredProperty(RDF.li(index)).changeObject(o);
138         return this;
139     }
140     
141     public Seq set(int index, boolean o) {
142         checkIndex(index);
143         getRequiredProperty(RDF.li(index)).changeObject(o);
144         return this;
145     }
146     
147     public Seq set(int index, long o) {
148         checkIndex(index);
149         getRequiredProperty(RDF.li(index)).changeObject(o);
150         return this;
151     }
152     
153     public Seq set(int index, float o) {
154         checkIndex(index);
155         getRequiredProperty(RDF.li(index)).changeObject(o);
156         return this;
157     }
158     
159     public Seq set(int index, double o) {
160         checkIndex(index);
161         getRequiredProperty(RDF.li(index)).changeObject(o);
162         return this;
163     }
164     
165     public Seq set(int index, char o) {
166         checkIndex(index);
167         getRequiredProperty(RDF.li(index)).changeObject(o);
168         return this;
169     }
170     
171     public Seq set(int index, String JavaDoc o) {
172         checkIndex(index);
173         getRequiredProperty(RDF.li(index)).changeObject(o);
174         return this;
175     }
176     
177     public Seq set(int index, String JavaDoc o, String JavaDoc l) {
178         checkIndex(index);
179         getRequiredProperty(RDF.li(index)).changeObject(o, l);
180         return this;
181     }
182     
183     public Seq set(int index, Object JavaDoc o) {
184         checkIndex(index);
185         getRequiredProperty(RDF.li(index)).changeObject(o);
186         return this;
187     }
188     
189     public Seq add(int index, boolean o) {
190         return add( index, String.valueOf( o ) );
191     }
192     
193     public Seq add(int index, long o) {
194         return add( index, String.valueOf( o ) );
195     }
196     
197     public Seq add(int index, char o) {
198         return add( index, String.valueOf( o ) );
199     }
200     
201     public Seq add(int index, float o) {
202         return add( index, String.valueOf( o ) );
203     }
204     
205     public Seq add(int index, double o) {
206         return add( index, String.valueOf( o ) );
207     }
208     
209     public Seq add(int index, Object JavaDoc o) {
210         return add( index, String.valueOf( o ) );
211     }
212     
213     public Seq add(int index, String JavaDoc o) {
214         return add( index, o, "" );
215     }
216     
217     public Seq add( int index, String JavaDoc o, String JavaDoc l ) {
218         return add( index, literal( o, l ) );
219     }
220     
221     public Seq add(int index, RDFNode o) {
222         int size = size();
223         checkIndex(index, size+1);
224         shiftUp(index, size);
225         addProperty(RDF.li(index), o);
226         return this;
227     }
228         
229      public NodeIterator iterator()
230         { return listContainerMembers( seqIteratorFactory ); }
231     
232     public Container remove(Statement s) {
233         getModel().remove(s);
234         shiftDown(s.getPredicate().getOrdinal()+1, size()+1);
235         return this;
236     }
237     
238     public Seq remove(int index) {
239         getRequiredProperty(RDF.li(index)).remove();
240         shiftDown(index+1, size()+1);
241         return this;
242     }
243     
244     public Container remove(int index, RDFNode o) {
245         return remove(getModel().createStatement(this, RDF.li(index), o).remove());
246     }
247     
248     public int indexOf( RDFNode o ) {
249         return containerIndexOf( o );
250     }
251     
252     public int indexOf(boolean o) {
253         return indexOf( String.valueOf( o ) );
254     }
255     
256     public int indexOf(long o) {
257         return indexOf( String.valueOf( o ) );
258     }
259     
260     public int indexOf(char o) {
261         return indexOf( String.valueOf( o ) );
262     }
263     
264     public int indexOf(float o) {
265         return indexOf( String.valueOf( o ) );
266     }
267     
268     public int indexOf(double o) {
269         return indexOf( String.valueOf( o ) );
270     }
271
272     public int indexOf(Object JavaDoc o) {
273         return indexOf( String.valueOf( o ) );
274     }
275         
276     public int indexOf(String JavaDoc o) {
277         return indexOf( o, "" );
278     }
279     
280     public int indexOf(String JavaDoc o, String JavaDoc l) {
281         return indexOf( literal( o, l ) );
282     }
283         
284     private Literal literal( String JavaDoc s, String JavaDoc lang )
285         { return new LiteralImpl( Node.createLiteral( s, lang, false ), getModelCom() ); }
286         
287     protected void shiftUp(int start, int finish) {
288         Statement stmt = null;
289         for (int i = finish; i >= start; i--) {
290             stmt = getRequiredProperty(RDF.li(i));
291             getModel().remove(stmt);
292             addProperty(RDF.li(i+1), stmt.getObject());
293         }
294     }
295     protected void shiftDown(int start, int finish) {
296         Statement stmt = null;
297         for (int i=start; i<=finish; i++) {
298             stmt = getRequiredProperty(RDF.li(i));
299             addProperty(RDF.li(i-1), stmt.getObject());
300             stmt.remove();
301         }
302     }
303     
304     protected void checkIndex(int index) {
305         checkIndex( index, size() );
306     }
307     
308     protected void checkIndex(int index, int max) {
309         if (! (1 <= index && index <= max)) {
310             throw new SeqIndexBoundsException( max, index );
311         }
312     }
313 }
314 /*
315  * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
316  * All rights reserved.
317  *
318  * Redistribution and use in source and binary forms, with or without
319  * modification, are permitted provided that the following conditions
320  * are met:
321  * 1. Redistributions of source code must retain the above copyright
322  * notice, this list of conditions and the following disclaimer.
323  * 2. Redistributions in binary form must reproduce the above copyright
324  * notice, this list of conditions and the following disclaimer in the
325  * documentation and/or other materials provided with the distribution.
326  * 3. The name of the author may not be used to endorse or promote products
327  * derived from this software without specific prior written permission.
328
329  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
330  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
331  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
332  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
333  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
334  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
335  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
336  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
337  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
338  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
339  *
340  * SeqImpl.java
341  *
342  * Created on 08 August 2000, 17:10
343  */

344
Popular Tags