*/
package org.opendaylight.bgp.concepts;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
byteAggregator.writeBytes(Ipv4Util.bytesForAddress(((Ipv4NextHopCase) cnextHop).getIpv4NextHop().getGlobal()));
} else if (cnextHop instanceof Ipv6NextHopCase) {
final Ipv6NextHop nextHop = ((Ipv6NextHopCase) cnextHop).getIpv6NextHop();
- if (nextHop.getGlobal() == null) {
- throw new IllegalArgumentException("Ipv6 Next Hop is missing Global address.");
- }
+ Preconditions.checkArgument(nextHop.getGlobal() != null, "Ipv6 Next Hop is missing Global address.");
byteAggregator.writeBytes(Ipv6Util.bytesForAddress(nextHop.getGlobal()));
if (nextHop.getLinkLocal() != null) {
byteAggregator.writeBytes(Ipv6Util.bytesForAddress(nextHop.getLinkLocal()));
*/
package org.opendaylight.protocol.bgp.parser;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import java.util.Map;
public static BGPError forValue(final int code, final int subcode) {
final BGPError e = VALUE_MAP.get(new BGPErrorIdentifier((short) code, (short) subcode));
- if (e != null) {
- return e;
- }
- throw new IllegalArgumentException("BGP Error code " + code + " and subcode " + subcode + " not recognized.");
+ Preconditions.checkArgument(e != null, "BGP Error code %s and subcode %s not recognized.", code, subcode);
+ return e;
}
}
final CParameters cap = optionalCapa.getCParameters();
final ByteBuf bytes = Unpooled.buffer();
this.reg.serializeCapability(cap, bytes);
- if (bytes == null) {
- throw new IllegalArgumentException("Unhandled capability class" + cap.getImplementedInterface());
- }
+ Preconditions.checkArgument(bytes != null, "Unhandled capability class %s", cap.getImplementedInterface());
if (LOG.isTraceEnabled()) {
LOG.trace("BGP capability serialized to: {}", ByteBufUtil.hexDump(bytes));
*/
package org.opendaylight.protocol.bgp.parser.mock;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import java.util.Map;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@Override
public Notification parseMessage(final ByteBuf buffer) throws BGPParsingException, BGPDocumentedException {
final Notification ret = this.messages.get(buffer);
- if (ret == null) {
- throw new IllegalArgumentException("Undefined message encountered");
- }
+ Preconditions.checkArgument(ret != null, "Undefined message encountered");
return ret;
}
package org.opendaylight.controller.config.yang.bgp.rib.impl;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.Future;
private static final int PRIVILEGED_PORTS = 1024;
- public BGPPeerAcceptorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public BGPPeerAcceptorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public BGPPeerAcceptorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerAcceptorModule oldModule, java.lang.AutoCloseable oldInstance) {
+ public BGPPeerAcceptorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerAcceptorModule oldModule, final java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
// Validate future success
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
- public void operationComplete(Future<Void> future) {
- if(!future.isSuccess()) {
- throw new IllegalStateException(String.format("Unable to start bgp server on %s", getAddress()), future.cause());
- }
+ public void operationComplete(final Future<Void> future) {
+ Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp server on %s", getAddress(), future.cause());
}
});
package org.opendaylight.controller.config.yang.bgp.rib.impl;
import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
import io.netty.util.concurrent.Future;
import java.net.InetSocketAddress;
private InetSocketAddress createAddress() {
final IpAddress ip = getHost();
+ Preconditions.checkArgument(ip.getIpv4Address() != null || ip.getIpv6Address() != null, "Failed to handle host %s", ip);
if (ip.getIpv4Address() != null) {
return new InetSocketAddress(InetAddresses.forString(ip.getIpv4Address().getValue()), getPort().getValue());
- } else if (ip.getIpv6Address() != null) {
- return new InetSocketAddress(InetAddresses.forString(ip.getIpv6Address().getValue()), getPort().getValue());
- } else {
- throw new IllegalStateException("Failed to handle host " + getHost());
}
+ return new InetSocketAddress(InetAddresses.forString(ip.getIpv6Address().getValue()), getPort().getValue());
}
@Override
// FIXME we need to remove field "value" from IpAddress since equals does not work as expected when value being present
// Remove after this bug is fixed https://bugs.opendaylight.org/show_bug.cgi?id=1276
final IpAddress host = super.getHost();
+ Preconditions.checkArgument(host.getIpv4Address() != null || host.getIpv6Address() != null, "Unexpected host %s", host);
if(host.getIpv4Address() != null) {
return new IpAddress(host.getIpv4Address());
- } else if(host.getIpv6Address() != null){
- return new IpAddress(host.getIpv6Address());
}
-
- throw new IllegalArgumentException("Unexpected host " + host);
+ return new IpAddress(host.getIpv6Address());
}
private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final String password, final AsNumber remoteAs, final BGPPeerRegistry registry) {
Preconditions.checkArgument(socketAddress instanceof InetSocketAddress, "Expecting InetSocketAddress but was %s", socketAddress.getClass());
final InetAddress inetAddress = ((InetSocketAddress) socketAddress).getAddress();
+ Preconditions.checkArgument(inetAddress instanceof Inet4Address || inetAddress instanceof Inet6Address, "Expecting %s or %s but was %s", Inet4Address.class, Inet6Address.class, inetAddress.getClass());
if(inetAddress instanceof Inet4Address) {
return new IpAddress(new Ipv4Address(inetAddress.getHostAddress()));
- } else if(inetAddress instanceof Inet6Address) {
- return new IpAddress(new Ipv6Address(inetAddress.getHostAddress()));
}
-
- throw new IllegalArgumentException("Expecting " + Inet4Address.class + " or " + Inet6Address.class + " but was " + inetAddress.getClass());
+ return new IpAddress(new Ipv6Address(inetAddress.getHostAddress()));
}
@Override
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder();
final List<Requests> reqs = Lists.newArrayList();
while (!objects.isEmpty()) {
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcrep, "Wrong instance of Message. Passed instance of %s. Need Pcrep.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessage repMsg = ((Pcrep) message).getPcrepMessage();
- if (repMsg.getReplies() == null || repMsg.getReplies().isEmpty()) {
- throw new IllegalArgumentException("Replies cannot be null or empty.");
- }
+ Preconditions.checkArgument(repMsg.getReplies() != null && !repMsg.getReplies().isEmpty(), "Replies cannot be null or empty.");
final ByteBuf buffer = Unpooled.buffer();
for (final Replies reply : repMsg.getReplies()) {
- if (reply.getRp() == null) {
- throw new IllegalArgumentException("Reply must contain RP object.");
- }
+ Preconditions.checkArgument(reply.getRp() != null, "Reply must contain RP object.");
serializeObject(reply.getRp(), buffer);
if (reply.getAugmentation(Replies1.class) != null && reply.getAugmentation(Replies1.class).getLsp() != null) {
serializeObject(reply.getAugmentation(Replies1.class).getLsp(), buffer);
@Override
public Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcrpt message cannot be empty.");
}
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcup message cannot be empty.");
}
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder();
final List<Requests> reqs = Lists.newArrayList();
while (!objects.isEmpty()) {
package org.opendaylight.protocol.pcep.ietf.stateful07;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
@Override
protected PcerrMessage validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Error message is empty.");
}
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
-
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
if (buffer == null) {
return null;
}
- if (buffer.readableBytes() != V4_LENGTH) {
- throw new IllegalArgumentException("Length " + buffer.readableBytes() + " does not match LSP Identifiers Ipv4 tlv length.");
- }
+ Preconditions.checkArgument(buffer.readableBytes() == V4_LENGTH, "Length %s does not match LSP Identifiers Ipv4 tlv length.", buffer.readableBytes());
final Ipv4Builder builder = new Ipv4Builder();
builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
final LspId lspId = new LspId((long) buffer.readUnsignedShort());
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
-
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
if (buffer == null) {
return null;
}
- if (buffer.readableBytes() != V6_LENGTH) {
- throw new IllegalArgumentException("Length " + buffer.readableBytes() + " does not match LSP Identifiers Ipv6 tlv length.");
- }
+ Preconditions.checkArgument(buffer.readableBytes() == V6_LENGTH, "Length %s does not match LSP Identifiers Ipv6 tlv length.", buffer.readableBytes());
final Ipv6Builder builder = new Ipv6Builder();
builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(buffer));
final LspId lspId = new LspId((long) buffer.readUnsignedShort());
@Override
public Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcrpt message cannot be empty.");
}
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcup message cannot be empty.");
}
package org.opendaylight.protocol.pcep.impl.message;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof CloseMessage, "Wrong instance of Message. Passed instance of %s. Need CloseMessage.", message.getClass());
final CCloseMessage close = ((CloseMessage) message).getCCloseMessage();
-
- if (close.getCClose() == null) {
- throw new IllegalArgumentException("Close Object must be present in Close Message.");
- }
- ByteBuf buffer = Unpooled.buffer();
+ Preconditions.checkArgument(close.getCClose() != null, "Close Object must be present in Close Message.");
+ final ByteBuf buffer = Unpooled.buffer();
serializeObject(close.getCClose(), buffer);
MessageUtil.formatMessage(TYPE, buffer, out);
}
@Override
protected Close validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) {
throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
}
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof PcerrMessage, "Wrong instance of Message. Passed instance of %s. Need PcerrMessage.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage err = ((PcerrMessage) message).getPcerrMessage();
-
- if (err.getErrors() == null || err.getErrors().isEmpty()) {
- throw new IllegalArgumentException("Errors should not be empty.");
- }
+ Preconditions.checkArgument(err.getErrors() != null && !err.getErrors().isEmpty(), "Errors should not be empty.");
final ByteBuf buffer = Unpooled.buffer();
serializeCases(err, buffer);
for (final Errors e : err.getErrors()) {
@Override
protected PcerrMessage validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Error message is empty.");
}
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcmonrep message cannot be empty.");
}
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcmonreq, "Wrong instance of Message. Passed instance of %s. Need Pcmonreq.", message.getClass());
final PcreqMessage msg = ((Pcmonreq) message).getPcreqMessage();
- if (msg.getMonitoringRequest() == null) {
- throw new IllegalArgumentException("MONITORING object MUST be present.");
- }
+ Preconditions.checkArgument(msg.getMonitoringRequest() != null, "MONITORING object MUST be present.");
final ByteBuf buffer = Unpooled.buffer();
serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
if (msg.getSvec() != null) {
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcmonreq message cannot be empty.");
}
serializeObject(rps.getRp(), buffer);
}
}
- if (n.getNotifications() == null || n.getNotifications().isEmpty()) {
- throw new IllegalArgumentException("Message must contain at least one notification object");
- }
+ Preconditions.checkArgument(n.getNotifications() != null && !n.getNotifications().isEmpty(), "Message must contain at least one notification object");
for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications not : n.getNotifications()) {
serializeObject(not.getCNotification(), buffer);
}
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Notification message cannot be empty.");
}
package org.opendaylight.protocol.pcep.impl.message;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof OpenMessage, "Wrong instance of Message. Passed instance of %s. Need OpenMessage.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage();
-
- if (open.getOpen() == null) {
- throw new IllegalArgumentException("Open Object must be present in Open Message.");
- }
- ByteBuf buffer = Unpooled.buffer();
+ Preconditions.checkArgument(open.getOpen() != null, "Open Object must be present in Open Message.");
+ final ByteBuf buffer = Unpooled.buffer();
serializeObject(open.getOpen(), buffer);
MessageUtil.formatMessage(TYPE, buffer, out);
}
@Override
protected org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open validate(
final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty() || !(objects.get(0) instanceof Open)) {
throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcrep, "Wrong instance of Message. Passed instance of %s. Need Pcrep.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessage repMsg = ((Pcrep) message).getPcrepMessage();
- if (repMsg.getReplies() == null || repMsg.getReplies().isEmpty()) {
- throw new IllegalArgumentException("Replies cannot be null or empty.");
- }
+ Preconditions.checkArgument(repMsg.getReplies() != null && !repMsg.getReplies().isEmpty(), "Replies cannot be null or empty.");
final ByteBuf buffer = Unpooled.buffer();
for (final Replies reply : repMsg.getReplies()) {
- if (reply.getRp() == null) {
- throw new IllegalArgumentException("Reply must contain RP object.");
- }
+ Preconditions.checkArgument(reply.getRp() != null, "Reply must contain RP object.");
serializeReply(reply, buffer);
}
MessageUtil.formatMessage(TYPE, buffer, out);
@Override
protected Pcrep validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcrep message cannot be empty.");
}
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcreq, "Wrong instance of Message. Passed instance of %s. Need Pcreq.", message.getClass());
final PcreqMessage msg = ((Pcreq) message).getPcreqMessage();
- if (msg.getRequests() == null || msg.getRequests().isEmpty()) {
- throw new IllegalArgumentException("Requests cannot be null or empty.");
- }
+ Preconditions.checkArgument(msg.getRequests() != null && !msg.getRequests().isEmpty(), "Requests cannot be null or empty.");
final ByteBuf buffer = Unpooled.buffer();
if (msg.getMonitoringRequest() != null) {
serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
+ Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcrep message cannot be empty.");
}
}
private Svec getValidSvec(final SvecBuilder builder, final List<Object> objects) {
- if (objects == null || objects.isEmpty()) {
- throw new IllegalArgumentException("List cannot be null or empty.");
- }
+ Preconditions.checkArgument(objects != null && !objects.isEmpty(), "Passed list can't be null or empty.");
if (objects.get(0) instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) {
builder.setSvec((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) objects.get(0));
*/
package org.opendaylight.protocol.pcep.impl.tls;
+import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
switch (pathType) {
case CLASSPATH:
in = SslKeyStore.class.getResourceAsStream(filename);
- if (in == null) {
- throw new IllegalStateException("KeyStore file not found: "
- + filename);
- }
+ Preconditions.checkArgument(in != null, "KeyStore file not found: %s", filename);
break;
case PATH:
LOG.debug("Current dir using System: {}", System.getProperty("user.dir"));
final File keystorefile = new File(filename);
try {
in = new FileInputStream(keystorefile);
- } catch (FileNotFoundException e) {
- throw new IllegalStateException("KeyStore file not found: "
- + filename,e);
+ } catch (final FileNotFoundException e) {
+ throw new IllegalStateException("KeyStore file not found: " + filename,e);
}
break;
default:
import com.google.common.base.Charsets;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.net.InetSocketAddress;
private KeyMapping contructKeys() {
final KeyMapping ret = new KeyMapping();
if (getClient() != null) {
- for (Client c : getClient()) {
+ for (final Client c : getClient()) {
if (c.getAddress() == null) {
LOG.warn("Client {} does not have an address skipping it", c);
continue;
private String getAddressString(final IpAddress address) {
+ Preconditions.checkArgument(address.getIpv4Address() != null || address.getIpv6Address() != null, "Address %s is invalid", address);
if (address.getIpv4Address() != null) {
return address.getIpv4Address().getValue();
}
- if (address.getIpv6Address() != null) {
- return address.getIpv6Address().getValue();
- }
-
- throw new IllegalArgumentException(String.format("Address %s is invalid", address));
+ return address.getIpv6Address().getValue();
}
* should something like isMd5ServerSupported()
*/
- PCEPDispatcherImplModuleMXBean dispatcherProxy = dependencyResolver.newMXBeanProxy(getDispatcher(),
+ final PCEPDispatcherImplModuleMXBean dispatcherProxy = this.dependencyResolver.newMXBeanProxy(getDispatcher(),
PCEPDispatcherImplModuleMXBean.class);
- boolean md5ServerSupported = dispatcherProxy.getMd5ServerChannelFactory() != null;
+ final boolean md5ServerSupported = dispatcherProxy.getMd5ServerChannelFactory() != null;
JmxAttributeValidationException.checkCondition(md5ServerSupported,
"password is not compatible with selected dispatcher", clientJmxAttribute);
private InetAddress listenAddress() {
final IpAddress a = getListenAddress();
+ Preconditions.checkArgument(a.getIpv4Address() != null || a.getIpv6Address() != null, "Address %s not supported", a);
if (a.getIpv4Address() != null) {
return InetAddresses.forString(a.getIpv4Address().getValue());
- } else if (a.getIpv6Address() != null) {
- return InetAddresses.forString(a.getIpv6Address().getValue());
- } else {
- throw new IllegalArgumentException("Address " + a + " not supported");
}
+ return InetAddresses.forString(a.getIpv6Address().getValue());
}
@Override
* @return a new byte array that is a sub-array of the original
*/
public static byte[] subByte(final byte[] bytes, final int startIndex, final int length) {
- if (!checkLength(bytes, length) || !checkStartIndex(bytes, startIndex, length)) {
- throw new IllegalArgumentException("Cannot create subByte, invalid arguments: Length: " + length + " startIndex: " + startIndex);
- }
+ Preconditions.checkArgument(checkLength(bytes, length) && checkStartIndex(bytes, startIndex, length), "Cannot create subByte, invalid arguments: Length: %s startIndex: %s", length, startIndex);
final byte[] res = new byte[length];
System.arraycopy(bytes, startIndex, res, 0, length);
return res;
* @return int
*/
public static int bytesToInt(final byte[] bytes) {
- if (bytes.length > Integer.SIZE / Byte.SIZE) {
- throw new IllegalArgumentException("Cannot convert bytes to integer. Byte array too big.");
- }
+ Preconditions.checkArgument(bytes.length <= Integer.SIZE / Byte.SIZE, "Cannot convert bytes to integer. Byte array too big.");
byte[] res = new byte[Integer.SIZE / Byte.SIZE];
if (bytes.length != Integer.SIZE / Byte.SIZE) {
System.arraycopy(bytes, 0, res, Integer.SIZE / Byte.SIZE - bytes.length, bytes.length);
* @return long
*/
public static long bytesToLong(final byte[] bytes) {
- if (bytes.length > Long.SIZE / Byte.SIZE) {
- throw new IllegalArgumentException("Cannot convert bytes to long.Byte array too big.");
- }
+ Preconditions.checkArgument(bytes.length <= Long.SIZE / Byte.SIZE, "Cannot convert bytes to long.Byte array too big.");
byte[] res = new byte[Long.SIZE / Byte.SIZE];
if (bytes.length != Long.SIZE / Byte.SIZE) {
System.arraycopy(bytes, 0, res, Long.SIZE / Byte.SIZE - bytes.length, bytes.length);
* @return bytes array without first 'count' bytes
*/
public static byte[] cutBytes(final byte[] bytes, final int count) {
- if (bytes.length == 0 || count > bytes.length || count <= 0) {
- throw new IllegalArgumentException("Cannot cut bytes, invalid arguments: Count: " + count + " bytes.length: " + bytes.length);
- }
+ Preconditions.checkArgument(bytes.length != 0 && count <= bytes.length && count > 0, "Cannot cut bytes, invalid arguments: Count: %s bytes.length: %s", count, bytes.length);
return Arrays.copyOfRange(bytes, count, bytes.length);
}
* @return copied value aligned to right
*/
public static byte copyBitsRange(final byte src, final int fromBit, final int length) {
- if (fromBit < 0 || fromBit > Byte.SIZE - 1 || length < 1 || length > Byte.SIZE) {
- throw new IllegalArgumentException("fromBit or toBit is out of range.");
- }
- if (fromBit + length > Byte.SIZE) {
- throw new IllegalArgumentException("Out of range.");
- }
+ Preconditions.checkArgument(fromBit >= 0 && fromBit <= Byte.SIZE - 1 && length >= 1 && length <= Byte.SIZE, "fromBit or toBit is out of range.");
+ Preconditions.checkArgument(fromBit + length <= Byte.SIZE, "Out of range.");
byte retByte = 0;
int retI = 0;