Du bist hier: Snippet-Verzeichnis » Java (241)
Sprache:

Agilesoft Collection Iterator

Sprache: English
Programmiersprache: Java
Veröffentlicht von: ashleym [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 971


Beschreibung

This is an Iterator class for an Agilesoft API Collection.

Code

1 package com.agilesoft.api.iterator; 2 3 import com.agilesoft.api.APIException; 4 import com.agilesoft.api.Collection; 5 6 import java.util.NoSuchElementException; 7 8 /** 9 * This class simplifies the iterator of an Agilesoft API collection.<br> 10 * It should not exist. The Collection class should have an iterator method 11 * that returns a standard java.util.Iterator class. 12 * 13 * @author Ashley Martens 14 * @version 1.0 15 */ 16 public class CollectionIterator 17 implements java.util.Iterator 18 { 19 protected Collection m_oCollection = null; 20 protected int m_iCollectionCounter = 0, 21 m_iRowCount = 0; 22 23 /** 24 * Create the iterator 25 */ 26 public CollectionIterator(Collection collection) 27 throws com.agilesoft.api.APIException 28 { 29 m_iRowCount = collection.getCount(); 30 m_oCollection = collection; 31 } 32 33 /** 34 * Will next() return a valid object 35 */ 36 public boolean hasNext() 37 { 38 if (m_iCollectionCounter >= m_iRowCount) { 39 if (m_oCollection != null) { 40 m_oCollection.compact(); 41 } 42 } 43 return m_iCollectionCounter < m_iRowCount; 44 } 45 46 /** 47 * Return the next object in the table 48 */ 49 public Object next() 50 throws NoSuchElementException 51 { 52 Object oRet = null; 53 if (hasNext()) { 54 try { 55 oRet = m_oCollection.get(m_iCollectionCounter); 56 m_iCollectionCounter++; 57 } catch (APIException a) { 58 NoSuchElementException e = 59 new NoSuchElementException(a.getMessage()); 60 e.initCause(a); 61 throw e; 62 } 63 } else { 64 throw new NoSuchElementException(); 65 } 66 return oRet; 67 } 68 69 /** 70 * This is an unsupported feature 71 */ 72 public void remove() 73 throws UnsupportedOperationException, IllegalStateException 74 { 75 try { 76 m_oCollection.remove(m_iCollectionCounter--); 77 } catch (APIException e) { 78 IllegalStateException i = new IllegalStateException(e.getMessage()); 79 i.initCause(e); 80 throw i; 81 } 82 } 83 }

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS