public class CommonUtils extends Object
| 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. |
| 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.
|
public static final String NULL_REP
null value.public static final String NONE
public static final String NO_BODY
public static final int INDENT_SIZE
public static final String INDENT
public static final String EOLI
public static final String E_NULL_PARAMS
public static final String E_DEPRECATED
public static final String E_RESERVED
public static final String E_MUTABLE
public static final String E_CONTAINS
public static final String E_NOT_SUP_BEFORE
public static final String E_NOT_SUP_BEFORE_11
public static final String E_NOT_SUP_BEFORE_12
public static final String E_NOT_SUP_BEFORE_13
public static String hex(long value)
String s = hex(48); // "0x30"
value - the valuepublic static String hex(int value)
String s = hex(64); // "0x40"
value - the valuepublic static int parseHexInt(String hex)
int m = parseHexInt("0xff"); // 255
int n = parseHexInt("ff"); // 255
hex - a string representing a hexadecimal number with an optional
"0x" prefixNumberFormatException - if the hex string is not formatted
correctlypublic static long parseHexLong(String hex)
long m = parseHexInt("0xff"); // 255L
long n = parseHexInt("ff"); // 255L
hex - a string representing a hexadecimal number with an optional
"0x" prefixNumberFormatException - if the hex string is not formatted
correctlypublic static int cSize(Collection<?> c)
c - the collectionpublic static <T> int aSize(T[] array)
array - the arraypublic static int aSize(byte[] array)
array - the arraypublic static void notNull(Object... objects)
objects - the objects to testNullPointerException - if any argument is nullpublic static void notNullIncompleteMsg(Object... objects) throws IncompleteMessageException
objects - the objects to testIncompleteMessageException - if any argument is nullpublic static void notNullIncompleteStruct(Object... objects) throws IncompleteStructureException
objects - the objects to testIncompleteStructureException - if any argument is nullpublic static void notMutable(OpenflowStructure struct)
struct - the structure to testIllegalArgumentException - if the argument is mutablepublic static void notMutable(MultipartBody body)
body - the multipart-body to testIllegalArgumentException - if the argument is mutablepublic static void notMutable(OpenflowMessage msg)
msg - the msg to testIllegalArgumentException - if the argument is mutablepublic static void notContains(Collection<?> coll, Object o)
coll - the collectiono - the objectIllegalArgumentException - if the collection contains the objectpublic static void stringField(String str, int fieldSize)
fieldSize - 1 or less (we need
a byte for the null terminator).str - the string to test (may be null)fieldSize - the size of field to fit the string intoIllegalArgumentException - if the string will not fit the fieldpublic static void verMin11(ProtocolVersion pv, String text)
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.pv - the protocol version to testtext - additional detail to add to the exception messageVersionMismatchException - if protocol version is earlier than 1.1public static void verMin11(ProtocolVersion pv)
1.1 at a minimum. If it is, this
method silently returns. If it is not,
a VersionMismatchException is thrown.pv - the protocol version to testVersionMismatchException - if protocol version is earlier than 1.1public static void verMin12(ProtocolVersion pv, String text)
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.pv - the protocol version to testtext - additional detail to add to the exception messageVersionMismatchException - if protocol version is earlier than 1.2public static void verMin12(ProtocolVersion pv)
1.2 at a minimum. If it is, this
method silently returns. If it is not,
a VersionMismatchException is thrown.pv - the protocol version to testVersionMismatchException - if protocol version is earlier than 1.2public static void verMin13(ProtocolVersion pv, String text)
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.pv - the protocol version to testtext - additional detail to add to the exception messageVersionMismatchException - if protocol version is earlier than 1.3public static void verMin13(ProtocolVersion pv)
1.3 at a minimum. If it is, this
method silently returns. If it is not,
a VersionMismatchException is thrown.pv - the protocol version to testVersionMismatchException - if protocol version is earlier than 1.3public static void verMinSince(ProtocolVersion pv, ProtocolVersion since, String text)
VersionMismatchException is thrown.
The supplied text is included in the exception message.pv - the protocol version to testsince - the protocol version to test againsttext - additional detail to add to the exception messageVersionMismatchException - if pv is earlier than
the version specified as sincepublic static void sameVersion(String text, ProtocolVersion... vers)
VersionMismatchException
is thrown, with the specified message text.text - text of the exception messagevers - the versions to testpublic static void notDeprecated(ProtocolVersion pv, ProtocolVersion deprecatedAt, String text)
VersionMismatchException is thrown, with the specified message
text.pv - the protocol version to testdeprecatedAt - the version at which the feature was deprecatedtext - additional detail to add to the exception messageVersionMismatchException - if pv is the same as or
later than the version specified as deprecatedAtCopyright © 2014. All Rights Reserved.