Added some API documentation. 56/5056/1
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 31 Jan 2014 10:35:15 +0000 (11:35 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 31 Jan 2014 10:35:15 +0000 (11:35 +0100)
Change-Id: I4fe17f920c8483694842ac96759ef45aa3765c1f
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv4Util.java
concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv6Util.java
util/src/main/java/org/opendaylight/protocol/util/ByteArray.java
util/src/main/java/org/opendaylight/protocol/util/RemoveOnlySet.java
util/src/main/java/org/opendaylight/protocol/util/Values.java

index e15536ba0006791e8ff81c5b82f4a16649fc34cb..e643ea8e48bcf70122a3802673709a2d574d899d 100644 (file)
@@ -35,6 +35,13 @@ public final class Ipv4Util {
 
        public static final int IP4_LENGTH = 4;
 
+       /**
+        * Converts byte array to Inet4Address.
+        * 
+        * @param bytes to be converted
+        * @return InetAddress instance
+        * @throws IllegalArgumentException if {@link UnknownHostException} is thrown.
+        */
        private static InetAddress getAddress(final byte[] bytes) {
                try {
                        return Inet4Address.getByAddress(bytes);
@@ -43,16 +50,34 @@ public final class Ipv4Util {
                }
        }
 
+       /**
+        * Converts byte array to Ipv4Address.
+        * 
+        * @param bytes to be converted to Ipv4Address
+        * @return Ipv4Address
+        */
        public static Ipv4Address addressForBytes(final byte[] bytes) {
                return new Ipv4Address(InetAddresses.toAddrString(getAddress(bytes)));
        }
 
+       /**
+        * Converts Ipv4Address to byte array.
+        * 
+        * @param address Ipv4Address to be converted
+        * @return byte array
+        */
        public static byte[] bytesForAddress(final Ipv4Address address) {
                final InetAddress a = InetAddresses.forString(address.getValue());
                Preconditions.checkArgument(a instanceof Inet4Address);
                return a.getAddress();
        }
 
+       /**
+        * Converts Ipv4Prefix to byte array.
+        * 
+        * @param prefix Ipv4Prefix to be converted
+        * @return byte array
+        */
        public static byte[] bytesForPrefix(final Ipv4Prefix prefix) {
                final String p = prefix.getValue();
                final int sep = p.indexOf('/');
@@ -62,6 +87,13 @@ public final class Ipv4Util {
                return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length())) });
        }
 
+       /**
+        * Creates an Ipv4Prefix object from given byte array.
+        * 
+        * @param bytes IPv4 address
+        * @param length prefix length
+        * @return Ipv4Prefix object
+        */
        public static Ipv4Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * Byte.SIZE);
                final byte[] tmp = Arrays.copyOfRange(bytes, 0, IP4_LENGTH);
@@ -69,11 +101,16 @@ public final class Ipv4Util {
                return new Ipv4Prefix(InetAddresses.toAddrString(a) + '/' + length);
        }
 
