GeometryCollectionIterator.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import Iterator from '../../../../java/util/Iterator'
  2. import NoSuchElementException from '../../../../java/util/NoSuchElementException'
  3. import GeometryCollection from './GeometryCollection'
  4. import UnsupportedOperationException from '../../../../java/lang/UnsupportedOperationException'
  5. export default class GeometryCollectionIterator {
  6. constructor() {
  7. GeometryCollectionIterator.constructor_.apply(this, arguments)
  8. }
  9. static constructor_() {
  10. this._parent = null
  11. this._atStart = null
  12. this._max = null
  13. this._index = null
  14. this._subcollectionIterator = null
  15. const parent = arguments[0]
  16. this._parent = parent
  17. this._atStart = true
  18. this._index = 0
  19. this._max = parent.getNumGeometries()
  20. }
  21. static isAtomic(geom) {
  22. return !(geom instanceof GeometryCollection)
  23. }
  24. next() {
  25. if (this._atStart) {
  26. this._atStart = false
  27. if (GeometryCollectionIterator.isAtomic(this._parent)) this._index++
  28. return this._parent
  29. }
  30. if (this._subcollectionIterator !== null)
  31. if (this._subcollectionIterator.hasNext())
  32. return this._subcollectionIterator.next()
  33. else
  34. this._subcollectionIterator = null
  35. if (this._index >= this._max)
  36. throw new NoSuchElementException()
  37. const obj = this._parent.getGeometryN(this._index++)
  38. if (obj instanceof GeometryCollection) {
  39. this._subcollectionIterator = new GeometryCollectionIterator(obj)
  40. return this._subcollectionIterator.next()
  41. }
  42. return obj
  43. }
  44. remove() {
  45. throw new UnsupportedOperationException(this.getClass().getName())
  46. }
  47. hasNext() {
  48. if (this._atStart)
  49. return true
  50. if (this._subcollectionIterator !== null) {
  51. if (this._subcollectionIterator.hasNext())
  52. return true
  53. this._subcollectionIterator = null
  54. }
  55. if (this._index >= this._max)
  56. return false
  57. return true
  58. }
  59. get interfaces_() {
  60. return [Iterator]
  61. }
  62. }