AVLSet.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { NavigableSet, cast_java_util_NavigableSet } from '../../../java/util/NavigableSet';
  2. import { JavaIterator, cast_java_util_Iterator } from '../../../java/util/JavaIterator';
  3. import { Collection, cast_java_util_Collection } from '../../../java/util/Collection';
  4. import { JavaObject, cast_java_lang_Object } from '../../../java/lang/JavaObject';
  5. import { SortedSet, cast_java_util_SortedSet } from '../../../java/util/SortedSet';
  6. import { AVLMap, cast_de_nrw_schule_svws_core_adt_map_AVLMap } from '../../../core/adt/map/AVLMap';
  7. import { Comparator, cast_java_util_Comparator } from '../../../java/util/Comparator';
  8. export class AVLSet<E> extends JavaObject implements NavigableSet<E> {
  9. private readonly _set : NavigableSet<E>;
  10. /**
  11. * Erzeugt ein leeres Set, welche bei den Schlüsselwerten die natürliche Ordnung des {@link Comparable} -
  12. * Interface nutzt.
  13. */
  14. public constructor();
  15. /**
  16. * Erstellt eine neues Setp und nutzt dabei die angegeben Ordnung der Schlüssel.
  17. *
  18. * @param comparator Die Ordnung für die Schlüssel.
  19. */
  20. public constructor(comparator : Comparator<E>);
  21. /**
  22. * Erstellt ein neues Set mit den Daten des angegebenen Sets und nutzt dabei die Ordnung dieses Sets.
  23. *
  24. * @param set Die Map mit den Daten.
  25. */
  26. public constructor(set : SortedSet<E>);
  27. /**
  28. * Implementation for method overloads of 'constructor'
  29. */
  30. public constructor(__param0? : Comparator<E> | SortedSet<E>) {
  31. super();
  32. if ((typeof __param0 === "undefined")) {
  33. let map : AVLMap<E, E> = new AVLMap();
  34. map.allowKeyAlone(true);
  35. this._set = map.navigableKeySet();
  36. } else if (((typeof __param0 !== "undefined") && ((typeof __param0 !== 'undefined') && (__param0 instanceof Object) && (__param0 !== null) && ('compare' in __param0) && (typeof __param0.compare === 'function')) || (__param0 === null))) {
  37. let comparator : Comparator<E> = cast_java_util_Comparator(__param0);
  38. let map : AVLMap<E, E> = new AVLMap(comparator);
  39. map.allowKeyAlone(true);
  40. this._set = map.navigableKeySet();
  41. } else if (((typeof __param0 !== "undefined") && ((__param0 instanceof JavaObject) && (__param0.isTranspiledInstanceOf('java.util.SortedSet'))) || (__param0 === null))) {
  42. let set : SortedSet<E> = cast_java_util_SortedSet(__param0);
  43. let map : AVLMap<E, E> = new AVLMap();
  44. map.allowKeyAlone(true);
  45. this._set = map.navigableKeySet();
  46. this._set.addAll(set);
  47. } else throw new Error('invalid method overload');
  48. }
  49. public comparator() : Comparator<Partial<E>> {
  50. return this._set.comparator();
  51. }
  52. public first() : E {
  53. return this._set.first();
  54. }
  55. public last() : E {
  56. return this._set.last();
  57. }
  58. public size() : number {
  59. return this._set.size();
  60. }
  61. public isEmpty() : boolean {
  62. return this._set.isEmpty();
  63. }
  64. public contains(o : unknown) : boolean {
  65. return this._set.contains(o);
  66. }
  67. public toArray() : Array<unknown>;
  68. public toArray<T>(a : Array<T>) : Array<T>;
  69. /**
  70. * Implementation for method overloads of 'toArray'
  71. */
  72. public toArray<T>(__param0? : Array<T>) : Array<T> | Array<unknown> {
  73. if ((typeof __param0 === "undefined")) {
  74. return this._set.toArray();
  75. } else if (((typeof __param0 !== "undefined") && Array.isArray(__param0))) {
  76. let a : Array<T> = __param0;
  77. return this._set.toArray(a);
  78. } else throw new Error('invalid method overload');
  79. }
  80. public add(e : E) : boolean {
  81. return this._set.add(e);
  82. }
  83. public remove(o : unknown) : boolean {
  84. return this._set.remove(o);
  85. }
  86. public containsAll(c : Collection<unknown>) : boolean {
  87. return this._set.containsAll(c);
  88. }
  89. public addAll(c : Collection<E>) : boolean {
  90. return this._set.addAll(c);
  91. }
  92. public retainAll(c : Collection<unknown>) : boolean {
  93. return this._set.retainAll(c);
  94. }
  95. public removeAll(c : Collection<unknown>) : boolean {
  96. return this._set.removeAll(c);
  97. }
  98. public clear() : void {
  99. this._set.clear();
  100. }
  101. public lower(e : E) : E | null {
  102. return this._set.lower(e);
  103. }
  104. public floor(e : E) : E | null {
  105. return this._set.floor(e);
  106. }
  107. public ceiling(e : E) : E | null {
  108. return this._set.ceiling(e);
  109. }
  110. public higher(e : E) : E | null {
  111. return this._set.higher(e);
  112. }
  113. public pollFirst() : E | null {
  114. return this._set.pollFirst();
  115. }
  116. public pollLast() : E | null {
  117. return this._set.pollLast();
  118. }
  119. public iterator() : JavaIterator<E> {
  120. return this._set.iterator();
  121. }
  122. public descendingSet() : NavigableSet<E> {
  123. return this._set.descendingSet();
  124. }
  125. public descendingIterator() : JavaIterator<E> {
  126. return this._set.descendingIterator();
  127. }
  128. public subSet(fromElement : E, fromInclusive : boolean, toElement : E, toInclusive : boolean) : NavigableSet<E>;
  129. public subSet(fromElement : E, toElement : E) : SortedSet<E>;
  130. /**
  131. * Implementation for method overloads of 'subSet'
  132. */
  133. public subSet(__param0 : E, __param1 : E | boolean, __param2? : E, __param3? : boolean) : NavigableSet<E> | SortedSet<E> {
  134. if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && typeof __param1 === "boolean") && ((typeof __param2 !== "undefined") && (typeof __param2 !== "undefined")) && ((typeof __param3 !== "undefined") && typeof __param3 === "boolean")) {
  135. let fromElement : E = __param0 as unknown as E;
  136. let fromInclusive : boolean = __param1 as boolean;
  137. let toElement : E = __param2 as unknown as E;
  138. let toInclusive : boolean = __param3 as boolean;
  139. return this._set.subSet(fromElement, fromInclusive, toElement, toInclusive);
  140. } else if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && (typeof __param1 !== "undefined")) && (typeof __param2 === "undefined") && (typeof __param3 === "undefined")) {
  141. let fromElement : E = __param0 as unknown as E;
  142. let toElement : E = __param1 as unknown as E;
  143. return this._set.subSet(fromElement, toElement);
  144. } else throw new Error('invalid method overload');
  145. }
  146. public headSet(toElement : E, inclusive : boolean) : NavigableSet<E>;
  147. public headSet(toElement : E) : SortedSet<E>;
  148. /**
  149. * Implementation for method overloads of 'headSet'
  150. */
  151. public headSet(__param0 : E, __param1? : boolean) : NavigableSet<E> | SortedSet<E> {
  152. if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && typeof __param1 === "boolean")) {
  153. let toElement : E = __param0 as unknown as E;
  154. let inclusive : boolean = __param1 as boolean;
  155. return this._set.headSet(toElement, inclusive);
  156. } else if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && (typeof __param1 === "undefined")) {
  157. let toElement : E = __param0 as unknown as E;
  158. return this._set.headSet(toElement);
  159. } else throw new Error('invalid method overload');
  160. }
  161. public tailSet(fromElement : E, inclusive : boolean) : NavigableSet<E>;
  162. public tailSet(fromElement : E) : SortedSet<E>;
  163. /**
  164. * Implementation for method overloads of 'tailSet'
  165. */
  166. public tailSet(__param0 : E, __param1? : boolean) : NavigableSet<E> | SortedSet<E> {
  167. if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && typeof __param1 === "boolean")) {
  168. let fromElement : E = __param0 as unknown as E;
  169. let inclusive : boolean = __param1 as boolean;
  170. return this._set.tailSet(fromElement, inclusive);
  171. } else if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && (typeof __param1 === "undefined")) {
  172. let fromElement : E = __param0 as unknown as E;
  173. return this._set.tailSet(fromElement);
  174. } else throw new Error('invalid method overload');
  175. }
  176. isTranspiledInstanceOf(name : string): boolean {
  177. return ['java.util.SortedSet', 'java.util.Collection', 'de.nrw.schule.svws.core.adt.set.AVLSet', 'java.util.Set', 'java.util.NavigableSet', 'java.lang.Iterable'].includes(name);
  178. }
  179. public [Symbol.iterator](): Iterator<E> {
  180. let iter : JavaIterator<E> = this.iterator();
  181. const result : Iterator<E> = {
  182. next() : IteratorResult<E> {
  183. if (iter.hasNext())
  184. return { value : iter.next(), done : false };
  185. return { value : null, done : true };
  186. }
  187. };
  188. return result;
  189. }
  190. }
  191. export function cast_de_nrw_schule_svws_core_adt_set_AVLSet<E>(obj : unknown) : AVLSet<E> {
  192. return obj as AVLSet<E>;
  193. }