Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LoadingMonitorRepository |
|
| 0.0;0 |
1 | /* | |
2 | * Licensed under the MIT License | |
3 | * | |
4 | * Copyright 2011 (c) Flávio Silva, 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 | 1 | package org.vostokframework.application.monitoring |
30 | { | |
31 | import org.as3collections.IList; | |
32 | import org.as3collections.IMap; | |
33 | import org.as3collections.lists.ReadOnlyArrayList; | |
34 | import org.as3collections.maps.HashMap; | |
35 | import org.as3collections.maps.TypedMap; | |
36 | import org.as3utils.ReflectionUtil; | |
37 | import org.vostokframework.VostokIdentification; | |
38 | import org.vostokframework.domain.loading.errors.DuplicateLoadingMonitorError; | |
39 | ||
40 | /** | |
41 | * description | |
42 | * | |
43 | * @author Flávio Silva | |
44 | */ | |
45 | public class LoadingMonitorRepository | |
46 | { | |
47 | private var _monitorMap:IMap;//<String,ILoadingMonitor> - where String = ILoadingMonitor.id | |
48 | ||
49 | /** | |
50 | * description | |
51 | */ | |
52 | public function LoadingMonitorRepository() | |
53 | 1 | { |
54 | 1 | _monitorMap = new TypedMap(new HashMap(), String, ILoadingMonitor); |
55 | 1 | } |
56 | ||
57 | /** | |
58 | * description | |
59 | * | |
60 | * @throws ArgumentError if the <code>report</code> argument is <code>null</code>. | |
61 | * @return | |
62 | */ | |
63 | public function add(monitor:ILoadingMonitor): void | |
64 | { | |
65 | 0 | if (!monitor) throw new ArgumentError("Argument <monitor> must not be null."); |
66 | ||
67 | 0 | if (_monitorMap.containsKey(monitor.loader.identification.toString())) |
68 | { | |
69 | 0 | var message:String = "There is already an ILoadingMonitor object stored with identification:\n"; |
70 | 0 | message += "<" + monitor.loader.identification + ">\n"; |
71 | 0 | message += "Use the method <LoadingMonitorRepository().exists()> to check if an ILoadingMonitor object already exists.\n"; |
72 | ||
73 | 0 | throw new DuplicateLoadingMonitorError(message); |
74 | } | |
75 | ||
76 | 0 | _monitorMap.put(monitor.loader.identification.toString(), monitor); |
77 | 0 | } |
78 | ||
79 | /** | |
80 | * description | |
81 | * | |
82 | * @return | |
83 | */ | |
84 | public function clear(): void | |
85 | { | |
86 | 1 | _monitorMap.clear(); |
87 | 1 | } |
88 | ||
89 | /** | |
90 | * description | |
91 | * | |
92 | * @param assetId | |
93 | * @throws ArgumentError if the <code>identification</code> argument is <code>null</code>. | |
94 | * @return | |
95 | */ | |
96 | public function exists(identification:VostokIdentification): Boolean | |
97 | { | |
98 | 0 | if (!identification) throw new ArgumentError("Argument <identification> must not be null."); |
99 | ||
100 | 0 | return _monitorMap.containsKey(identification.toString()); |
101 | } | |
102 | ||
103 | /** | |
104 | * description | |
105 | * | |
106 | * @param identification | |
107 | * @throws ArgumentError if the <code>identification</code> argument is <code>null</code>. | |
108 | * @return | |
109 | */ | |
110 | public function find(identification:VostokIdentification): ILoadingMonitor | |
111 | { | |
112 | 0 | if (!identification) throw new ArgumentError("Argument <identification> must not be null."); |
113 | ||
114 | 0 | return _monitorMap.getValue(identification.toString()); |
115 | } | |
116 | ||
117 | /** | |
118 | * description | |
119 | * | |
120 | * @return | |
121 | */ | |
122 | public function findAll(): IList | |
123 | { | |
124 | 0 | if (isEmpty()) return null; |
125 | 0 | var l:IList = new ReadOnlyArrayList(_monitorMap.getValues().toArray()); |
126 | ||
127 | 0 | return l; |
128 | } | |
129 | ||
130 | /** | |
131 | * description | |
132 | * | |
133 | * @return | |
134 | */ | |
135 | public function isEmpty(): Boolean | |
136 | { | |
137 | 0 | return _monitorMap.isEmpty(); |
138 | } | |
139 | ||
140 | /** | |
141 | * description | |
142 | * | |
143 | * @param assetId | |
144 | * @throws ArgumentError if the <code>assetId</code> argument is <code>null</code> or <code>empty</code>. | |
145 | * @return | |
146 | */ | |
147 | public function remove(identification:VostokIdentification): Boolean | |
148 | { | |
149 | 0 | if (!identification) throw new ArgumentError("Argument <identification> must not be null."); |
150 | ||
151 | 0 | return _monitorMap.remove(identification.toString()) != null; |
152 | } | |
153 | ||
154 | /** | |
155 | * description | |
156 | * | |
157 | * @return | |
158 | */ | |
159 | public function size(): int | |
160 | { | |
161 | 0 | return _monitorMap.size(); |
162 | } | |
163 | ||
164 | /** | |
165 | * description | |
166 | * | |
167 | * @return | |
168 | */ | |
169 | public function toString(): String | |
170 | { | |
171 | 0 | return "[" + ReflectionUtil.getClassName(this) + "] <" + _monitorMap.getValues() + ">"; |
172 | } | |
173 | ||
174 | } | |
175 | ||
176 | } |