bunti/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java

70 lines
1.5 KiB
Java
Raw Normal View History

package de.ctdo.bunti.dmx;
import de.ctdo.bunti.dmx.model.DMXChannel;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* DMXChannel container
* @author jCoder
*
*/
public class DMXChannels {
2012-03-04 09:50:50 +00:00
private Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>();
/**
* Returns the number of channels
* @return number of channels
*/
2012-03-04 09:50:50 +00:00
public final int getCount() {
2012-03-07 21:12:18 +00:00
return this.channelByName.size();
}
/**
* Returns a channel by name
* @param name channel name
* @return channel or null if not found
*/
2012-03-04 09:50:50 +00:00
public final DMXChannel getChannelByName(String name) {
if (name == null) {
return null;
}
return this.channelByName.get(name);
}
/**
* Adds a channel
* @param channel channel to add
* @return true on success, false on error
*/
2012-03-04 09:50:50 +00:00
public final boolean addChannel(DMXChannel channel) {
// object cannot be null
if (channel == null) {
return false;
}
// description cannot be null
if (channel.getName() == null) {
return false;
}
// entry must not exist by name
2012-03-04 00:21:00 +00:00
if (this.channelByName.containsKey(channel.getName())) {
return false;
}
this.channelByName.put(channel.getName(), channel);
return true;
}
/**
* Returns an (unmodifiable) collection of all channels
* @return unmodifiable collection of all channels
*/
2012-03-04 09:50:50 +00:00
public final Collection<DMXChannel> getAllChannels() {
2012-03-07 21:12:18 +00:00
return Collections.unmodifiableCollection(this.channelByName.values());
}
}