+       /**
+        * Creates a list of Ipv4 Prefixes from given byte array.
+        * 
+        * @param bytes to be converted to List of Ipv4Prefixes.
+        * @return List<Ipv4Prefix>
+        */
        public static List<Ipv4Prefix> prefixListForBytes(final byte[] bytes) {
                if (bytes.length == 0) {
                        return Collections.emptyList();
                }
-
                final List<Ipv4Prefix> list = Lists.newArrayList();
                int byteOffset = 0;
                while (byteOffset < bytes.length) {
@@ -86,6 +123,12 @@ public final class Ipv4Util {
                return list;
        }
 
+       /**
+        * Obtains prefix length from given prefix.
+        * 
+        * @param prefix
+        * @return prefix length
+        */
        public static int getPrefixLength(final IpPrefix prefix) {
                String p = "";
                if (prefix.getIpv4Prefix() != null) {
index 31113d0540b3a4e17edc929fc2f9faabe97dd6fc..ab7eea5a0155cdf0990e9b65f316e8fcccd7a21f 100644 (file)
@@ -33,6 +33,13 @@ public final class Ipv6Util {
 
        public static final int IPV6_LENGTH = 16;
 
+       /**
+        * Converts byte array to Inet6Address.
+        * 
+        * @param bytes to be converted
+        * @return InetAddress instance
+        * @throws IllegalArgumentException if {@link UnknownHostException} is thrown.
+        */
        private static InetAddress getAddress(final byte[] bytes) {
                try {
                        return Inet6Address.getByAddress(bytes);
@@ -41,16 +48,34 @@ public final class Ipv6Util {
                }
        }
 
+       /**
+        * Converts byte array to Ipv6Address.
+        * 
+        * @param bytes to be converted to Ipv6Address
+        * @return Ipv6Address
+        */
        public static Ipv6Address addressForBytes(final byte[] bytes) {
                return new Ipv6Address(InetAddresses.toAddrString(getAddress(bytes)));
        }
 
+       /**
+        * Converts Ipv6Address to byte array.
+        * 
+        * @param address Ipv6Address to be converted
+        * @return byte array
+        */
        public static byte[] bytesForAddress(final Ipv6Address address) {
                final InetAddress a = InetAddresses.forString(address.getValue());
                Preconditions.checkArgument(a instanceof Inet6Address);
                return a.getAddress();
        }
 
+       /**
+        * Converts Ipv6Prefix to byte array.
+        * 
+        * @param prefix Ipv6Prefix to be converted
+        * @return byte array
+        */
        public static byte[] bytesForPrefix(final Ipv6Prefix prefix) {
                final String p = prefix.getValue();
                final int sep = p.indexOf('/');
@@ -60,6 +85,13 @@ public final class Ipv6Util {
                return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length())) });
        }
 
+       /**
+        * Creates an Ipv6Prefix object from given byte array.
+        * 
+        * @param bytes IPv6 address
+        * @param length prefix length
+        * @return Ipv6Prefix object
+        */
        public static Ipv6Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * Byte.SIZE);
                final byte[] tmp = Arrays.copyOfRange(bytes, 0, IPV6_LENGTH);
@@ -67,6 +99,12 @@ public final class Ipv6Util {
                return new Ipv6Prefix(InetAddresses.toAddrString(a) + '/' + length);
        }
 
+       /**
+        * Creates a list of Ipv6 Prefixes from given byte array.
+        * 
+        * @param bytes to be converted to List of Ipv6Prefixes.
+        * @return List<Ipv6Prefix>
+        */
        public static List<Ipv6Prefix> prefixListForBytes(final byte[] bytes) {
                if (bytes.length == 0) {
                        return Collections.emptyList();
index 139ca517d7c988b675a9b6749820c45f61bc70ce..b208c0bc9652d787d2edda9d60358fb6b209394b 100644 (file)
@@ -22,9 +22,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedInteger;
 
 /**
- * 
  * Util class for methods working with byte array.
- * 
  */
 public final class ByteArray {
        private ByteArray() {
@@ -472,6 +470,12 @@ public final class ByteArray {
                return bytes;
        }
 
+       /**
+        * Trims zeros from the beginning of the byte array.
+        * 
+        * @param bytes
+        * @return byte array without leading zeros.
+        */
        public static byte[] trim(final byte[] bytes) {
                int i = bytes.length - 1;
                while (i >= 0 && bytes[i] == 0) {
@@ -480,15 +484,33 @@ public final class ByteArray {
                return Arrays.copyOf(bytes, i + 1);
        }
 
+       /**
+        * Converts given byte array to unsigned Integer.
+        * 
+        * @param bytes byte array to be converted to unsigned Integer.
+        * @return uint
+        */
        public static UnsignedInteger bytesToUint32(final byte[] bytes) {
                Preconditions.checkArgument(bytes.length == Integer.SIZE / Byte.SIZE);
                return UnsignedInteger.fromIntBits(bytesToInt(bytes));
        }
 
+       /**
+        * Converts uint to byte array.
+        * 
+        * @param uint to be converted to byte array
+        * @return byte array
+        */
        public static byte[] uint32ToBytes(final UnsignedInteger uint) {
                return intToBytes(uint.intValue());
        }
 
+       /**
+        * Converts uint as long to byte array.
+        * 
+        * @param uint to be converted to byte array
+        * @return byte array
+        */
        public static byte[] uint32ToBytes(final long uint) {
                return uint32ToBytes(UnsignedInteger.valueOf(uint));
        }
index cc41f64c1f3bff8a17ad7a7c56b1e2b6e8e2e8ba..f6c809090052ae947f4c09fa59d45bca22984875 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Set;
 
+@Deprecated
 public class RemoveOnlySet<E> implements Set<E> {
        private final Set<E> set;
 
@@ -34,56 +35,56 @@ public class RemoveOnlySet<E> implements Set<E> {
 
        @Override
        public void clear() {
-               set.clear();
+               this.set.clear();
        }
 
        @Override
        public boolean contains(final Object o) {
-               return set.contains(o);
+               return this.set.contains(o);
        }
 
        @Override
        public boolean containsAll(final Collection<?> c) {
-               return set.containsAll(c);
+               return this.set.containsAll(c);
        }
 
        @Override
        public boolean isEmpty() {
-               return set.isEmpty();
+               return this.set.isEmpty();
        }
 
        @Override
        public Iterator<E> iterator() {
-               return set.iterator();
+               return this.set.iterator();
        }
 
        @Override
        public boolean remove(final Object o) {
-               return set.remove(o);
+               return this.set.remove(o);
        }
 
        @Override
        public boolean removeAll(final Collection<?> c) {
-               return set.removeAll(c);
+               return this.set.removeAll(c);
        }
 
        @Override
        public boolean retainAll(final Collection<?> c) {
-               return set.retainAll(c);
+               return this.set.retainAll(c);
        }
 
        @Override
        public int size() {
-               return set.size();
+               return this.set.size();
        }
 
        @Override
        public Object[] toArray() {
-               return set.toArray();
+               return this.set.toArray();
        }
 
        @Override
        public <T> T[] toArray(final T[] a) {
-               return set.toArray(a);
+               return this.set.toArray(a);
        }
 }
index fe181102785cdcbbe919d5f955b71d2a8373a59b..2433ed5d2e414b0a4c004ecb41c985b02f000970 100644 (file)
@@ -7,14 +7,26 @@
  */
 package org.opendaylight.protocol.util;
 
+/**
+ * Util class for storing various util values as constants.
+ */
 public final class Values {
 
        private Values() {
        }
 
+       /**
+        * Maximum unsigned Short value.
+        */
        public static final int UNSIGNED_SHORT_MAX_VALUE = 65535;
 
+       /**
+        * Maximum unsigned Byte value.
+        */
        public static final int UNSIGNED_BYTE_MAX_VALUE = 255;
 
+       /**
+        * Maximum nsigned Byte value in hex.
+        */
        public static final int BYTE_MAX_VALUE_BYTES = 0xFF;
 }