*/
@Nonnull
public static byte[] getBits(final byte[] data, final int startOffset, final int numBits) throws BufferException {
- int startByteOffset = 0;
+ int startByteOffset;
int extranumBits = numBits % NetUtils.NUM_BITS_IN_A_BYTE;
final int extraOffsetBits = startOffset % NetUtils.NUM_BITS_IN_A_BYTE;
int numBytes = numBits % NetUtils.NUM_BITS_IN_A_BYTE != 0 ? 1 + numBits / NetUtils.NUM_BITS_IN_A_BYTE
public static long toNumber(final byte[] array) {
long ret = 0;
long length = array.length;
- int value = 0;
+ int value;
for (int i = 0; i < length; i++) {
value = array[i];
if (value < 0) {
int bitsRest = numBits % NetUtils.NUM_BITS_IN_A_BYTE;
int startOffset = array.length - length;
long ret = 0;
- int value = 0;
+ int value;
value = array[startOffset - 1] & getLSBMask(bitsRest);
value = array[startOffset - 1] < 0 ? array[startOffset - 1] + 256 : array[startOffset - 1];
*/
public static byte[] toByteArray(final Number input) {
Class<? extends Number> dataType = input.getClass();
- short size = 0;
+ short size;
long longValue = input.longValue();
if (dataType == Byte.class || dataType == byte.class) {
*/
public static byte[] toByteArray(final Number input, final int numBits) {
Class<? extends Number> dataType = input.getClass();
- short size = 0;
+ short size;
long longValue = input.longValue();
if (dataType == Short.class) {
}
if (bytes[0] == 0 && dataType == Long.class || bytes[0] == 0 && dataType == Integer.class) {
- int index = 0;
+ int index;
for (index = 0; index < length; ++index) {
if (bytes[index] != 0) {
bytes[0] = bytes[index];
* @return byte[]
*/
public static byte[] shiftBitsToMSB(final byte[] inputBytes, final int numBits) {
- int numBitstoShiftBy = 0;
+ int numBitstoShiftBy;
int leadZeroesMSB = 8;
- int numEndRestBits = 0;
+ int numEndRestBits;
int size = inputBytes.length;
byte[] shiftedBytes = new byte[size];
int numBytes = inputBytes.length;
int numBitstoShift = numBits % NetUtils.NUM_BITS_IN_A_BYTE;
byte[] shiftedBytes = new byte[numBytes];
- int inputLsb = 0;
- int inputMsb = 0;
+ int inputLsb;
+ int inputMsb;
if (numBitstoShift == 0) {
return inputBytes;
int extraOffsetBits = startOffset % NetUtils.NUM_BITS_IN_A_BYTE;
int extranumBits = numBits % NetUtils.NUM_BITS_IN_A_BYTE;
int restBits = numBits % NetUtils.NUM_BITS_IN_A_BYTE;
- int inputMSBbits = 0;
+ int inputMSBbits;
int inputLSBbits = 0;
if (numBits == 0) {
}
CustomTLVKey other = (CustomTLVKey) obj;
- if (oui != other.oui) {
- return false;
- }
-
- if (subtype != other.subtype) {
- return false;
- }
-
- return true;
+ return oui == other.oui && subtype == other.subtype;
}
}
CISCOQINQ("Cisco QINQ", 0x9200); // Cisco non-standard QinQ
private static final String REGEX_NUMBER_STRING = "^[0-9]+$";
- private String description;
- private int number;
+ private final String description;
+ private final int number;
EtherTypes(final String description, final int number) {
this.description = description;
return false;
}
EthernetAddress other = (EthernetAddress) obj;
- if (!Arrays.equals(macAddress, other.macAddress)) {
- return false;
- }
- return true;
+ return Arrays.equals(macAddress, other.macAddress);
}
@Override
}
public static long stringToLong(final String values) {
- long value = new BigInteger(values.replaceAll(":", ""), 16).longValue();
- return value;
+ return new BigInteger(values.replaceAll(":", ""), 16).longValue();
}
/**
/**
* Returns the TLV byte type.
*
- * @param String description of the type of TLV
+ * @param typeDesc description of the type of TLV
* @return byte type of TLV
*/
private byte getType(final String typeDesc) {
- if (typeDesc.equals(CHASSISID)) {
- return LLDPTLV.TLVType.ChassisID.getValue();
- } else if (typeDesc.equals(PORTID)) {
- return LLDPTLV.TLVType.PortID.getValue();
- } else if (typeDesc.equals(TTL)) {
- return LLDPTLV.TLVType.TTL.getValue();
- } else if (typeDesc.equals(SYSTEMNAMEID)) {
- return LLDPTLV.TLVType.SystemName.getValue();
- } else {
- return LLDPTLV.TLVType.Unknown.getValue();
+ switch (typeDesc) {
+ case CHASSISID:
+ return LLDPTLV.TLVType.ChassisID.getValue();
+ case PORTID:
+ return LLDPTLV.TLVType.PortID.getValue();
+ case TTL:
+ return LLDPTLV.TLVType.TTL.getValue();
+ case SYSTEMNAMEID:
+ return LLDPTLV.TLVType.SystemName.getValue();
+ default:
+ return LLDPTLV.TLVType.Unknown.getValue();
}
}
private LLDPTLV getFromTLVs(final Byte type) {
- LLDPTLV tlv = null;
+ LLDPTLV tlv;
tlv = mandatoryTLVs.get(type);
if (tlv == null) {
tlv = optionalTLVs.get(type);
int lldpSize = size; // LLDP size
if (LOG.isTraceEnabled()) {
- LOG.trace("LLDP: {} (offset {} bitsize {})", new Object[] { HexEncode.bytesToHexString(data),
- lldpOffset, lldpSize });
+ LOG.trace("LLDP: {} (offset {} bitsize {})", HexEncode.bytesToHexString(data), lldpOffset, lldpSize);
}
/*
* Deserialize the TLVs until we reach the end of the packet
(byte) 4), SystemName((byte) 5), SystemDesc((byte) 6), Custom(
(byte) 127);
- private byte value;
+ private final byte value;
TLVType(final byte value) {
this.value = value;
*/
public int getLength() {
return (int) BitBufferHelper.toNumber(fieldValues.get(LENGTH),
- FIELD_COORDINATES.get(LENGTH).getRight().intValue());
+ FIELD_COORDINATES.get(LENGTH).getRight());
}
/**
public int getfieldnumBits(final String fieldName) {
if (fieldName.equals(VALUE)) {
return NetUtils.NUM_BITS_IN_A_BYTE * BitBufferHelper.getShort(
- fieldValues.get(LENGTH), FIELD_COORDINATES.get(LENGTH)
- .getRight().intValue());
+ fieldValues.get(LENGTH), FIELD_COORDINATES.get(LENGTH).getRight());
}
return FIELD_COORDINATES.get(fieldName).getRight();
}
}
public static boolean fieldsConflict(final int field1, final int field2) {
- if (field1 == 0 || field2 == 0 || field1 == field2) {
- return false;
- }
- return true;
+ return field1 != 0 && field2 != 0 && field1 != field2;
}
public static InetAddress parseInetAddress(final String addressString) {
startOffset = bitOffset + this.getfieldOffset(hdrField);
numBits = this.getfieldnumBits(hdrField);
- byte[] hdrFieldBytes = null;
+ byte[] hdrFieldBytes;
try {
hdrFieldBytes = BitBufferHelper.getBits(data, startOffset,
numBits);