public final class Util extends Object
Warning: All methods related to Log4J 1.2 are now deprecated, as we are switching
to SLF4J for all logging activity. If you were
using getLogger(Class), just replace all occurrences of getLogger(Class) with
LoggerFactory.getLogger(Class) (some other minor modifications to your source code might
be required).
Note that while ProgressLogger will still support for a while Log4J 1.2, getLogger(Class) and
ensureLog4JIsConfigured(Class, Level) ensure just minimal support.
| Modifier and Type | Field and Description |
|---|---|
static Runtime |
RUNTIME
A static reference to
Runtime.getRuntime(). |
| Modifier and Type | Method and Description |
|---|---|
static long |
availableMemory()
Returns the amount of available memory (free memory plus never allocated memory).
|
static void |
compactMemory()
Tries to compact memory as much as possible by forcing garbage collection.
|
static void |
ensureLog4JIsConfigured()
Deprecated.
Use SLF4J.
|
static void |
ensureLog4JIsConfigured(Class<?> klass)
Deprecated.
Use SLF4J.
|
static void |
ensureLog4JIsConfigured(Class<?> klass,
Level level)
Deprecated.
Use SLF4J.
|
static void |
ensureLog4JIsConfigured(Level level)
Deprecated.
Use SLF4J.
|
static String |
format(double d)
Formats a number.
|
static String |
format(double d,
NumberFormat format)
Formats a number using a specified
NumberFormat. |
static String |
format(long l)
Formats a number.
|
static String |
format(long l,
NumberFormat format)
Formats a number using a specified
NumberFormat. |
static String |
formatBinarySize(long l)
Formats a binary size.
|
static String |
formatBinarySize(long l,
NumberFormat format)
Formats a size using a specified
NumberFormat. |
static String |
formatSize(long l)
Formats a size.
|
static String |
formatSize(long l,
NumberFormat format)
Formats a size using a specified
NumberFormat. |
static String |
formatSize2(long l)
Formats a size.
|
static String |
formatSize2(long l,
NumberFormat format)
Formats a size using a specified
NumberFormat and binary unit multipliers. |
static Logger |
getDebugLogger(Class<?> klass)
Deprecated.
|
static Logger |
getLogger(Class<?> klass)
Deprecated.
|
static int[] |
identity(int n)
Stores the identity permutation in a new array of given length.
|
static int[] |
identity(int[] perm)
Stores the identity permutation in an array.
|
static long[][] |
identity(long n)
Stores the identity permutation in a new big array of given length.
|
static long[][] |
identity(long[][] perm)
Stores the identity permutation in a big array.
|
static int[] |
invertPermutation(int[] perm)
Computes the inverse of a permutation expressed
as an array of n distinct integers in [0 .. n)
and stores the result in a new array.
|
static int[] |
invertPermutation(int[] perm,
int[] inv)
Computes the inverse of a permutation expressed
as an array of n distinct integers in [0 .. n).
|
static long[][] |
invertPermutation(long[][] perm)
Computes the inverse of a permutation expressed
as a big array of n distinct long integers in [0 .. n)
and stores the result in a new big array.
|
static long[][] |
invertPermutation(long[][] perm,
long[][] inv)
Computes the inverse of a permutation expressed
as a big array of n distinct long integers in [0 .. n).
|
static int[] |
invertPermutationInPlace(int[] perm)
Computes in place the inverse of a permutation expressed
as an array of n distinct integers in [0 .. n).
|
static long[][] |
invertPermutationInPlace(long[][] perm)
Computes in place the inverse of a permutation expressed
as a big array of n distinct long integers in [0 .. n).
|
static boolean |
log4JIsConfigured()
Deprecated.
Use SLF4J.
|
static boolean |
memoryIsLow()
Returns true if less then 5% of the available memory is free.
|
static int |
percAvailableMemory()
Returns the percentage of available memory (free memory plus never allocated memory).
|
static long |
randomSeed()
Returns a random seed generated by taking a unique increasing long, adding
System.nanoTime() and scrambling the result using the finalisation step of Austin
Appleby's MurmurHash3. |
static byte[] |
randomSeedBytes()
Returns a random seed generated by
randomSeed() under the form of an array of eight bytes. |
public static final Runtime RUNTIME
Runtime.getRuntime().public static String format(double d)
This method formats a double separating thousands and printing just two fractional digits.
Note that the method is synchronized, as it uses a static NumberFormat.
d - a number.public static String format(long l)
This method formats a long separating thousands.
Note that the method is synchronized, as it uses a static NumberFormat.
l - a number.public static String format(double d, NumberFormat format)
NumberFormat.d - a number.format - a format.public static String format(long l, NumberFormat format)
NumberFormat.l - a number.format - a format.public static String formatSize(long l)
This method formats a long using suitable unit multipliers (e.g., K, M, G, and T) and printing just two fractional digits.
Note that the method is synchronized, as it uses a static NumberFormat.
l - a number, representing a size (e.g., memory).public static String formatBinarySize(long l)
This method formats a long using suitable unit binary multipliers (e.g., Ki, Mi, Gi, and Ti) and printing no fractional digits. The argument must be a power of 2.
Note that the method is synchronized, as it uses a static NumberFormat.
l - a number, representing a binary size (e.g., memory); must be a power of 2.public static String formatSize2(long l)
This method formats a long using suitable binary unit multipliers (e.g., Ki, Mi, Gi, and Ti) and printing just two fractional digits.
Note that the method is synchronized, as it uses a static NumberFormat.
l - a number, representing a size (e.g., memory).public static String formatSize(long l, NumberFormat format)
NumberFormat.
This method formats a long using suitable unit multipliers (e.g., K, M, G, and T)
and the given NumberFormat for the digits.
l - a number, representing a size (e.g., memory).format - a format.public static String formatBinarySize(long l, NumberFormat format)
NumberFormat.
This method formats a long using suitable unit binary multipliers (e.g., Ki, Mi, Gi, and Ti)
and the given NumberFormat for the digits. The argument must be a power of 2.
l - a number, representing a binary size (e.g., memory); must be a power of 2.format - a format.public static String formatSize2(long l, NumberFormat format)
NumberFormat and binary unit multipliers.
This method formats a long using suitable binary
unit multipliers (e.g., Ki, Mi, Gi, and Ti)
and the given NumberFormat for the digits.
l - a number, representing a size (e.g., memory).format - a format.@Deprecated public static boolean log4JIsConfigured()
@Deprecated public static void ensureLog4JIsConfigured(Class<?> klass)
BasicConfigurator.configure(), and
setting the root logger level to Level.INFO.klass - the calling class (to be shown to the user).@Deprecated public static void ensureLog4JIsConfigured(Class<?> klass, Level level)
BasicConfigurator.configure(), and
setting the root logger level to level.klass - the calling class (to be shown to the user).level - the required logging level.@Deprecated public static void ensureLog4JIsConfigured()
BasicConfigurator.configure(), and
setting the root logger level to Level.INFO.@Deprecated public static void ensureLog4JIsConfigured(Level level)
BasicConfigurator.configure(), and
setting the root logger level to a specified logging level.level - the required logging level.@Deprecated public static Logger getLogger(Class<?> klass)
LoggerFactory.getLogger(Class)Logger.getLogger(java.lang.Class) method and then ensureLog4JIsConfigured().klass - a class that will be passed to Logger.getLogger(java.lang.Class).Logger.getLogger(java.lang.Class).@Deprecated public static Logger getDebugLogger(Class<?> klass)
LoggerFactory.getLogger(Class)Logger.getLogger(java.lang.Class) method and then ensureLog4JIsConfigured() with argument Level.DEBUG.klass - a class that will be passed to Logger.getLogger(java.lang.Class).Logger.getLogger(java.lang.Class).public static boolean memoryIsLow()
public static long availableMemory()
public static int percAvailableMemory()
public static void compactMemory()
public static long randomSeed()
System.nanoTime() and scrambling the result using the finalisation step of Austin
Appleby's MurmurHash3.public static byte[] randomSeedBytes()
randomSeed() under the form of an array of eight bytes.public static int[] invertPermutationInPlace(int[] perm)
Warning: if perm is not a permutation,
essentially anything can happen.
perm - the permutation to be inverted.perm.public static int[] invertPermutation(int[] perm,
int[] inv)
Warning: if perm is not a permutation,
essentially anything can happen.
perm - the permutation to be inverted.inv - the array storing the inverse.inv.public static int[] invertPermutation(int[] perm)
Warning: if perm is not a permutation,
essentially anything can happen.
perm - the permutation to be inverted.public static int[] identity(int[] perm)
perm - an array of integers.perm, filled with the identity permutation.public static int[] identity(int n)
n - the size of the array.n, filled with the identity permutation.public static long[][] invertPermutationInPlace(long[][] perm)
Warning: if perm is not a permutation,
essentially anything can happen.
perm - the permutation to be inverted.perm.public static long[][] invertPermutation(long[][] perm,
long[][] inv)
Warning: if perm is not a permutation,
essentially anything can happen.
perm - the permutation to be inverted.inv - the big array storing the inverse.inv.public static long[][] invertPermutation(long[][] perm)
Warning: if perm is not a permutation,
essentially anything can happen.
perm - the permutation to be inverted.public static long[][] identity(long[][] perm)
perm - a big array.perm, filled with the identity permutation.public static long[][] identity(long n)
n - the size of the array.n, filled with the identity permutation.