LinkedCollectionIterator.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { JavaObject, cast_java_lang_Object } from '../../../java/lang/JavaObject';
  2. import { ConcurrentModificationException, cast_java_util_ConcurrentModificationException } from '../../../java/util/ConcurrentModificationException';
  3. import { LinkedCollection, cast_de_nrw_schule_svws_core_adt_collection_LinkedCollection } from '../../../core/adt/collection/LinkedCollection';
  4. import { JavaIterator, cast_java_util_Iterator } from '../../../java/util/JavaIterator';
  5. import { NoSuchElementException, cast_java_util_NoSuchElementException } from '../../../java/util/NoSuchElementException';
  6. import { LinkedCollectionElement, cast_de_nrw_schule_svws_core_adt_collection_LinkedCollectionElement } from '../../../core/adt/collection/LinkedCollectionElement';
  7. import { UnsupportedOperationException, cast_java_lang_UnsupportedOperationException } from '../../../java/lang/UnsupportedOperationException';
  8. export class LinkedCollectionIterator<E> extends JavaObject implements JavaIterator<E> {
  9. private _collection : LinkedCollection<E>;
  10. private _current : LinkedCollectionElement<E> | null = null;
  11. private readonly _expModCount : number;
  12. /**
  13. * Erzeugt einen neuen LinkedCollectionIterator. Dabei wird die Referenz auf
  14. * die {@link LinkedCollection} übergeben.
  15. *
  16. * @param collection die zum Iterator zugehörige {@link LinkedCollection}
  17. */
  18. constructor(collection : LinkedCollection<E>) {
  19. super();
  20. this._collection = collection;
  21. this._expModCount = collection._modCount;
  22. this._current = collection._head;
  23. }
  24. public hasNext() : boolean {
  25. if (this._collection._modCount !== this._expModCount)
  26. throw new ConcurrentModificationException()
  27. return (this._current !== null);
  28. }
  29. public next() : E {
  30. if (this._collection._modCount !== this._expModCount)
  31. throw new ConcurrentModificationException()
  32. if (this._current === null)
  33. throw new NoSuchElementException()
  34. let result : E = this._current.getValue();
  35. this._current = this._current.getNext();
  36. return result;
  37. }
  38. public remove() : void {
  39. throw new UnsupportedOperationException("remove")
  40. }
  41. isTranspiledInstanceOf(name : string): boolean {
  42. return ['java.util.Iterator', 'de.nrw.schule.svws.core.adt.collection.LinkedCollectionIterator'].includes(name);
  43. }
  44. }
  45. export function cast_de_nrw_schule_svws_core_adt_collection_LinkedCollectionIterator<E>(obj : unknown) : LinkedCollectionIterator<E> {
  46. return obj as LinkedCollectionIterator<E>;
  47. }