source: gs2-extensions/tdb/trunk/src/java/org/greenstone/tdbjava/TDBJavaKeyEnumeration.java@ 30193

Last change on this file since 30193 was 30193, checked in by jmt12, 9 years ago

Initial checkin of Java->JNI->TDB wrapper

File size: 1.8 KB
Line 
1/*
2 * Copyright (C) 2015 Greenstone Digital Library, University of Waikato
3 * $Id$
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20package org.greenstone.tdbjava;
21
22import java.util.Enumeration;
23import java.util.NoSuchElementException;
24
25import org.greenstone.tdbjava.TDBJava;
26import org.greenstone.tdbjava.TDBJavaException;
27
28class TDBJavaKeyEnumeration
29 implements Enumeration
30{
31 private TDBJava db_driver;
32 private String current_key;
33 private String next_key;
34
35 TDBJavaKeyEnumeration(TDBJava db_driver)
36 throws TDBJavaException
37 {
38 this.db_driver = db_driver;
39 this.current_key = null;
40 this.next_key = this.db_driver.getFirstKey();
41 }
42
43 public boolean hasMoreElements()
44 {
45 return (this.next_key != null);
46 }
47
48 public Object nextElement()
49 throws NoSuchElementException
50 {
51 try {
52 this.current_key = this.next_key;
53 if (this.current_key == null) {
54 throw new NoSuchElementException();
55 }
56 else {
57 this.next_key = this.db_driver.getNextKey(this.current_key);
58 }
59 }
60 catch (Exception e) {
61 throw new NoSuchElementException();
62 }
63 return this.current_key;
64 }
65}
Note: See TracBrowser for help on using the repository browser.