Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Sequences |
|
| 0.0;0 | ||||
Sequences$Intf |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 | * | |
5 | * This code is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 only, as | |
7 | * published by the Free Software Foundation. Sun designates this | |
8 | * particular file as subject to the "Classpath" exception as provided | |
9 | * by Sun in the LICENSE file that accompanied this code. | |
10 | * | |
11 | * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | * version 2 for more details (a copy is included in the LICENSE file that | |
15 | * accompanied this code). | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License version | |
18 | * 2 along with this work; if not, write to the Free Software Foundation, | |
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 | * | |
21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
22 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
23 | * have any questions. | |
24 | */ | |
25 | ||
26 | package javafx.lang; | |
27 | ||
28 | import java.lang.Object; | |
29 | import java.lang.Comparable; | |
30 | import java.lang.System; | |
31 | import java.util.Comparator; | |
32 | ||
33 | import java.lang.UnsupportedOperationException; | |
34 | ||
35 | ||
36 | /** | |
37 | * This class contains various functions for manipulating sequences (such as | |
38 | * sorting and searching). All of these functions are nonmutative, they do not | |
39 | * change the input-parameters, but create new instances for output. | |
40 | * | |
41 | * @author Michael Heinrichs | |
42 | */ | |
43 | ||
44 | 6 | public class Sequences { |
45 | ||
46 | public static function isEqualByContentIdentity(seq1: Object[], seq2: Object[]): Boolean { | |
47 | 7 | return com.sun.javafx.runtime.sequence.Sequences.isEqualByContentIdentity(seq1, seq2); |
48 | } | |
49 | ||
50 | /** | |
51 | * Searches the specified sequence for the specified object using the | |
52 | * binary search algorithm. The sequence must be sorted into ascending | |
53 | * order according to the natural ordering of its elements (as by | |
54 | * the sort(Sequence<T>) method) prior to making this call. | |
55 | * | |
56 | * If it is not sorted, the results are undefined. If the array contains | |
57 | * multiple elements equal to the specified object, there is no guarantee | |
58 | * which one will be found. | |
59 | * | |
60 | * @param seq The sequence to be searched. | |
61 | * @param key The value to be searched for. | |
62 | * @return Index of the search key, if it is contained in the array; | |
63 | * otherwise, (-(insertion point) - 1). The insertion point is | |
64 | * defined as the point at which the key would be inserted into the | |
65 | * array: the index of the first element greater than the key, or | |
66 | * a.length if all elements in the array are less than the specified | |
67 | * key. Note that this guarantees that the return value will be >= 0 | |
68 | * if and only if the key is found. | |
69 | */ | |
70 | public static function binarySearch(seq: Comparable[], key: Comparable): Integer { | |
71 | 6 | return com.sun.javafx.runtime.sequence.Sequences.binarySearch(seq, key); |
72 | } | |
73 | ||
74 | /** | |
75 | * Searches the specified array for the specified object using the | |
76 | * binary search algorithm. The array must be sorted into ascending | |
77 | * order according to the specified comparator (as by the | |
78 | * sort(Sequence<T>, Comparator<? super T>) method) prior to making | |
79 | * this call. | |
80 | * | |
81 | * If it is not sorted, the results are undefined. If the array contains | |
82 | * multiple elements equal to the specified object, there is no guarantee | |
83 | * which one will be found. | |
84 | * | |
85 | * @param seq The sequence to be searched. | |
86 | * @param key The value to be searched for. | |
87 | * @param c The comparator by which the array is ordered. A null value | |
88 | * indicates that the elements' natural ordering should be used. | |
89 | * @return Index of the search key, if it is contained in the array; | |
90 | * otherwise, (-(insertion point) - 1). The insertion point is | |
91 | * defined as the point at which the key would be inserted into the | |
92 | * array: the index of the first element greater than the key, or | |
93 | * a.length if all elements in the array are less than the specified | |
94 | * key. Note that this guarantees that the return value will be >= 0 | |
95 | * if and only if the key is found. | |
96 | */ | |
97 | public static function binarySearch(seq: Object[], key: Object, c: Comparator): Integer { | |
98 | 8 | return com.sun.javafx.runtime.sequence.Sequences.binarySearch(seq, key, c); |
99 | } | |
100 | ||
101 | /** | |
102 | * Searches the specified sequence for the specified object. | |
103 | * | |
104 | * If the sequence contains multiple elements equal to the specified object, | |
105 | * the first occurence in the sequence will be returned. | |
106 | * | |
107 | * The method nextIndexOf can be used in consecutive calls to iterate | |
108 | * through all occurences of a specified object. | |
109 | * | |
110 | * @param seq The sequence to be searched. | |
111 | * @param key The value to be searched for. | |
112 | * @return Index of the search key, if it is contained in the array; | |
113 | * otherwise -1. | |
114 | */ | |
115 | public static function indexByIdentity(seq: Object[], key: Object): Integer { | |
116 | 11 | return com.sun.javafx.runtime.sequence.Sequences.indexByIdentity(seq, key); |
117 | } | |
118 | ||
119 | /** | |
120 | * Searches the specified sequence for an object with the same value. The | |
121 | * objects are compared using the method equals(). If the sequence is sorted, | |
122 | * binarySearch should be used instead. | |
123 | * | |
124 | * If the sequence contains multiple elements equal to the specified object, | |
125 | * the first occurence in the sequence will be returned. | |
126 | * | |
127 | * The method nextIndexOf can be used in consecutive calls to iterate | |
128 | * through all occurences of a specified object. | |
129 | * | |
130 | * @param seq The sequence to be searched. | |
131 | * @param key The value to be searched for. | |
132 | * @return Index of the search key, if it is contained in the array; | |
133 | * otherwise -1. | |
134 | */ | |
135 | public static function indexOf(seq: Object[], key: Object): Integer { | |
136 | 10 | return com.sun.javafx.runtime.sequence.Sequences.indexOf(seq, key); |
137 | } | |
138 | ||
139 | /** | |
140 | * Returns the element with the maximum value in the specified sequence, | |
141 | * according to the natural ordering of its elements. All elements in the | |
142 | * sequence must implement the Comparable interface. Furthermore, all | |
143 | * elements in the sequence must be mutually comparable (that is, | |
144 | * e1.compareTo(e2) must not throw a ClassCastException for any elements | |
145 | * e1 and e2 in the sequence). | |
146 | * | |
147 | * If the sequence contains multiple elements with the maximum value, | |
148 | * there is no guarantee which one will be found. | |
149 | * | |
150 | * @param seq The sequence to be searched. | |
151 | * @return The element with the maximum value. | |
152 | */ | |
153 | public static function max(seq: Comparable[]): Comparable { | |
154 | 6 | return com.sun.javafx.runtime.sequence.Sequences.max(seq); |
155 | } | |
156 | ||
157 | /** | |
158 | * Returns the element with the maximum value in the specified sequence, | |
159 | * according to the specified comparator. All elements in the sequence must | |
160 | * be mutually comparable by the specified comparator (that is, | |
161 | * c.compare(e1, e2) must not throw a ClassCastException for any elements | |
162 | * e1 and e2 in the sequence). | |
163 | * | |
164 | * If the sequence contains multiple elements with the maximum value, | |
165 | * there is no guarantee which one will be found. | |
166 | * | |
167 | * @param seq The sequence to be searched. | |
168 | * @param c The comparator to determine the order of the sequence. | |
169 | * A null value indicates that the elements' natural ordering | |
170 | * should be used. | |
171 | * @return The element with the maximum value. | |
172 | */ | |
173 | public static function max(seq: Object[], c: Comparator): Object { | |
174 | 7 | return com.sun.javafx.runtime.sequence.Sequences.max(seq, c); |
175 | } | |
176 | ||
177 | /** | |
178 | * Returns the element with the minimum value in the specified sequence, | |
179 | * according to the natural ordering of its elements. All elements in the | |
180 | * sequence must implement the Comparable interface. Furthermore, all | |
181 | * elements in the sequence must be mutually comparable (that is, | |
182 | * e1.compareTo(e2) must not throw a ClassCastException for any elements | |
183 | * e1 and e2 in the sequence). | |
184 | * | |
185 | * If the sequence contains multiple elements with the minimum value, | |
186 | * there is no guarantee which one will be found. | |
187 | * | |
188 | * @param seq The sequence to be searched. | |
189 | * @return The element with the maximum value. | |
190 | */ | |
191 | public static function min(seq: Comparable[]): Comparable { | |
192 | 6 | return com.sun.javafx.runtime.sequence.Sequences.min(seq); |
193 | } | |
194 | ||
195 | /** | |
196 | * Returns the element with the minimum value in the specified sequence, | |
197 | * according to the specified comparator. All elements in the sequence must | |
198 | * be mutually comparable by the specified comparator (that is, | |
199 | * c.compare(e1, e2) must not throw a ClassCastException for any elements | |
200 | * e1 and e2 in the sequence). | |
201 | * | |
202 | * If the sequence contains multiple elements with the minimum value, | |
203 | * there is no guarantee which one will be found. | |
204 | * | |
205 | * @param seq The sequence to be searched. | |
206 | * @param c The comparator to determine the order of the sequence. | |
207 | * A null value indicates that the elements' natural ordering | |
208 | * should be used. | |
209 | * @return The element with the minimum value. | |
210 | */ | |
211 | public static function min(seq: Object[], c: Comparator): Object { | |
212 | 7 | return com.sun.javafx.runtime.sequence.Sequences.min(seq, c); |
213 | } | |
214 | ||
215 | /** | |
216 | * Searches the specified sequence for an object with the same value, | |
217 | * starting the search at the specified position. The objects are compared | |
218 | * using the method equals(). | |
219 | * | |
220 | * If the sequence contains multiple elements equal to the specified object, | |
221 | * the first occurence in the subsequence will be returned. | |
222 | * | |
223 | * @param seq The sequence to be searched. | |
224 | * @param key The value to be searched for. | |
225 | * @param pos The position in the sequence to start the search. If pos is | |
226 | * negative or 0 the whole sequence will be searched. | |
227 | * @return Index of the search key, if it is contained in the array; | |
228 | * otherwise -1. | |
229 | */ | |
230 | public static function nextIndexByIdentity(seq: Object[], key: Object, pos: Integer): Integer { | |
231 | 7 | return com.sun.javafx.runtime.sequence.Sequences.nextIndexByIdentity(seq, key, pos); |
232 | } | |
233 | ||
234 | /** | |
235 | * Searches the specified sequence for the specified object, starting the | |
236 | * search at the specified position. | |
237 | * | |
238 | * If the sequence contains multiple elements equal to the specified object, | |
239 | * the first occurence in the subsequence will be returned. | |
240 | * | |
241 | * @param seq The sequence to be searched. | |
242 | * @param key The value to be searched for. | |
243 | * @param pos The position in the sequence to start the search. If pos is | |
244 | * negative or 0 the whole sequence will be searched. | |
245 | * @return Index of the search key, if it is contained in the array; | |
246 | * otherwise -1. | |
247 | */ | |
248 | public static function nextIndexOf(seq: Object[], key: Object, pos: Integer): Integer { | |
249 | 6 | return com.sun.javafx.runtime.sequence.Sequences.nextIndexOf(seq, key, pos); |
250 | } | |
251 | ||
252 | public static function <<reverse>> (seq:Object[]): Object[] { | |
253 | 3 | return com.sun.javafx.runtime.sequence.Sequences.<<reverse>>(seq); |
254 | } | |
255 | ||
256 | /** | |
257 | * Sorts the specified sequence of objects into ascending order, according | |
258 | * to the natural ordering of its elements. All elements in the sequence | |
259 | * must implement the Comparable interface. Furthermore, all elements in | |
260 | * the sequence must be mutually comparable (that is, e1.compareTo(e2) | |
261 | * must not throw a ClassCastException for any elements e1 and e2 in the | |
262 | * sequence). | |
263 | * | |
264 | * This method is immutative, the result is returned in a new sequence, | |
265 | * while the original sequence is left untouched. | |
266 | * | |
267 | * This sort is guaranteed to be stable: equal elements will not be | |
268 | * reordered as a result of the sort. | |
269 | * | |
270 | * The sorting algorithm is a modified mergesort (in which the merge is | |
271 | * omitted if the highest element in the low sublist is less than the | |
272 | * lowest element in the high sublist). This algorithm offers guaranteed | |
273 | * n*log(n) performance. | |
274 | * | |
275 | * @param seq The sequence to be sorted. | |
276 | * @return The sorted sequence. | |
277 | */ | |
278 | public static function sort(seq: Comparable[]): Comparable[] { | |
279 | 11 | return com.sun.javafx.runtime.sequence.Sequences.sort(seq); |
280 | } | |
281 | ||
282 | /** | |
283 | * Sorts the specified sequence of objects according to the order induced | |
284 | * by the specified comparator. All elements in the sequence must be | |
285 | * mutually comparable by the specified comparator (that is, | |
286 | * c.compare(e1, e2) must not throw a ClassCastException for any elements | |
287 | * e1 and e2 in the sequence). | |
288 | * | |
289 | * This method is immutative, the result is returned in a new sequence, | |
290 | * while the original sequence is left untouched. | |
291 | * | |
292 | * This sort is guaranteed to be stable: equal elements will not be | |
293 | * reordered as a result of the sort. | |
294 | * | |
295 | * The sorting algorithm is a modified mergesort (in which the merge is | |
296 | * omitted if the highest element in the low sublist is less than the | |
297 | * lowest element in the high sublist). This algorithm offers guaranteed | |
298 | * n*log(n) performance. | |
299 | * | |
300 | * @param seq The sequence to be sorted. | |
301 | * @param c The comparator to determine the order of the sequence. | |
302 | * A null value indicates that the elements' natural ordering | |
303 | * should be used. | |
304 | * @return The sorted sequence. | |
305 | */ | |
306 | 0 | public static function sort(seq: Object[], c: Comparator): Object[] { |
307 | 6 | return com.sun.javafx.runtime.sequence.Sequences.sort(seq, c); |
308 | } | |
309 | } |