    001/*-
    002 * Copyright 2015, 2016 Diamond Light Source Ltd.
    003 *
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the Eclipse Public License v1.0
    006 * which accompanies this distribution, and is available at
    007 * http://www.eclipse.org/legal/epl-v10.html
    008 */
    009
    010package org.eclipse.january.dataset;
    011
    012import java.util.Collections;
    013import java.util.Set;
    014import java.util.concurrent.ConcurrentHashMap;
    015
    016/**
    017 * Class used by DynamicDataset to delegate
    018 */
    019public class DataListenerDelegate {
    020
    021        private Set<IDataListener> listeners;
    022
    023        public DataListenerDelegate() {
    024                listeners = Collections.newSetFromMap(new ConcurrentHashMap<IDataListener, Boolean>());
    025        }
    026
    027        public void addDataListener(IDataListener l) {
    028                listeners.add(l);
    029        }
    030
    031        public void removeDataListener(IDataListener l) {
    032                listeners.remove(l);
    033        }
    034
    035        public void fire(DataEvent evt) {
    036                for (IDataListener listener : listeners) {
    037                        listener.dataChangePerformed(evt);
    038                }
    039        }
    040
    041        public boolean hasDataListeners() {
    042                return listeners.size() > 0;
    043        }
    044
    045        public void clear() {
    046                listeners.clear();
    047        }
    048
    049}