cleanup and removed unnecessary code

This commit is contained in:
Lucas Pleß 2012-03-07 22:12:18 +01:00
parent 27bbe2fd5a
commit 3bad0fd48f
5 changed files with 14 additions and 71 deletions

View File

@ -4,8 +4,7 @@ public class DMXChannel {
private int offset; private int offset;
private String name; private String name;
private int value; private int value;
private long lastChangedTimestamp = 0;
public DMXChannel(int offset, String name) { public DMXChannel(int offset, String name) {
this.name = name; this.name = name;
this.offset = offset; this.offset = offset;
@ -18,11 +17,6 @@ public class DMXChannel {
public final void setValue(int value) { public final void setValue(int value) {
this.value = value; this.value = value;
lastChangedTimestamp = System.currentTimeMillis();
}
public final long getLastChangedTimestamp() {
return lastChangedTimestamp;
} }
public final int getOffset() { public final int getOffset() {
@ -41,10 +35,6 @@ public class DMXChannel {
this.name = name; this.name = name;
} }
public final void hasbeenSendOut() {
this.lastChangedTimestamp = System.currentTimeMillis();
}
@Override @Override
public final String toString() { public final String toString() {
return "DMXChannel " + getName() + "," + getOffset() + "," + getValue(); return "DMXChannel " + getName() + "," + getOffset() + "," + getValue();

View File

@ -11,8 +11,6 @@ import java.util.Map;
* *
*/ */
public class DMXChannels { public class DMXChannels {
private Map<Integer,DMXChannel> channelByNumber = new HashMap<Integer, DMXChannel>();
private Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>(); private Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>();
/** /**
@ -20,7 +18,7 @@ public class DMXChannels {
* @return number of channels * @return number of channels
*/ */
public final int getCount() { public final int getCount() {
return this.channelByNumber.size(); return this.channelByName.size();
} }
/** /**
@ -35,15 +33,6 @@ public class DMXChannels {
return this.channelByName.get(name); return this.channelByName.get(name);
} }
/**
* Returns a channel by offset
* @param number number
* @return channel or null if not found
*/
public final DMXChannel getChannelByNumber(int number) {
return this.channelByNumber.get(number);
}
/** /**
* Adds a channel * Adds a channel
* @param channel channel to add * @param channel channel to add
@ -58,55 +47,21 @@ public class DMXChannels {
if (channel.getName() == null) { if (channel.getName() == null) {
return false; return false;
} }
// entry must not exist by offset
if (this.channelByNumber.containsKey(channel.getOffset())) {
return false;
}
// entry must not exist by name // entry must not exist by name
if (this.channelByName.containsKey(channel.getName())) { if (this.channelByName.containsKey(channel.getName())) {
return false; return false;
} }
this.channelByNumber.put(channel.getOffset(), channel);
this.channelByName.put(channel.getName(), channel); this.channelByName.put(channel.getName(), channel);
return true; return true;
} }
/**
* Removes a channel by offset
* @param offset offset
* @return removed channel or null if it does not exist
*/
public final DMXChannel removeChannel(int offset) {
DMXChannel tmpChannel = this.channelByNumber.remove(offset);
if (tmpChannel != null) {
this.channelByName.remove(tmpChannel.getName());
}
return tmpChannel;
}
/**
* Removes a channel by name
* @param name channel name
* @return removed channel or null if it does not exist
*/
public final DMXChannel removeChannel(String name) {
if (name == null) {
return null;
}
DMXChannel tmpChannel = this.channelByName.remove(name);
if (tmpChannel != null) {
this.channelByNumber.remove(tmpChannel.getOffset());
}
return tmpChannel;
}
/** /**
* Returns an (unmodifiable) collection of all channels * Returns an (unmodifiable) collection of all channels
* @return unmodifiable collection of all channels * @return unmodifiable collection of all channels
*/ */
public final Collection<DMXChannel> getAllChannels() { public final Collection<DMXChannel> getAllChannels() {
return Collections.unmodifiableCollection(this.channelByNumber.values()); return Collections.unmodifiableCollection(this.channelByName.values());
} }
} }

View File

@ -6,7 +6,7 @@ import de.ctdo.bunti.model.BuntiDevice;
public interface DMXMixer { public interface DMXMixer {
void setDMX512Channel(int channel, int value); boolean setDMX512Channel(int channel, int value);
void updateDevice(BuntiDevice device, Map<String, Object> options); boolean updateDevice(BuntiDevice device, Map<String, Object> options);
} }

View File

@ -41,7 +41,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
} }
@Scheduled(fixedDelay = 100) //TODO aendern auf 10ms @Scheduled(fixedDelay = 100)
public final void sendOutDMXBuffer() { public final void sendOutDMXBuffer() {
if (dmxMap.size() == 0) { if (dmxMap.size() == 0) {
initDMXData(); initDMXData();
@ -51,11 +51,9 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress); artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
hasDataChanged = false; hasDataChanged = false;
} }
// logger.debug(sb.toString());
} }
public final void updateDevice(BuntiDevice device, Map<String, Object> options) { public final boolean updateDevice(BuntiDevice device, Map<String, Object> options) {
BuntiDMXDevice dmxDev = (BuntiDMXDevice) device; BuntiDMXDevice dmxDev = (BuntiDMXDevice) device;
if (dmxDev.setValuesFromOptions(options)) { if (dmxDev.setValuesFromOptions(options)) {
@ -63,21 +61,22 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
dmxMap.putAll(dmxDev.getChannelData()); dmxMap.putAll(dmxDev.getChannelData());
LOGGER.info("setValuesFromOptions on " + device); LOGGER.info("setValuesFromOptions on " + device);
} return true;
else {
LOGGER.info("setValuesFromOptions on " + device + " failed");
} }
LOGGER.info("setValuesFromOptions on " + device + " failed");
return false;
} }
@Override @Override
public final void setDMX512Channel(int channel, int value) { public final boolean setDMX512Channel(int channel, int value) {
if (!DMX.checkChannelBoundaries(channel)) { if (!DMX.checkChannelBoundaries(channel)) {
return; return false;
} }
dmxMap.put(channel, DMX.sanitizeDMXValue(value)); dmxMap.put(channel, DMX.sanitizeDMXValue(value));
hasDataChanged = true; hasDataChanged = true;
return true;
} }
@Override @Override

View File

@ -3,8 +3,7 @@ package de.ctdo.bunti.model;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static junit.framework.Assert.*;
import static org.junit.Assert.assertTrue;
public class Strobe1500Test { public class Strobe1500Test {
Strobe1500 dut; Strobe1500 dut;