| 1 | /** |
| 2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.deduced.viewer.web.server; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | import java.util.Collections; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.deduced.PropertyChangeEvent; |
| 23 | import org.deduced.PropertyListener; |
| 24 | |
| 25 | /** |
| 26 | * |
| 27 | * ChangeEventAggregator is used to listen to change events and aggregate them |
| 28 | * in a list of synchronized change events. |
| 29 | * |
| 30 | * @author Steve McDuff |
| 31 | * |
| 32 | * @param <K> listener key |
| 33 | * @param <V> listener value |
| 34 | */ |
| 35 | public class ChangeEventAggregator<K, V> implements PropertyListener<K, V> |
| 36 | { |
| 37 | |
| 38 | /** |
| 39 | * monitored change event list |
| 40 | */ |
| 41 | private List<PropertyChangeEvent<? extends K, ? extends V>> changeEventList = |
| 42 | Collections |
| 43 | .synchronizedList(new ArrayList<PropertyChangeEvent<? extends K, ? extends V>>()); |
| 44 | |
| 45 | /** |
| 46 | * get the Change Event List. The list is synchronized so it is multi-thread |
| 47 | * safe. The caller can also modify the list as desired. A common usage is |
| 48 | * to purge the list of pending events. |
| 49 | * |
| 50 | * @return the change event list |
| 51 | */ |
| 52 | public List<PropertyChangeEvent<? extends K, ? extends V>> getChangeEventList() |
| 53 | { |
| 54 | return changeEventList; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * (non-JSDoc) |
| 59 | * |
| 60 | * @see org.deduced.PropertyListener#propertyChanged(org.deduced.PropertyChangeEvent) |
| 61 | */ |
| 62 | @Override |
| 63 | public void propertyChanged( |
| 64 | PropertyChangeEvent<? extends K, ? extends V> event) |
| 65 | { |
| 66 | changeEventList.add(event); |
| 67 | } |
| 68 | |
| 69 | } |