
package cz.karry.dop.core;

import java.util.ArrayList;

/**
 *
 * @author karry
 */
public class Signal {
    private boolean active = false;
    private String name;
    private ArrayList<SignalListener> listeners = new ArrayList<SignalListener>();

    public Signal(String name) {
        this.name = name;
    }
    
    public String getName(){
        return this.name;
    }
    
    public boolean isActive(){
        return this.active;
    }

    public void removeSignalListener(SignalListener listener) {
        listeners.remove(listener);
    }
    
    public void setState(boolean active){
        if (this.active == active)
            return;
        
        // System.out.println("signal "+getName()+" set "+(active?"up":"down"));
        
        this.active = active;
        for (int i=0; i< listeners.size(); i++){
            listeners.get(i).signalChangePerformed(this, active);
        }
    }
    
    public void addSignalListener(SignalListener listener){
        listeners.add(listener);
    }
    
    public ArrayList<SignalListener> getSignalListeners(){
        return this.listeners;
    }
    
}
