Fix some PMD warnings.

pull/3/head
Bertrik Sikken 2019-05-03 22:08:55 +02:00
rodzic 1ce025f9e0
commit 25daf045e3
4 zmienionych plików z 17 dodań i 15 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -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());
}

Wyświetl plik

@ -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() {

Wyświetl plik

@ -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;
}