com.h3c.of.lib

## Class CommonUtils

- java.lang.Object
- - com.h3c.of.lib.CommonUtils

-     public class CommonUtils
      extends Object

  Provides common constants and utility methods.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `E_CONTAINS` "Already contains" exception message.
    `static String` | `E_DEPRECATED` "Deprecated since" exception message.
    `static String` | `E_MUTABLE` "Mutable" exception message.
    `static String` | `E_NOT_SUP_BEFORE`
    `static String` | `E_NOT_SUP_BEFORE_11` "Not supported before 1.1" exception message.
    `static String` | `E_NOT_SUP_BEFORE_12` "Not supported before 1.2" exception message.
    `static String` | `E_NOT_SUP_BEFORE_13` "Not supported before 1.3" exception message.
    `static String` | `E_NULL_PARAMS` Null parameter(s) exception message.
    `static String` | `E_RESERVED` "Reserved value" exception message.
    `static String` | `EOLI` Combined EOL and spaced indent for toDebugString() implementations.
    `static String` | `INDENT` Default indentation for toDebugString() implementations.
    `static int` | `INDENT_SIZE` Number of spaces to indent for toDebugString() implementations.
    `static String` | `NO_BODY` "(no body)" text for toDebugString() implementations.
    `static String` | `NONE` String representing "(none)".
    `static String` | `NULL_REP` String representation of the `null` value.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `aSize(byte[] array)` Returns the size of the specified array.
    `static <T> int` | `aSize(T[] array)` Returns the size of the specified array.
    `static int` | `cSize(Collection<?> c)` Returns the size of the specified collection.
    `static String` | `hex(int value)` Returns the given int as a string in hex form.
    `static String` | `hex(long value)` Returns the given long as a string in hex form.
    `static void` | `notContains(Collection<?> coll, Object o)` Verifies that the given collection does not already contain the specified object.
    `static void` | `notDeprecated(ProtocolVersion pv, ProtocolVersion deprecatedAt, String text)` Ensures that the specified protocol version is prior to the specified deprecated version (the version at which the feature is no longer valid).
    `static void` | `notMutable(MultipartBody body)` Verifies that the argument is not mutable.
    `static void` | `notMutable(OpenflowMessage msg)` Verifies that the argument is not mutable.
    `static void` | `notMutable(OpenflowStructure struct)` Verifies that the argument is not mutable.
    `static void` | `notNull(Object... objects)` Verifies that arguments are not null.
    `static void` | `notNullIncompleteMsg(Object... objects)` Verifies that arguments are not null.
    `static void` | `notNullIncompleteStruct(Object... objects)` Verifies that arguments are not null.
    `static int` | `parseHexInt(String hex)` Converts a hex string with an optional "0x" prefix into an int.
    `static long` | `parseHexLong(String hex)` Converts a hex string with an optional "0x" prefix into a long.
    `static void` | `sameVersion(String text, ProtocolVersion... vers)` Ensures that the specified versions are all the same.
    `static void` | `stringField(String str, int fieldSize)` Verifies that the given string will fit in the given field size.
    `static void` | `verMin11(ProtocolVersion pv)` Ensures that the specified protocol version is `1.1` at a minimum.
    `static void` | `verMin11(ProtocolVersion pv, String text)` Ensures that the specified protocol version is `1.1` at a minimum.
    `static void` | `verMin12(ProtocolVersion pv)` Ensures that the specified protocol version is `1.2` at a minimum.
    `static void` | `verMin12(ProtocolVersion pv, String text)` Ensures that the specified protocol version is `1.2` at a minimum.
    `static void` | `verMin13(ProtocolVersion pv)` Ensures that the specified protocol version is `1.3` at a minimum.
    `static void` | `verMin13(ProtocolVersion pv, String text)` Ensures that the specified protocol version is `1.3` at a minimum.
    `static void` | `verMinSince(ProtocolVersion pv, ProtocolVersion since, String text)` Ensures that the specified protocol version is, at a minimum the specified since version.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NULL_REP

          public static final String NULL_REP

      String representation of the `null` value.
      See Also:
        Constant Field Values

    - #### NONE

          public static final String NONE

      String representing "(none)".
      See Also:
        Constant Field Values

    - #### NO_BODY

          public static final String NO_BODY

      "(no body)" text for toDebugString() implementations.
      See Also:
        Constant Field Values

    - #### INDENT_SIZE

          public static final int INDENT_SIZE

      Number of spaces to indent for toDebugString() implementations.
      See Also:
        Constant Field Values

    - #### INDENT

          public static final String INDENT

      Default indentation for toDebugString() implementations.
      See Also:
        Constant Field Values

    - #### EOLI

          public static final String EOLI

      Combined EOL and spaced indent for toDebugString() implementations.

    - #### E_NULL_PARAMS

          public static final String E_NULL_PARAMS

      Null parameter(s) exception message.

    - #### E_DEPRECATED

          public static final String E_DEPRECATED

      "Deprecated since" exception message.

    - #### E_RESERVED

          public static final String E_RESERVED

      "Reserved value" exception message.

    - #### E_MUTABLE

          public static final String E_MUTABLE

      "Mutable" exception message.

    - #### E_CONTAINS

          public static final String E_CONTAINS

      "Already contains" exception message.

    - #### E_NOT_SUP_BEFORE

          public static final String E_NOT_SUP_BEFORE

    - #### E_NOT_SUP_BEFORE_11

          public static final String E_NOT_SUP_BEFORE_11

      "Not supported before 1.1" exception message.

    - #### E_NOT_SUP_BEFORE_12

          public static final String E_NOT_SUP_BEFORE_12

      "Not supported before 1.2" exception message.

    - #### E_NOT_SUP_BEFORE_13

          public static final String E_NOT_SUP_BEFORE_13

      "Not supported before 1.3" exception message.

  - ### Method Detail

    - #### hex

          public static String hex(long value)

      Returns the given long as a string in hex form. For example:

           String s = hex(48);   // "0x30"

      Parameters:
        `value` - the value
      Returns:
        the value in hex form

    - #### hex

          public static String hex(int value)

      Returns the given int as a string in hex form. For example:

           String s = hex(64);    // "0x40"

      Parameters:
        `value` - the value
      Returns:
        the value in hex form

    - #### parseHexInt

          public static int parseHexInt(String hex)

      Converts a hex string with an optional "0x" prefix into an int. The hex string is a string representation of an unsigned integer in base 16. For example:

           int m = parseHexInt("0xff"); // 255
           int n = parseHexInt("ff");   // 255

      Parameters:
        `hex` - a string representing a hexadecimal number with an optional "0x" prefix
      Returns:
        the value as an int
      Throws:
        `NumberFormatException` - if the hex string is not formatted correctly

    - #### parseHexLong

          public static long parseHexLong(String hex)

      Converts a hex string with an optional "0x" prefix into a long. The hex string is a string representation of an unsigned long in base 16. For example:

           long m = parseHexInt("0xff"); // 255L
           long n = parseHexInt("ff");   // 255L

      Parameters:
        `hex` - a string representing a hexadecimal number with an optional "0x" prefix
      Returns:
        the value as a long
      Throws:
        `NumberFormatException` - if the hex string is not formatted correctly

    - #### cSize

          public static int cSize(Collection<?> c)

      Returns the size of the specified collection. If null is specified, zero is returned.
      Parameters:
        `c` - the collection
      Returns:
        the collection's size

    - #### aSize

          public static <T> int aSize(T[] array)

      Returns the size of the specified array. If null is specified, zero is returned.
      Parameters:
        `array` - the array
      Returns:
        the array's size

    - #### aSize

          public static int aSize(byte[] array)

      Returns the size of the specified array. If null is specified, zero is returned.
      Parameters:
        `array` - the array
      Returns:
        the array's size

    - #### notNull

          public static void notNull(Object... objects)

      Verifies that arguments are not null. Throws a NullPointerException if one (or more) is.
      Parameters:
        `objects` - the objects to test
      Throws:
        `NullPointerException` - if any argument is null

    - #### notNullIncompleteMsg

          public static void notNullIncompleteMsg(Object... objects)
                                           throws IncompleteMessageException

      Verifies that arguments are not null. Throws an IncompleteMessageException if one (or more) is.
      Parameters:
        `objects` - the objects to test
      Throws:
        `IncompleteMessageException` - if any argument is null

    - #### notNullIncompleteStruct

          public static void notNullIncompleteStruct(Object... objects)
                                              throws IncompleteStructureException

      Verifies that arguments are not null. Throws an IncompleteStructureException if one (or more) is.
      Parameters:
        `objects` - the objects to test
      Throws:
        `IncompleteStructureException` - if any argument is null

    - #### notMutable

          public static void notMutable(OpenflowStructure struct)

      Verifies that the argument is not mutable.
      Parameters:
        `struct` - the structure to test
      Throws:
        `IllegalArgumentException` - if the argument is mutable

    - #### notMutable

          public static void notMutable(MultipartBody body)

      Verifies that the argument is not mutable.
      Parameters:
        `body` - the multipart-body to test
      Throws:
        `IllegalArgumentException` - if the argument is mutable

    - #### notMutable

          public static void notMutable(OpenflowMessage msg)

      Verifies that the argument is not mutable.
      Parameters:
        `msg` - the msg to test
      Throws:
        `IllegalArgumentException` - if the argument is mutable

    - #### notContains

          public static void notContains(Collection<?> coll,
                         Object o)

      Verifies that the given collection does not already contain the specified object.
      Parameters:
        `coll` - the collection
        `o` - the object
      Throws:
        `IllegalArgumentException` - if the collection contains the object

    - #### stringField

          public static void stringField(String str,
                         int fieldSize)

      Verifies that the given string will fit in the given field size. The string length must be `fieldSize - 1` or less (we need a byte for the null terminator).
      Parameters:
        `str` - the string to test (may be null)
        `fieldSize` - the size of field to fit the string into
      Throws:
        `IllegalArgumentException` - if the string will not fit the field

    - #### verMin11

          public static void verMin11(ProtocolVersion pv,
                      String text)

      Ensures that the specified protocol version is `1.1` at a minimum. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown. The supplied text is included in the exception message.
      Parameters:
        `pv` - the protocol version to test
        `text` - additional detail to add to the exception message
      Throws:
        `VersionMismatchException` - if protocol version is earlier than 1.1

    - #### verMin11

          public static void verMin11(ProtocolVersion pv)

      Ensures that the specified protocol version is `1.1` at a minimum. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown.
      Parameters:
        `pv` - the protocol version to test
      Throws:
        `VersionMismatchException` - if protocol version is earlier than 1.1

    - #### verMin12

          public static void verMin12(ProtocolVersion pv,
                      String text)

      Ensures that the specified protocol version is `1.2` at a minimum. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown. The supplied text is included in the exception message.
      Parameters:
        `pv` - the protocol version to test
        `text` - additional detail to add to the exception message
      Throws:
        `VersionMismatchException` - if protocol version is earlier than 1.2

    - #### verMin12

          public static void verMin12(ProtocolVersion pv)

      Ensures that the specified protocol version is `1.2` at a minimum. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown.
      Parameters:
        `pv` - the protocol version to test
      Throws:
        `VersionMismatchException` - if protocol version is earlier than 1.2

    - #### verMin13

          public static void verMin13(ProtocolVersion pv,
                      String text)

      Ensures that the specified protocol version is `1.3` at a minimum. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown. The supplied text is included in the exception message.
      Parameters:
        `pv` - the protocol version to test
        `text` - additional detail to add to the exception message
      Throws:
        `VersionMismatchException` - if protocol version is earlier than 1.3

    - #### verMin13

          public static void verMin13(ProtocolVersion pv)

      Ensures that the specified protocol version is `1.3` at a minimum. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown.
      Parameters:
        `pv` - the protocol version to test
      Throws:
        `VersionMismatchException` - if protocol version is earlier than 1.3

    - #### verMinSince

          public static void verMinSince(ProtocolVersion pv,
                         ProtocolVersion since,
                         String text)

      Ensures that the specified protocol version is, at a minimum the specified since version. If it is, this method silently returns. If it is not, a `VersionMismatchException` is thrown. The supplied text is included in the exception message.
      Parameters:
        `pv` - the protocol version to test
        `since` - the protocol version to test against
        `text` - additional detail to add to the exception message
      Throws:
        `VersionMismatchException` - if `pv` is earlier than the version specified as `since`

    - #### sameVersion

          public static void sameVersion(String text,
                         ProtocolVersion... vers)

      Ensures that the specified versions are all the same. If they are, this method silently returns. If not, a `VersionMismatchException` is thrown, with the specified message text.
      Parameters:
        `text` - text of the exception message
        `vers` - the versions to test

    - #### notDeprecated

          public static void notDeprecated(ProtocolVersion pv,
                           ProtocolVersion deprecatedAt,
                           String text)

      Ensures that the specified protocol version is prior to the specified deprecated version (the version at which the feature is no longer valid). If it is, this method silently returns. If not, a `VersionMismatchException` is thrown, with the specified message text.
      Parameters:
        `pv` - the protocol version to test
        `deprecatedAt` - the version at which the feature was deprecated
        `text` - additional detail to add to the exception message
      Throws:
        `VersionMismatchException` - if `pv` is the same as or later than the version specified as `deprecatedAt`

Copyright © 2014. All Rights Reserved.