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 { private Map channelByName = new HashMap(); /** * Returns the number of channels * @return number of channels */ public final int getCount() { return this.channelByName.size(); } /** * Returns a channel by name * @param name channel name * @return channel or null if not found */ 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 */ 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 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 */ public final Collection getAllChannels() { return Collections.unmodifiableCollection(this.channelByName.values()); } }