Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ListUtil |
|
| 0.0;0 |
1 | /* | |
2 | * Licensed under the MIT License | |
3 | * | |
4 | * Copyright 2010 (c) Flávio Silva, http://flsilva.com | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person | |
7 | * obtaining a copy of this software and associated documentation | |
8 | * files (the "Software"), to deal in the Software without | |
9 | * restriction, including without limitation the rights to use, | |
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the | |
12 | * Software is furnished to do so, subject to the following | |
13 | * conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be | |
16 | * included in all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
25 | * OTHER DEALINGS IN THE SOFTWARE. | |
26 | * | |
27 | * http://www.opensource.org/licenses/mit-license.php | |
28 | */ | |
29 | ||
30 | 1 | package org.as3collections.utils |
31 | { | |
32 | import org.as3collections.IList; | |
33 | import org.as3collections.ISortedList; | |
34 | import org.as3collections.lists.TypedList; | |
35 | import org.as3collections.lists.TypedSortedList; | |
36 | import org.as3collections.lists.UniqueList; | |
37 | import org.as3collections.lists.UniqueSortedList; | |
38 | ||
39 | import flash.errors.IllegalOperationError; | |
40 | ||
41 | /** | |
42 | * A utility class to work with implementations of the <code>IList</code> interface. | |
43 | * | |
44 | * @author Flávio Silva | |
45 | */ | |
46 | public class ListUtil | |
47 | { | |
48 | /** | |
49 | * <code>ListUtil</code> is a static class and shouldn't be instantiated. | |
50 | * | |
51 | * @throws IllegalOperationError <code>ListUtil</code> is a static class and shouldn't be instantiated. | |
52 | */ | |
53 | public function ListUtil() | |
54 | 1 | { |
55 | 1 | throw new IllegalOperationError("ListUtil is a static class and shouldn't be instantiated."); |
56 | } | |
57 | ||
58 | /** | |
59 | * Returns a new <code>TypedList</code> with the <code>wrapList</code> argument wrapped. | |
60 | * | |
61 | * @param wrapList the target list to be wrapped by the <code>TypedList</code>. | |
62 | * @param type the type of the elements allowed by the returned <code>TypedList</code>. | |
63 | * @throws ArgumentError if the <code>wrapList</code> argument is <code>null</code>. | |
64 | * @throws ArgumentError if the <code>type</code> argument is <code>null</code>. | |
65 | * @throws org.as3coreaddendum.errors.ClassCastError if the types of one or more elements in the <code>wrapList</code> argument are incompatible with the <code>type</code> argument. | |
66 | * @return a new <code>TypedList</code> with the <code>wrapList</code> argument wrapped. | |
67 | */ | |
68 | public static function getTypedList(wrapList:IList, type:*): TypedList | |
69 | { | |
70 | 1 | return new TypedList(wrapList, type); |
71 | } | |
72 | ||
73 | /** | |
74 | * Returns a new <code>TypedSortedList</code> with the <code>wrapList</code> argument wrapped. | |
75 | * | |
76 | * @param wrapList the target list to be wrapped by the <code>TypedSortedList</code>. | |
77 | * @param type the type of the elements allowed by the returned <code>TypedSortedList</code>. | |
78 | * @throws ArgumentError if the <code>wrapList</code> argument is <code>null</code>. | |
79 | * @throws ArgumentError if the <code>type</code> argument is <code>null</code>. | |
80 | * @throws org.as3coreaddendum.errors.ClassCastError if the types of one or more elements in the <code>wrapList</code> argument are incompatible with the <code>type</code> argument. | |
81 | * @return a new <code>TypedSortedList</code> with the <code>wrapList</code> argument wrapped. | |
82 | */ | |
83 | public static function getTypedSortedList(wrapList:ISortedList, type:*): TypedSortedList | |
84 | { | |
85 | 1 | return new TypedSortedList(wrapList, type); |
86 | } | |
87 | ||
88 | /** | |
89 | * Returns a new <code>UniqueList</code> with the <code>wrapList</code> argument wrapped. | |
90 | * | |
91 | * @param wrapList the target list to be wrapped by the <code>UniqueList</code>. | |
92 | * @throws ArgumentError if the <code>wrapList</code> argument is <code>null</code>. | |
93 | * @return a new <code>UniqueList</code> with the <code>wrapList</code> argument wrapped. | |
94 | */ | |
95 | public static function getUniqueList(wrapList:IList): UniqueList | |
96 | { | |
97 | 1 | return new UniqueList(wrapList); |
98 | } | |
99 | ||
100 | /** | |
101 | * Returns a new <code>UniqueSortedList</code> with the <code>wrapList</code> argument wrapped. | |
102 | * | |
103 | * @param wrapList the target list to be wrapped by the <code>UniqueSortedList</code>. | |
104 | * @throws ArgumentError if the <code>wrapList</code> argument is <code>null</code>. | |
105 | * @return a new <code>UniqueSortedList</code> with the <code>wrapList</code> argument wrapped. | |
106 | */ | |
107 | public static function getUniqueSortedList(wrapList:ISortedList): UniqueSortedList | |
108 | { | |
109 | 1 | return new UniqueSortedList(wrapList); |
110 | } | |
111 | ||
112 | /** | |
113 | * Returns a new <code>TypedList</code> that wraps a new <code>UniqueList</code> that wraps the <code>wrapList</code> argument. | |
114 | * <p>The result will be a unique and typed array list, despite of the return type <code>TypedList</code>.</p> | |
115 | * | |
116 | * @param wrapList the target list to be wrapped. | |
117 | * @param type the type of the elements allowed by the returned <code>TypedList</code>. | |
118 | * @throws ArgumentError if the <code>wrapList</code> argument is <code>null</code>. | |
119 | * @throws ArgumentError if the <code>type</code> argument is <code>null</code>. | |
120 | * @throws org.as3coreaddendum.errors.ClassCastError if the types of one or more elements in the <code>wrapList</code> argument are incompatible with the <code>type</code> argument. | |
121 | * @return a new <code>TypedList</code> that wraps a new <code>UniqueList</code> that wraps the <code>wrapList</code> argument. | |
122 | */ | |
123 | public static function getUniqueTypedList(wrapList:IList, type:*): TypedList | |
124 | { | |
125 | 1 | return new TypedList(new UniqueList(wrapList), type); |
126 | } | |
127 | ||
128 | /** | |
129 | * Returns a new <code>TypedSortedList</code> that wraps a new <code>UniqueSortedList</code> that wraps the <code>wrapList</code> argument. | |
130 | * <p>The result will be a unique and typed sorted list, despite of the return type <code>TypedSortedList</code>.</p> | |
131 | * | |
132 | * @param wrapList the target list to be wrapped. | |
133 | * @param type the type of the elements allowed by the returned <code>TypedSortedList</code>. | |
134 | * @throws ArgumentError if the <code>wrapList</code> argument is <code>null</code>. | |
135 | * @throws ArgumentError if the <code>type</code> argument is <code>null</code>. | |
136 | * @throws org.as3coreaddendum.errors.ClassCastError if the types of one or more elements in the <code>wrapList</code> argument are incompatible with the <code>type</code> argument. | |
137 | * @return a new <code>TypedSortedList</code> that wraps a new <code>UniqueSortedList</code> that wraps the <code>wrapList</code> argument. | |
138 | */ | |
139 | public static function getUniqueTypedSortedList(wrapList:ISortedList, type:*): TypedSortedList | |
140 | { | |
141 | 1 | return new TypedSortedList(new UniqueSortedList(wrapList), type); |
142 | } | |
143 | ||
144 | } | |
145 | ||
146 | } |