001package 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. 002 003import java.util.*; 004 005 006/** Collected lights and sensors on stage. 007 * 008 * @see votorola.s.gwt.stage.Stage#lightBank() 009 */ 010public final class LightBank 011{ 012 013 014 /** Adds a light to the bank. 015 * 016 * @throws IllegalArgumentException if the light is already in the bank. 017 * 018 * @see #removeLight(Light) 019 */ 020 public void addLight( final Light<? extends Sensor> light ) 021 { 022 if( lights.contains( light )) throw new IllegalArgumentException( "light already added" ); 023 024 for( final Sensor1 sensor: sensors ) sensor.addingLight( light ); 025 lights.add( light ); 026 } 027 028 029 030 /** Adds a sensor to the stage. 031 * 032 * @throws IllegalArgumentException if the sensor is already on stage. 033 * 034 * @see #removeSensor(Sensor1) 035 */ 036 public void addSensor( final Sensor1 sensor ) 037 { 038 if( sensors.contains( sensor )) throw new IllegalArgumentException( "sensor already added" ); 039 040 for( final Light<? extends Sensor> light: lights ) sensor.addingLight( light ); 041 sensors.add( sensor ); 042 } 043 044 045 046 /** Removes a light from the bank. 047 * 048 * @throws IllegalArgumentException if the light is not in the bank. 049 * 050 * @see #addLight(Light) 051 */ 052 public void removeLight( final Light<? extends Sensor> light ) 053 { 054 if( !lights.remove( light )) throw new IllegalArgumentException( "no such light" ); 055 056 for( final Sensor1 sensor: sensors ) sensor.removingLight( light ); 057 } 058 059 060 061 /** Removes a sensor from the stage. 062 * 063 * @throws IllegalArgumentException if the sensor is not on stage. 064 * 065 * @see #addSensor(Sensor1) 066 */ 067 public void removeSensor( final Sensor1 sensor ) 068 { 069 if( !sensors.remove( sensor )) throw new IllegalArgumentException( "no such sensor" ); 070 071 sensor.removed(); 072 } 073 074 075 076//// P r i v a t e /////////////////////////////////////////////////////////////////////// 077 078 079 private final LinkedList<Light<? extends Sensor>> lights = new LinkedList<Light<? extends Sensor>>(); 080 081 082 083 private final LinkedList<Sensor1> sensors = new LinkedList<Sensor1>(); 084 085 086}