package votorola.s.gwt.stage.light; // Copyright 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.util.*; /** Collected lights and sensors on stage. * * @see votorola.s.gwt.stage.Stage#lightBank() */ public final class LightBank { /** Adds a light to the bank. * * @throws IllegalArgumentException if the light is already in the bank. * * @see #removeLight(Light) */ public void addLight( final Light light ) { if( lights.contains( light )) throw new IllegalArgumentException( "light already added" ); for( final Sensor1 sensor: sensors ) sensor.addingLight( light ); lights.add( light ); } /** Adds a sensor to the stage. * * @throws IllegalArgumentException if the sensor is already on stage. * * @see #removeSensor(Sensor1) */ public void addSensor( final Sensor1 sensor ) { if( sensors.contains( sensor )) throw new IllegalArgumentException( "sensor already added" ); for( final Light light: lights ) sensor.addingLight( light ); sensors.add( sensor ); } /** Removes a light from the bank. * * @throws IllegalArgumentException if the light is not in the bank. * * @see #addLight(Light) */ public void removeLight( final Light light ) { if( !lights.remove( light )) throw new IllegalArgumentException( "no such light" ); for( final Sensor1 sensor: sensors ) sensor.removingLight( light ); } /** Removes a sensor from the stage. * * @throws IllegalArgumentException if the sensor is not on stage. * * @see #addSensor(Sensor1) */ public void removeSensor( final Sensor1 sensor ) { if( !sensors.remove( sensor )) throw new IllegalArgumentException( "no such sensor" ); sensor.removed(); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final LinkedList> lights = new LinkedList>(); private final LinkedList sensors = new LinkedList(); }