From 2f693b0f7ec557daf1db807a9f892cd4e6560c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Thu, 8 Mar 2012 01:22:31 +0100 Subject: [PATCH] cleaned up from violations --- .../java/de/ctdo/bunti/artnet/ByteUtils.java | 25 ++++++++++++------- .../bunti/artnet/SimpleArtNetSenderImpl.java | 2 +- .../bunti/artnet/packets/ArtDmxPacket.java | 5 ++-- .../bunti/control/BuntiControllerImpl.java | 4 +-- .../ctdo/bunti/dao/BuntiDevicesDAOImpl.java | 6 ++--- .../java/de/ctdo/bunti/dmx/DMXMixerImpl.java | 6 ++--- .../java/de/ctdo/bunti/model/Par56Spot.java | 12 ++++----- .../de/ctdo/bunti/web/RestController.java | 14 ++++------- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java index 78fe284..33cf9c1 100644 --- a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java +++ b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java @@ -20,6 +20,11 @@ package de.ctdo.bunti.artnet; public class ByteUtils { + private static final int BYTE_OVERFLOW = 256; + private static final int BYTE_MAX = 0xff; + private static final int BIT_PER_BYTE = 8; + private static final int ONE_BYTE_OFFSET = 1; + private final byte[] data; public ByteUtils(byte[] data) { @@ -27,21 +32,23 @@ public class ByteUtils { } public static final int byteToUint(byte b) { - return (b < 0 ? 256 + b : b); + return (b < 0 ? BYTE_OVERFLOW + b : b); } + public static final byte uintToByte(int i) { + return (byte)(i & BYTE_MAX); + } public final byte[] getBytes() { return data; } public final int getInt16(int offset) { - return (byteToUint(data[offset]) << 8) | byteToUint(data[offset + 1]); + return (byteToUint(data[offset]) << BIT_PER_BYTE) | byteToUint(data[offset + 1]); } - public final int getInt16LE(int offset) { - return (byteToUint(data[offset + 1]) << 8) | byteToUint(data[offset]); + return (byteToUint(data[offset + ONE_BYTE_OFFSET]) << BIT_PER_BYTE) | byteToUint(data[offset]); } public final int getInt8(int offset) { @@ -57,17 +64,17 @@ public class ByteUtils { } public final void setInt16(int val, int offset) { - data[offset] = (byte) (val >> 8 & 0xff); - data[offset + 1] = (byte) (val & 0xff); + data[offset] = (byte) (val >> BIT_PER_BYTE & BYTE_MAX); + data[offset + ONE_BYTE_OFFSET] = (byte) (val & BYTE_MAX); } public final void setInt16LE(int val, int offset) { - data[offset] = (byte) (val & 0xff); - data[offset + 1] = (byte) (val >> 8 & 0xff); + data[offset] = (byte) (val & BYTE_MAX); + data[offset + ONE_BYTE_OFFSET] = (byte) (val >> BIT_PER_BYTE & BYTE_MAX); } public final void setInt8(int val, int offset) { - data[offset] = (byte) (val & 0xff); + data[offset] = (byte) (val & BYTE_MAX); } } diff --git a/src/main/java/de/ctdo/bunti/artnet/SimpleArtNetSenderImpl.java b/src/main/java/de/ctdo/bunti/artnet/SimpleArtNetSenderImpl.java index c45eeff..cdcc386 100644 --- a/src/main/java/de/ctdo/bunti/artnet/SimpleArtNetSenderImpl.java +++ b/src/main/java/de/ctdo/bunti/artnet/SimpleArtNetSenderImpl.java @@ -42,7 +42,7 @@ public class SimpleArtNetSenderImpl implements SimpleArtNetSender { byte[] arr = new byte[size]; for (int i = 0; i < dmxData.size(); i++) { - arr[i] = (byte)(dmxData.get(i + DMX.DMX_STARTADDRESS_OFFSET) & 0xff); + arr[i] = ByteUtils.uintToByte(dmxData.get(i + DMX.DMX_STARTADDRESS_OFFSET)); } return arr; diff --git a/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java b/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java index 54d9fee..759d475 100644 --- a/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java +++ b/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java @@ -29,6 +29,7 @@ public class ArtDmxPacket extends ArtNetPacket { private static final int OFFSET_UNIVERSE = 14; private static final int OFFSET_DMX_LENGTH = 16; private static final int LOWER_NIBBLE = 0x0f; + private static final int HALF_BYTE = 4; private static final int SEQUENCE_ID_MAX = 0xff; private int numChannels; @@ -38,7 +39,7 @@ public class ArtDmxPacket extends ArtNetPacket { public ArtDmxPacket() { super(PacketType.ART_OUTPUT, DMX_PACKET_MAX_LENGTH); - getData().setInt8(2, OFFSET_PHYSICAL); + getData().setInt8(0, OFFSET_PHYSICAL); setUniverse(0, 0); } @@ -122,6 +123,6 @@ public class ArtDmxPacket extends ArtNetPacket { * @param universeID */ private void setUniverse(int subnetID, int universeID) { - getData().setInt16LE(subnetID << 4 | universeID, OFFSET_UNIVERSE); + getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE); } } \ No newline at end of file diff --git a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java index 6814c10..c3f0a2f 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java @@ -16,7 +16,7 @@ import de.ctdo.bunti.model.*; @Component public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware { - private static final Logger logger = LoggerFactory.getLogger(BuntiControllerImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class); private ApplicationEventPublisher applicationEventPublisher = null; private BuntiDevicesDAO devicesDAO; @@ -36,7 +36,7 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub if (device != null) { this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options)); - logger.debug("publishEvent in BuntiController"); + LOGGER.debug("publishEvent in BuntiController"); return true; } diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java index d063fb2..5e85c66 100644 --- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java +++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java @@ -35,7 +35,7 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO { @Override - public final Collection getAllDMXDevices() { + public Collection getAllDMXDevices() { List list = new ArrayList(); for (BuntiDevice device : devices) { if( device instanceof BuntiDMXDevice ) { @@ -46,12 +46,12 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO { } @Override - public final Collection getAllDevices() { + public Collection getAllDevices() { return Collections.unmodifiableCollection(devices); } @Override - public final BuntiDevice getDeviceById(int deviceId) { + public BuntiDevice getDeviceById(int deviceId) { for (BuntiDevice dev : devices) { if(dev.getDeviceId() == deviceId) { return dev; diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java index 95eaaae..7a32102 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java @@ -18,6 +18,7 @@ import java.util.Map; @Component public class DMXMixerImpl implements DMXMixer, ApplicationListener { private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class); + private static final int NET_SEND_INTERVAL = 100; private String artNetDeviceAddress; private final Map dmxMap = Collections.synchronizedMap(new HashMap()); @@ -35,12 +36,11 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener