AVLMapSubCollectionIterator.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { JavaObject, cast_java_lang_Object } from '../../../java/lang/JavaObject';
  2. import { IllegalStateException, cast_java_lang_IllegalStateException } from '../../../java/lang/IllegalStateException';
  3. import { AVLMapNode, cast_de_nrw_schule_svws_core_adt_map_AVLMapNode } from '../../../core/adt/map/AVLMapNode';
  4. import { JavaIterator, cast_java_util_Iterator } from '../../../java/util/JavaIterator';
  5. import { NoSuchElementException, cast_java_util_NoSuchElementException } from '../../../java/util/NoSuchElementException';
  6. import { AVLMapSubMap, cast_de_nrw_schule_svws_core_adt_map_AVLMapSubMap } from '../../../core/adt/map/AVLMapSubMap';
  7. export class AVLMapSubCollectionIterator<K, V> extends JavaObject implements JavaIterator<V> {
  8. private readonly _sub : AVLMapSubMap<K, V>;
  9. private _current : AVLMapNode<K, V> | null = null;
  10. private _next : AVLMapNode<K, V> | null = null;
  11. /**
  12. * Erstellt einen neuen VALUES-Iterator, welcher auf der {@link AVLMapSubMap} operiert.
  13. *
  14. * @param sub Die {@link AVLMapSubMap} auf der dieser Iterator operiert.
  15. */
  16. constructor(sub : AVLMapSubMap<K, V>) {
  17. super();
  18. this._sub = sub;
  19. this._current = null;
  20. this._next = this._sub.firstEntryAsNode();
  21. }
  22. public next() : V {
  23. if (this._next === null)
  24. throw new NoSuchElementException()
  25. this._current = this._next;
  26. this._next = this._sub.nextEntryOrNull(this._current);
  27. return this._current._val;
  28. }
  29. public hasNext() : boolean {
  30. return this._next !== null;
  31. }
  32. public remove() : void {
  33. if (this._current === null)
  34. throw new IllegalStateException()
  35. this._sub.remove(this._current.getKey());
  36. this._current = null;
  37. }
  38. isTranspiledInstanceOf(name : string): boolean {
  39. return ['java.util.Iterator', 'de.nrw.schule.svws.core.adt.map.AVLMapSubCollectionIterator'].includes(name);
  40. }
  41. }
  42. export function cast_de_nrw_schule_svws_core_adt_map_AVLMapSubCollectionIterator<K, V>(obj : unknown) : AVLMapSubCollectionIterator<K, V> {
  43. return obj as AVLMapSubCollectionIterator<K, V>;
  44. }