Do some code clean up

This commit is contained in:
Juergen Jung 2012-03-10 22:20:57 +01:00
parent a1feb25187
commit 2c259d8bfc
8 changed files with 30 additions and 35 deletions

View File

@ -28,7 +28,7 @@ public class ByteUtils {
private final byte[] data;
public ByteUtils(byte[] data) {
this.data = data;
this.data = data.clone();
}
public static final int byteToUint(byte b) {
@ -40,7 +40,7 @@ public class ByteUtils {
}
public final byte[] getBytes() {
return data;
return data.clone();
}
public final int getInt16(int offset) {

View File

@ -37,7 +37,7 @@ public abstract class ArtNetPacket {
}
public final void setData(byte[] data) {
this.data = new ByteUtils(data);
this.data = new ByteUtils(data.clone());
}
public final PacketType getType() {

View File

@ -19,6 +19,9 @@
package de.ctdo.bunti.artnet.packets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public enum PacketType {
ART_POLL(0x2000, null),
@ -47,6 +50,8 @@ public enum PacketType {
private final int opCode;
private final Class<? extends ArtNetPacket> packetClass;
private static final Logger LOGGER = LoggerFactory.getLogger(PacketType.class);
private PacketType(int code, Class<? extends ArtNetPacket> clazz) {
opCode = code;
@ -59,9 +64,9 @@ public enum PacketType {
try {
p = packetClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
LOGGER.error("Could not instanciate ArtNetPacket: ",e);
} catch (IllegalAccessException e) {
e.printStackTrace();
LOGGER.error("Could not instanciate ArtNetPacket: ",e);
}
}
return p;

View File

@ -22,12 +22,12 @@ public abstract class BuntiDevice {
*/
@SuppressWarnings("UnusedDeclaration")
public final String getType() {
String FQClassName = this.getClass().getName();
int firstChar = FQClassName.lastIndexOf ('.') + 1;
String fqClassName = this.getClass().getName();
int firstChar = fqClassName.lastIndexOf ('.') + 1;
if ( firstChar > 0 ) {
FQClassName = FQClassName.substring ( firstChar );
fqClassName = fqClassName.substring ( firstChar );
}
return FQClassName;
return fqClassName;
}
/**

View File

@ -8,35 +8,26 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.validation.Validator;
import java.util.Collection;
import java.util.Map;
@Controller
public class RestController {
private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class);
private Validator validator;
@Autowired
private BuntiController controller;
@Autowired
public void setValidator(Validator validator) {
this.validator = validator;
}
@Autowired
public final void setController(BuntiController controller) {
this.controller = controller;
}
@RequestMapping(value = "/devices", method = RequestMethod.GET)
public @ResponseBody Collection<BuntiDevice> getAll() {
@ResponseBody
public Collection<BuntiDevice> getAll() {
LOGGER.info("handle GET /devices request");
return controller.getAllDevices();
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
@ResponseBody
public BuntiDevice getDeviceById(@PathVariable("id") int id) {
LOGGER.info("handle GET /devices/" + id + " request");
return controller.getDeviceById(id);
}

View File

@ -17,7 +17,7 @@ public class AtmosphereResourceArgumentResolver implements WebArgumentResolver {
* @see org.springframework.web.bind.support.WebArgumentResolver#resolveArgument(org.springframework.core.MethodParameter, org.springframework.web.context.request.NativeWebRequest)
*/
@Override
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) {
if (AtmosphereResource.class.isAssignableFrom(methodParameter.getParameterType())) {
return AtmosphereUtils.getAtmosphereResource(webRequest.getNativeRequest(HttpServletRequest.class));

View File

@ -9,8 +9,9 @@ import org.springframework.util.Assert;
public final class AtmosphereUtils {
private AtmosphereUtils() { }
public static AtmosphereResource<HttpServletRequest, HttpServletResponse> getAtmosphereResource(
public static AtmosphereResource<HttpServletRequest, HttpServletResponse> getAtmosphereResource(
HttpServletRequest request) {
AtmosphereResource<HttpServletRequest, HttpServletResponse> resource =

View File

@ -1,11 +1,5 @@
package de.ctdo.bunti.websocket;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.Broadcaster;
import org.codehaus.jackson.map.ObjectMapper;
@ -16,6 +10,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@Controller
public class WebSocketController {
private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketController.class);
@ -40,10 +40,8 @@ public class WebSocketController {
bc.scheduleFixedBroadcast(new Callable<String>() {
private long sinceId = 0;
@Override
public String call() throws Exception {
public String call() throws IOException {
LOGGER.debug("call was called");
return mapper.writeValueAsString("blafaselblubb");