qflib 0.99

de.qfs.lib.util
Class Misc

java.lang.Object
  extended byde.qfs.lib.util.Misc

public abstract class Misc
extends java.lang.Object

A collection of miscellaneous utility functions.

Since:
0.99.0
Author:
Gregor Schmid

Constructor Summary
Misc()
           
 
Method Summary
static int countLines(java.lang.String text)
          Count the number of lines in a text String.
static boolean equalOrEmpty(java.lang.String s1, java.lang.String s2)
          Test whether two Strings are equal or both empty or null.
static boolean equalOrNull(java.lang.Object o1, java.lang.Object o2)
          Test whether two objects are equal or both null.
static byte[] fromHex(java.lang.String hex)
          Convert a hex String into a byte array.
static int getMajorJavaVersion()
          Get the major version of the Java VM.
static int getMediumJavaVersion()
          Get the medium version of the Java VM.
static int getMinorJavaVersion()
          Get the minor version of the Java VM.
static boolean isJavaVersion(int major, int medium, int minor)
          Test whether the version of the Java VM matches a given version.
static boolean isJavaVersionAtLeast(int major, int medium, int minor)
          Test whether the version of the Java VM is at least a given version.
static java.lang.String lineSepToLineFeed(java.lang.String text)
          Convert system specific line separators in a String to just line feed characters.
static java.lang.String quote(java.lang.String data, java.lang.String toQuote)
          Quote special characters in a String with a backslash.
static java.lang.String quote(java.lang.String data, java.lang.String toQuote, char quote)
          Quote special characters in a String.
static java.lang.String[] splitLines(java.lang.String text)
          Split a text into lines.
static java.lang.String toHex(byte[] data)
          Convert a byte array into a hex string.
static java.lang.String toHex(byte[] data, int start, int count)
          Convert a byte array into a hex string.
static java.lang.String unquote(java.lang.String data, java.lang.String toQuote)
          Unquote special characters in a String, quoted with a backslash.
static java.lang.String unquote(java.lang.String data, java.lang.String toQuote, char quote)
          Unquote special characters in a String.
static int unquotedIndexOf(java.lang.String data, java.lang.String chars, int start)
          Find the index of an unquoted version of a character in a String.
static int unquotedIndexOf(java.lang.String data, java.lang.String chars, int start, char quote)
          Find the index of an unquoted version of a character in a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Misc

public Misc()
Method Detail

equalOrNull

public static boolean equalOrNull(java.lang.Object o1,
                                  java.lang.Object o2)
Test whether two objects are equal or both null.

Parameters:
o1 - The first object.
o2 - The second object.
Returns:
True if they are equal or both null.

equalOrEmpty

public static boolean equalOrEmpty(java.lang.String s1,
                                   java.lang.String s2)
Test whether two Strings are equal or both empty or null.

Parameters:
s1 - The first String.
s2 - The second String.
Returns:
True if they are equal or both empty or null.

lineSepToLineFeed

public static java.lang.String lineSepToLineFeed(java.lang.String text)
Convert system specific line separators in a String to just line feed characters. Null Strings are OK. Any of the character combinations "\n", "\r\n", "\r" will be turned into a single line-feed "\n".

Parameters:
text - The input string.
Returns:
The converted string.

countLines

public static int countLines(java.lang.String text)
Count the number of lines in a text String. Recognizes the line separators \r, \n and \r\n.

Parameters:
text - The input text.
Returns:
0 if text is NULL, empty or a single line break. The number of lines otherwise.

splitLines

public static java.lang.String[] splitLines(java.lang.String text)
Split a text into lines. Recognizes the line separators \r, \n and \r\n.

Parameters:
text - The input text.
Returns:
An empty array if text is NULL or empty. An array with the text lines otherwise. The result lines don't contain line separators.

quote

public static java.lang.String quote(java.lang.String data,
                                     java.lang.String toQuote)
Quote special characters in a String with a backslash.

Parameters:
data - The string.
toQuote - The characters to quote. Don't forget to add the backslash itself.
Returns:
The quoted String.

quote

public static java.lang.String quote(java.lang.String data,
                                     java.lang.String toQuote,
                                     char quote)
Quote special characters in a String.

Parameters:
data - The string.
toQuote - The characters to quote. Don't forget to add the quote character itself.
quote - The quote character.
Returns:
The quoted String.

unquote

public static java.lang.String unquote(java.lang.String data,
                                       java.lang.String toQuote)
Unquote special characters in a String, quoted with a backslash.

Parameters:
data - The string.
toQuote - The characters to quote. Don't forget to add the backslash itself.
Returns:
The unquoted String.

unquote

public static java.lang.String unquote(java.lang.String data,
                                       java.lang.String toQuote,
                                       char quote)
Unquote special characters in a String.

Parameters:
data - The string.
toQuote - The characters to quote. Don't forget to add the quote character itself.
quote - The quote character.
Returns:
The unquoted String.

unquotedIndexOf

public static int unquotedIndexOf(java.lang.String data,
                                  java.lang.String chars,
                                  int start)
Find the index of an unquoted version of a character in a String.

Parameters:
data - The String.
chars - The characters to look for.
start - The position to start the search at.
Returns:
The index of the first unquoted char or -1.

unquotedIndexOf

public static int unquotedIndexOf(java.lang.String data,
                                  java.lang.String chars,
                                  int start,
                                  char quote)
Find the index of an unquoted version of a character in a String.

Parameters:
data - The String.
chars - The characters to look for.
start - The position to start the search at.
quote - The quote character.
Returns:
The index of the first unquoted char or -1.

toHex

public static java.lang.String toHex(byte[] data)
Convert a byte array into a hex string.

Parameters:
data - The data to convert.
Returns:
The hex string.

toHex

public static java.lang.String toHex(byte[] data,
                                     int start,
                                     int count)
Convert a byte array into a hex string.

Parameters:
data - The data to convert.
start - Start conversion at this position.
count - Convert that many bytes.
Returns:
The hex string.

fromHex

public static byte[] fromHex(java.lang.String hex)
                      throws java.lang.IllegalArgumentException
Convert a hex String into a byte array.

Parameters:
hex - The input String.
Returns:
The converted byte array.
Throws:
java.lang.IllegalArgumentException - If the string contains non-hex characters.

getMajorJavaVersion

public static int getMajorJavaVersion()
Get the major version of the Java VM.

Returns:
The major version of the Java VM.

getMediumJavaVersion

public static int getMediumJavaVersion()
Get the medium version of the Java VM.

Returns:
The medium version of the Java VM.

getMinorJavaVersion

public static int getMinorJavaVersion()
Get the minor version of the Java VM.

Returns:
The minor version of the Java VM.

isJavaVersion

public static boolean isJavaVersion(int major,
                                    int medium,
                                    int minor)
Test whether the version of the Java VM matches a given version.

Parameters:
major - The major version to test, -1 to ignore.
medium - The medium version to test, -1 to ignore.
minor - The minor version to test, -1 to ignore.
Returns:
True if the version matches, false otherwise.

isJavaVersionAtLeast

public static boolean isJavaVersionAtLeast(int major,
                                           int medium,
                                           int minor)
Test whether the version of the Java VM is at least a given version.

Parameters:
major - The major version to test, -1 to ignore.
medium - The medium version to test, -1 to ignore.
minor - The minor version to test, -1 to ignore.
Returns:
True if the version matches, false otherwise.

qflib 0.99