diff --git a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneItem.java b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneItem.java index c8376eb..d95b83b 100644 --- a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneItem.java +++ b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneItem.java @@ -68,13 +68,10 @@ public final class CayenneItem { */ public static CayenneItem parse(ByteBuffer bb) throws CayenneException { try { - final int channel = bb.get(); - final int type = bb.get() & 0xFF; - final ECayenneItem ct = ECayenneItem.parse(type); - if (ct == null) { - throw new CayenneException("Invalid cayenne type " + type); - } - final Double[] values = ct.parse(bb); + int channel = bb.get(); + int type = bb.get() & 0xFF; + ECayenneItem ct = ECayenneItem.parse(type); + Double[] values = ct.parse(bb); return new CayenneItem(channel, ct, values); } catch (BufferUnderflowException e) { throw new CayenneException(e); diff --git a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneMessage.java b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneMessage.java index b75efac..f7353ef 100644 --- a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneMessage.java +++ b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/CayenneMessage.java @@ -48,9 +48,9 @@ public final class CayenneMessage { * @throws CayenneException in case something went wrong during encoding (e.g. message too big) */ public byte[] encode(int maxSize) throws CayenneException { - final ByteBuffer bb = ByteBuffer.allocate(maxSize).order(ByteOrder.LITTLE_ENDIAN); - for (CayenneItem i : items) { - i.encode(bb); + ByteBuffer bb = ByteBuffer.allocate(maxSize).order(ByteOrder.LITTLE_ENDIAN); + for (CayenneItem item : items) { + item.encode(bb); } return Arrays.copyOfRange(bb.array(), 0, bb.position()); } diff --git a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/ECayenneItem.java b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/ECayenneItem.java index 8db2973..0408491 100644 --- a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/ECayenneItem.java +++ b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/ECayenneItem.java @@ -52,9 +52,14 @@ public enum ECayenneItem { * * @param type the type code * @return the enum, or null if not found + * @throws CayenneException */ - public static ECayenneItem parse(int type) { - return LOOKUP.get(type); + public static ECayenneItem parse(int type) throws CayenneException { + ECayenneItem item = LOOKUP.get(type); + if (item == null) { + throw new CayenneException("Invalid cayenne type " + type); + } + return item; } public int getType() { diff --git a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/formatter/FloatFormatter.java b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/formatter/FloatFormatter.java index 0644e0d..799d651 100644 --- a/cayenne/src/main/java/nl/sikken/bertrik/cayenne/formatter/FloatFormatter.java +++ b/cayenne/src/main/java/nl/sikken/bertrik/cayenne/formatter/FloatFormatter.java @@ -12,7 +12,7 @@ public final class FloatFormatter extends BaseFormatter { private final int size; private final double scale; private final boolean signed; - private final String format; + private final String formatString; /** * Constructor. @@ -27,7 +27,7 @@ public final class FloatFormatter extends BaseFormatter { this.size = size; this.scale = scale; this.signed = signed; - this.format = createFormatString(scale); + this.formatString = createFormatString(scale); } private String createFormatString(double scale) { @@ -51,7 +51,7 @@ public final class FloatFormatter extends BaseFormatter { public String[] format(Double[] values) { final String[] formatted = new String[length]; for (int i = 0; i < length; i++) { - formatted[i] = String.format(Locale.US, format, values[i]); + formatted[i] = String.format(Locale.US, formatString, values[i]); } return formatted; }