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

View File

@ -11,8 +11,6 @@ import java.util.Map;
*
*/
public class DMXChannels {
private Map<Integer,DMXChannel> channelByNumber = new HashMap<Integer, DMXChannel>();
private Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>();
/**
@ -20,7 +18,7 @@ public class DMXChannels {
* @return number of channels
*/
public final int getCount() {
return this.channelByNumber.size();
return this.channelByName.size();
}
/**
@ -35,15 +33,6 @@ public class DMXChannels {
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
* @param channel channel to add
@ -58,55 +47,21 @@ public class DMXChannels {
if (channel.getName() == null) {
return false;
}
// entry must not exist by offset
if (this.channelByNumber.containsKey(channel.getOffset())) {
return false;
}
// entry must not exist by name
if (this.channelByName.containsKey(channel.getName())) {
return false;
}
this.channelByNumber.put(channel.getOffset(), channel);
this.channelByName.put(channel.getName(), channel);
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
* @return unmodifiable collection of all channels
*/
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 {
void setDMX512Channel(int channel, int value);
void updateDevice(BuntiDevice device, Map<String, Object> options);
boolean setDMX512Channel(int channel, int value);
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() {
if (dmxMap.size() == 0) {
initDMXData();
@ -51,11 +51,9 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
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;
if (dmxDev.setValuesFromOptions(options)) {
@ -63,21 +61,22 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
dmxMap.putAll(dmxDev.getChannelData());
LOGGER.info("setValuesFromOptions on " + device);
}
else {
LOGGER.info("setValuesFromOptions on " + device + " failed");
return true;
}
LOGGER.info("setValuesFromOptions on " + device + " failed");
return false;
}
@Override
public final void setDMX512Channel(int channel, int value) {
public final boolean setDMX512Channel(int channel, int value) {
if (!DMX.checkChannelBoundaries(channel)) {
return;
return false;
}
dmxMap.put(channel, DMX.sanitizeDMXValue(value));
hasDataChanged = true;
return true;
}
@Override

View File

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