*/
package org.opendaylight.protocol.pcep.spi.pojo;
+import static com.google.common.base.Preconditions.checkArgument;
+
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import java.util.Optional;
private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
private static final int MAX_OBJECT_TYPE = 15;
- private static final int MAX_OBJECT_CLASS = 4;
+ private static final int MAX_OBJECT_CLASS = 4;
+
private final VendorInformationObjectRegistry viRegistry;
public SimpleObjectRegistry(final VendorInformationObjectRegistry viRegistry) {
this.viRegistry = viRegistry;
-
}
private static int createKey(final int objectClass, final int objectType) {
Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE);
Preconditions.checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE);
- return (objectClass << MAX_OBJECT_CLASS) | objectType;
+ return objectClass << MAX_OBJECT_CLASS | objectType;
}
public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
- Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illegal object class %s",
+ checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illegal object class %s",
objectClass);
- Preconditions.checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE, "Illegal object type %s", objectType);
+ checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE, "Illegal object type %s", objectType);
return this.handlers.registerParser(createKey(objectClass, objectType), parser);
}
- public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
+ public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass,
+ final ObjectSerializer serializer) {
return this.handlers.registerSerializer(objClass, serializer);
}
@Override
- public Object parseObject(final int objectClass, final int objectType, final ObjectHeader header, final ByteBuf buffer)
- throws PCEPDeserializerException {
- Preconditions.checkArgument(objectType >= 0 && objectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ public Object parseObject(final int objectClass, final int objectType, final ObjectHeader header,
+ final ByteBuf buffer) throws PCEPDeserializerException {
+ checkArgument(objectType >= 0 && objectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
final ObjectParser parser = this.handlers.getParser(createKey(objectClass, objectType));
if (parser == null) {
return;
}
serializer.serializeObject(object, buffer);
- }
+ }
+
@Override
public Optional<? extends Object> parseVendorInformationObject(final EnterpriseNumber enterpriseNumber,
final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {