it.unimi.dsi
Class Util

java.lang.Object
  extended by it.unimi.dsi.Util

public final class Util
extends java.lang.Object

All-purpose static-method container class.

Since:
0.1
Author:
Sebastiano Vigna

Method Summary
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()
          Ensures that Log4J is configured, by invoking, if necessary, BasicConfigurator.configure(), and setting the root logger level to Level.INFO.
static void ensureLog4JIsConfigured(org.apache.log4j.Level level)
          Ensures that Log4J is configured, by invoking, if necessary, BasicConfigurator.configure(), and setting the root logger level to level.
static java.lang.String format(double d)
          Formats a number.
static java.lang.String format(long l)
          Formats a number.
static java.lang.String formatBinarySize(long l)
          Formats a binary size.
static java.lang.String formatSize(long l)
          Formats a size.
static org.apache.log4j.Logger getLogger(java.lang.Class<?> klass)
          Calls Log4J's Logger.getLogger(java.lang.Class) method and then ensureLog4JIsConfigured().
static boolean log4JIsConfigured()
          Checks whether Log4J is properly configuring by searching for appenders in all loggers.
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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

format

public static java.lang.String format(double d)
Formats a number.

This method formats a double separating thousands and printing just two fractional digits.

Parameters:
d - a number.
Returns:
a string containing a pretty print of the number.

format

public static java.lang.String format(long l)
Formats a number.

This method formats a long separating thousands.

Parameters:
l - a number.
Returns:
a string containing a pretty print of the number.

formatSize

public static java.lang.String formatSize(long l)
Formats a size.

This method formats a long using suitable unit multipliers (e.g., K, M, G, and T) and printing just two fractional digits.

Parameters:
l - a number, representing a size (e.g., memory).
Returns:
a string containing a pretty print of the number using unit multipliers.

formatBinarySize

public static java.lang.String formatBinarySize(long l)
Formats a binary size.

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.

Parameters:
l - a number, representing a binary size (e.g., memory); must be a power of 2.
Returns:
a string containing a pretty print of the number using binary unit multipliers.

log4JIsConfigured

public static boolean log4JIsConfigured()
Checks whether Log4J is properly configuring by searching for appenders in all loggers.

Returns:
whether Log4J is configured (or, at least, an educated guess).

ensureLog4JIsConfigured

public static void ensureLog4JIsConfigured()
Ensures that Log4J is configured, by invoking, if necessary, BasicConfigurator.configure(), and setting the root logger level to Level.INFO.


ensureLog4JIsConfigured

public static void ensureLog4JIsConfigured(org.apache.log4j.Level level)
Ensures that Log4J is configured, by invoking, if necessary, BasicConfigurator.configure(), and setting the root logger level to level.

Parameters:
level - the required logging level.

getLogger

public static org.apache.log4j.Logger getLogger(java.lang.Class<?> klass)
Calls Log4J's Logger.getLogger(java.lang.Class) method and then ensureLog4JIsConfigured().

Parameters:
klass - a class that will be passed to Logger.getLogger(java.lang.Class).
Returns:
the logger returned by Logger.getLogger(java.lang.Class).

memoryIsLow

public static boolean memoryIsLow()
Returns true if less then 5% of the available memory is free.

Returns:
true if less then 5% of the available memory is free.

availableMemory

public static long availableMemory()
Returns the amount of available memory (free memory plus never allocated memory).

Returns:
the amount of available memory, in bytes.

percAvailableMemory

public static int percAvailableMemory()
Returns the percentage of available memory (free memory plus never allocated memory).

Returns:
the percentage of available memory.

compactMemory

public static void compactMemory()
Tries to compact memory as much as possible by forcing garbage collection.