</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
* A set of utility methods to efficiently instantiate various ietf-inet-types DTOs.
*/
@Beta
+@SuppressWarnings("checkstyle:classTypeParameterName")
public abstract class AbstractIetfInetUtil<A4, A4NZ extends A4, P4, A6, A6NZ extends A6, P6, A, ANZ, P> {
private static final int INET4_LENGTH = 4;
private static final int INET6_LENGTH = 16;
+
private final StringValueObjectFactory<A4> address4Factory;
private final StringValueObjectFactory<A4NZ> address4NoZoneFactory;
private final StringValueObjectFactory<P4> prefix4Factory;
}
protected abstract @NonNull A ipv4Address(@NonNull A4 addr);
+
protected abstract @NonNull ANZ ipv4AddressNoZone(@NonNull A4NZ addr);
+
protected abstract @NonNull A ipv6Address(@NonNull A6 addr);
+
protected abstract @NonNull ANZ ipv6AddressNoZone(@NonNull A6NZ addr);
protected abstract @Nullable A4 maybeIpv4Address(@NonNull A addr);
+
protected abstract @Nullable A4NZ maybeIpv4AddressNoZone(@NonNull ANZ addr);
+
protected abstract @Nullable A6 maybeIpv6Address(@NonNull A addr);
+
protected abstract @Nullable A6NZ maybeIpv6AddressNoZone(@NonNull ANZ addr);
protected abstract @NonNull P ipv4Prefix(@NonNull P4 addr);
+
protected abstract @NonNull P ipv6Prefix(@NonNull P6 addr);
+
protected abstract @NonNull String ipv4AddressString(@NonNull A4 addr);
+
protected abstract @NonNull String ipv6AddressString(@NonNull A6 addr);
+
protected abstract @NonNull String ipv4PrefixString(@NonNull P4 prefix);
+
protected abstract @NonNull String ipv6PrefixString(@NonNull P6 prefix);
/**
return prefix4Factory.newInstance(prefixStringV4(address, mask));
}
- public final @NonNull P4 ipv4PrefixForShort(final byte @NonNull[] address, final int mask) {
- if (mask == 0) {
- // Easy case, reuse the template
- return prefix4Factory.getTemplate();
- }
-
- return v4PrefixForShort(address, 0, mask / Byte.SIZE + (mask % Byte.SIZE == 0 ? 0 : 1), mask);
- }
-
- public final @NonNull P4 ipv4PrefixForShort(final byte @NonNull[] array, final int startOffset, final int mask) {
- if (mask == 0) {
- // Easy case, reuse the template
- return prefix4Factory.getTemplate();
- }
-
- return v4PrefixForShort(array, startOffset, mask / Byte.SIZE + (mask % Byte.SIZE == 0 ? 0 : 1), mask);
- }
-
/**
- * Create a /32 Ipv4Prefix for an {@link Inet4Address}
+ * Create a /32 Ipv4Prefix for an {@link Inet4Address}.
*
* @param addr An {@link Inet4Address}
* @return An Ipv4Prefix object
return newIpv4Prefix(ipv4AddressString(addr), mask);
}
+ public final @NonNull P4 ipv4PrefixForShort(final byte @NonNull[] address, final int mask) {
+ if (mask == 0) {
+ // Easy case, reuse the template
+ return prefix4Factory.getTemplate();
+ }
+
+ return v4PrefixForShort(address, 0, mask / Byte.SIZE + (mask % Byte.SIZE == 0 ? 0 : 1), mask);
+ }
+
+ public final @NonNull P4 ipv4PrefixForShort(final byte @NonNull[] array, final int startOffset, final int mask) {
+ if (mask == 0) {
+ // Easy case, reuse the template
+ return prefix4Factory.getTemplate();
+ }
+
+ return v4PrefixForShort(array, startOffset, mask / Byte.SIZE + (mask % Byte.SIZE == 0 ? 0 : 1), mask);
+ }
+
private static String stripZone(final String str) {
final int percent = str.indexOf('%');
return percent == -1 ? str : str.substring(0, percent);
return prefix6Factory.newInstance(addressStringV6(address) + '/' + mask);
}
- public final @NonNull P6 ipv6PrefixForShort(final byte @NonNull[] address, final int mask) {
- return ipv6PrefixForShort(address, 0, mask);
- }
-
- public final @NonNull P6 ipv6PrefixForShort(final byte @NonNull[] array, final int startOffset, final int mask) {
- if (mask == 0) {
- // Easy case, reuse the template
- return prefix6Factory.getTemplate();
- }
-
- checkArgument(mask > 0 && mask <= 128, "Invalid mask %s", mask);
- final int size = mask / Byte.SIZE + (mask % Byte.SIZE == 0 ? 0 : 1);
-
- // Until we can instantiate an IPv6 address for a partial array, use a temporary buffer
- byte[] tmp = new byte[INET6_LENGTH];
- System.arraycopy(array, startOffset, tmp, 0, size);
- return ipv6PrefixFor(tmp, mask);
- }
-
/**
* Create a /128 Ipv6Prefix by interpreting input bytes as an IPv4 address.
*
return newIpv6Prefix(ipv6AddressString(addr), mask);
}
+ public final @NonNull P6 ipv6PrefixForShort(final byte @NonNull[] address, final int mask) {
+ return ipv6PrefixForShort(address, 0, mask);
+ }
+
+ public final @NonNull P6 ipv6PrefixForShort(final byte @NonNull[] array, final int startOffset, final int mask) {
+ if (mask == 0) {
+ // Easy case, reuse the template
+ return prefix6Factory.getTemplate();
+ }
+
+ checkArgument(mask > 0 && mask <= 128, "Invalid mask %s", mask);
+ final int size = mask / Byte.SIZE + (mask % Byte.SIZE == 0 ? 0 : 1);
+
+ // Until we can instantiate an IPv6 address for a partial array, use a temporary buffer
+ byte[] tmp = new byte[INET6_LENGTH];
+ System.arraycopy(array, startOffset, tmp, 0, size);
+ return ipv6PrefixFor(tmp, mask);
+ }
+
private P6 newIpv6Prefix(final String addr, final int mask) {
checkArgument(mask >= 0 && mask <= 128, "Invalid mask %s", mask);
return prefix6Factory.newInstance(addr + '/' + mask);
private static final int MAC_BYTE_LENGTH = 6;
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
private static final byte[] HEX_VALUES;
+
static {
final byte[] b = new byte['f' + 1];
Arrays.fill(b, (byte)-1);
protected abstract String getPhysValue(P physAddress);
- static byte hexValue(final char c) {
- byte v;
+ static byte hexValue(final char ch) {
+ byte value;
try {
// Performance optimization: access the array and rely on the VM for catching
// illegal access (which boils down to illegal character, which should never happen.
- v = HEX_VALUES[c];
+ value = HEX_VALUES[ch];
} catch (IndexOutOfBoundsException e) {
- v = -1;
+ value = -1;
}
- if (v < 0) {
- throw new IllegalArgumentException("Invalid character '" + c + "' encountered");
+ if (value < 0) {
+ throw new IllegalArgumentException("Invalid character '" + ch + "' encountered");
}
- return v;
+ return value;
}
/**
return sb.toString();
}
- private static final void appendHexByte(final StringBuilder sb, final byte b) {
- final int v = Byte.toUnsignedInt(b);
- sb.append(HEX_CHARS[v >>> 4]).append(HEX_CHARS[v & 15]);
+ private static void appendHexByte(final StringBuilder sb, final byte byteVal) {
+ final int intVal = Byte.toUnsignedInt(byteVal);
+ sb.append(HEX_CHARS[intVal >>> 4]).append(HEX_CHARS[intVal & 15]);
}
}
*/
final class Ipv4Utils {
private Ipv4Utils() {
- throw new UnsupportedOperationException();
+
}
static void fillIpv4Bytes(final byte @NonNull[] bytes, final int byteStart, final String str, final int strStart,
private static final int INT16SZ = Short.BYTES;
private Ipv6Utils() {
- throw new UnsupportedOperationException();
+
}
/**
- * Convert Ipv6Address object to a valid Canonical v6 address in byte format
+ * Convert Ipv6Address object to a valid Canonical v6 address in byte format.
*
* @param bytes Byte array for output
* @param str String representation
* @param strLimit String offset which should not be processed
* @throws NullPointerException if ipv6address is null
*/
+ @SuppressWarnings("checkstyle:localVariableName")
static void fillIpv6Bytes(final byte @NonNull[] bytes, final String str, final int strLimit) {
- // Leading :: requires some special handling.
- int i = 0;
- if (str.charAt(i) == ':') {
- // Note ++i side-effect in check
- checkArgument(str.charAt(++i) == ':', "Invalid v6 address '%s'", str);
- }
+ // Leading :: requires some special handling.
+ int i = 0;
+ if (str.charAt(i) == ':') {
+ // Note ++i side-effect in check
+ checkArgument(str.charAt(++i) == ':', "Invalid v6 address '%s'", str);
+ }
- boolean haveVal = false;
- int val = 0;
- int colonp = -1;
- int j = 0;
- int curtok = i;
- while (i < strLimit) {
- final char ch = str.charAt(i++);
+ boolean haveVal = false;
+ int val = 0;
+ int colonp = -1;
+ int j = 0;
+ int curtok = i;
+ while (i < strLimit) {
+ final char ch = str.charAt(i++);
- // v6 separator
- if (ch == ':') {
- curtok = i;
- if (haveVal) {
- // removed overrun check - the regexp checks for valid data
- bytes[j++] = (byte) (val >>> 8 & 0xff);
- bytes[j++] = (byte) (val & 0xff);
- haveVal = false;
- val = 0;
- } else {
- // no need to check separator position validity - regexp does that
- colonp = j;
- }
+ // v6 separator
+ if (ch == ':') {
+ curtok = i;
+ if (haveVal) {
+ // removed overrun check - the regexp checks for valid data
+ bytes[j++] = (byte) (val >>> 8 & 0xff);
+ bytes[j++] = (byte) (val & 0xff);
+ haveVal = false;
+ val = 0;
+ } else {
+ // no need to check separator position validity - regexp does that
+ colonp = j;
+ }
- continue;
- }
+ continue;
+ }
- // frankenstein - v4 attached to v6, mixed notation
- if (ch == '.' && j + INADDR4SZ <= INADDR6SZ) {
- /*
- * This has passed the regexp so it is fairly safe to parse it
- * straight away. Use the Ipv4Utils for that.
- */
- Ipv4Utils.fillIpv4Bytes(bytes, j, str, curtok, strLimit);
- j += INADDR4SZ;
- haveVal = false;
- break;
- }
+ // frankenstein - v4 attached to v6, mixed notation
+ if (ch == '.' && j + INADDR4SZ <= INADDR6SZ) {
+ /*
+ * This has passed the regexp so it is fairly safe to parse it
+ * straight away. Use the Ipv4Utils for that.
+ */
+ Ipv4Utils.fillIpv4Bytes(bytes, j, str, curtok, strLimit);
+ j += INADDR4SZ;
+ haveVal = false;
+ break;
+ }
- /*
- * Business as usual - ipv6 address digit.
- * We can remove all checks from the original BSD code because
- * the regexp has already verified that we are not being fed
- * anything bigger than 0xffff between the separators.
- */
- final int chval = AbstractIetfYangUtil.hexValue(ch);
- val = val << 4 | chval;
- haveVal = true;
- }
+ /*
+ * Business as usual - ipv6 address digit.
+ * We can remove all checks from the original BSD code because
+ * the regexp has already verified that we are not being fed
+ * anything bigger than 0xffff between the separators.
+ */
+ final int chval = AbstractIetfYangUtil.hexValue(ch);
+ val = val << 4 | chval;
+ haveVal = true;
+ }
- if (haveVal) {
- verify(j + INT16SZ <= INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
- bytes[j++] = (byte) (val >> 8 & 0xff);
- bytes[j++] = (byte) (val & 0xff);
- }
+ if (haveVal) {
+ verify(j + INT16SZ <= INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
+ bytes[j++] = (byte) (val >> 8 & 0xff);
+ bytes[j++] = (byte) (val & 0xff);
+ }
- if (colonp != -1) {
- verify(j != INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
- expandZeros(bytes, colonp, j);
- } else {
- verify(j == INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
- }
- }
+ if (colonp != -1) {
+ verify(j != INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
+ expandZeros(bytes, colonp, j);
+ } else {
+ verify(j == INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
+ }
+ }
- private static void expandZeros(final byte[] bytes, final int where, final int filledBytes) {
- final int tailLength = filledBytes - where;
- final int tailOffset = INADDR6SZ - tailLength;
- System.arraycopy(bytes, where, bytes, tailOffset, tailLength);
- Arrays.fill(bytes, where, tailOffset, (byte)0);
+ private static void expandZeros(final byte[] bytes, final int where, final int filledBytes) {
+ final int tailLength = filledBytes - where;
+ final int tailOffset = INADDR6SZ - tailLength;
+ System.arraycopy(bytes, where, bytes, tailOffset, tailLength);
+ Arrays.fill(bytes, where, tailOffset, (byte)0);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.mdsal.model.ietf.util;
import static java.util.Objects.requireNonNull;
+@SuppressWarnings("checkstyle:memberName")
public class IpClass {
private final String _value;
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.mdsal.model.ietf.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Constructor;
-import org.junit.Test;
-
-public class Ipv4UtilsTest {
-
- @Test(expected = UnsupportedOperationException.class)
- public void privateConstructTest() throws Throwable {
- final Constructor<Ipv4Utils> constructor = Ipv4Utils.class.getDeclaredConstructor();
- assertFalse(constructor.isAccessible());
- constructor.setAccessible(true);
- try {
- constructor.newInstance();
- fail("Exception should be thrown");
- } catch (Exception e) {
- throw e.getCause();
- }
- }
-}
\ No newline at end of file
import static com.google.common.net.InetAddresses.forString;
import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
import static org.opendaylight.mdsal.model.ietf.util.Ipv6Utils.fillIpv6Bytes;
-import java.lang.reflect.Constructor;
import org.junit.Test;
public class Ipv6UtilsTest {
assertArrayEquals(test1, bytesForString("0:0:0:0:0:0:13.1.68.3"));
assertArrayEquals(test1, bytesForString("::13.1.68.3"));
- final byte[] test2 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)255, (byte)255,
- (byte)129, (byte)144, 52, 38 };
+ final byte[] test2 = new byte[] {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)255, (byte)255, (byte)129, (byte)144, 52, 38
+ };
assertArrayEquals(test2, bytesForString("0:0:0:0:0:FFFF:129.144.52.38"));
assertArrayEquals(test2, bytesForString("::FFFF:129.144.52.38"));
}
private static void assertEqualResult(final String str) {
assertArrayEquals(forString(str).getAddress(), bytesForString(str));
}
-
- @Test(expected = UnsupportedOperationException.class)
- public void privateConstructTest() throws Throwable {
- final Constructor<Ipv6Utils> constructor = Ipv6Utils.class.getDeclaredConstructor();
- assertFalse(constructor.isAccessible());
- constructor.setAccessible(true);
- try {
- constructor.newInstance();
- fail("Exception should be thrown");
- } catch (Exception e) {
- throw e.getCause();
- }
- }
-}
\ No newline at end of file
+}
import static java.util.Objects.requireNonNull;
+@SuppressWarnings("checkstyle:memberName")
public final class MacClass {
private final String _value;
import static java.util.Objects.requireNonNull;
+@SuppressWarnings("checkstyle:memberName")
public final class PhysClass {
private final String _value;