AVLMapSubCollection.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { JavaIterator, cast_java_util_Iterator } from '../../../java/util/JavaIterator';
  2. import { Collection, cast_java_util_Collection } from '../../../java/util/Collection';
  3. import { JavaObject, cast_java_lang_Object } from '../../../java/lang/JavaObject';
  4. import { JavaString, cast_java_lang_String } from '../../../java/lang/JavaString';
  5. import { AVLMapSubMap, cast_de_nrw_schule_svws_core_adt_map_AVLMapSubMap } from '../../../core/adt/map/AVLMapSubMap';
  6. import { UnsupportedOperationException, cast_java_lang_UnsupportedOperationException } from '../../../java/lang/UnsupportedOperationException';
  7. export class AVLMapSubCollection<K, V> extends JavaObject implements Collection<V> {
  8. private readonly _sub : AVLMapSubMap<K, V>;
  9. /**
  10. * Erstellt eine neue Sub-Collection zur übergebenen {@link AVLMapSubMap}.
  11. *
  12. * @param sub Die {@link AVLMapSubMap} auf der diese Sub-Collection operiert.
  13. */
  14. constructor(sub : AVLMapSubMap<K, V>) {
  15. super();
  16. this._sub = sub;
  17. }
  18. public toString() : String {
  19. let s : String | null = "";
  20. for (let value of this)
  21. s += (s.length === 0 ? "" : ", ") + value;
  22. return "values = [" + s.valueOf() + "], size = " + this.size() + " --> " + this._sub.toString().valueOf();
  23. }
  24. public size() : number {
  25. return this._sub.size();
  26. }
  27. public isEmpty() : boolean {
  28. return this._sub.isEmpty();
  29. }
  30. public contains(o : unknown) : boolean {
  31. return this._sub.containsValue(o);
  32. }
  33. public iterator() : JavaIterator<V> {
  34. return this._sub.bcGetSubCollectionIterator();
  35. }
  36. public toArray() : Array<unknown | null>;
  37. public toArray<T>(a : Array<T | null>) : Array<T | null>;
  38. /**
  39. * Implementation for method overloads of 'toArray'
  40. */
  41. public toArray<T>(__param0? : Array<T | null>) : Array<T | null> | Array<unknown | null> {
  42. if ((typeof __param0 === "undefined")) {
  43. return this._sub.bcGetArrayListOfValues().toArray();
  44. } else if (((typeof __param0 !== "undefined") && Array.isArray(__param0))) {
  45. let a : Array<T | null> = __param0;
  46. return this._sub.bcGetArrayListOfValues().toArray(a);
  47. } else throw new Error('invalid method overload');
  48. }
  49. public add(e : V) : boolean {
  50. throw new UnsupportedOperationException()
  51. }
  52. public remove(o : unknown) : boolean {
  53. throw new UnsupportedOperationException()
  54. }
  55. public containsAll(c : Collection<unknown>) : boolean {
  56. return this._sub.bcContainsAllValues(c);
  57. }
  58. public addAll(c : Collection<V>) : boolean {
  59. throw new UnsupportedOperationException()
  60. }
  61. public removeAll(c : Collection<unknown>) : boolean {
  62. throw new UnsupportedOperationException()
  63. }
  64. public retainAll(c : Collection<unknown>) : boolean {
  65. throw new UnsupportedOperationException()
  66. }
  67. public clear() : void {
  68. this._sub.clear();
  69. }
  70. isTranspiledInstanceOf(name : string): boolean {
  71. return ['de.nrw.schule.svws.core.adt.map.AVLMapSubCollection', 'java.util.Collection', 'java.lang.Iterable'].includes(name);
  72. }
  73. public [Symbol.iterator](): Iterator<V> {
  74. let iter : JavaIterator<V> = this.iterator();
  75. const result : Iterator<V> = {
  76. next() : IteratorResult<V> {
  77. if (iter.hasNext())
  78. return { value : iter.next(), done : false };
  79. return { value : null, done : true };
  80. }
  81. };
  82. return result;
  83. }
  84. }
  85. export function cast_de_nrw_schule_svws_core_adt_map_AVLMapSubCollection<K, V>(obj : unknown) : AVLMapSubCollection<K, V> {
  86. return obj as AVLMapSubCollection<K, V>;
  87. }