com.cleancode.util
Class Common

java.lang.Object
  extended by com.cleancode.util.Common

public final class Common
extends Object

Provides some common support methods.

Since:
CleanCode 0.9
Version:
$Revision: 9 $
Author:
Michael Sorens

Field Summary
static String VERSION
          Current version of this class.
 
Method Summary
static String decAndHex(int n)
          Generates a decimal and hex representation of an integer.
static int exponent(int value)
          Returns the power of two of the given number.
static
<T> HashMap<T,T>
toHashMap(T[] items)
          Generates a hash map from a one-dimensional array.
static
<T> HashSet<T>
toHashSet(T[] items)
          Generates a hash set from a one-dimensional array of items.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Current version of this class.

Method Detail

decAndHex

public static String decAndHex(int n)
Generates a decimal and hex representation of an integer.

Parameters:
n - integer argument
Returns:
String of the form "ddd [0xnnnnnnnn]"

toHashMap

public static <T> HashMap<T,T> toHashMap(T[] items)
Generates a hash map from a one-dimensional array. The array is consumed two elements at a time, the first being the key (which must be a String), and the second being its corresponding value.

Type Parameters:
T - Generic-type.
Parameters:
items - array from which to generate Map.
Returns:
HashMap representation of the items array

toHashSet

public static <T> HashSet<T> toHashSet(T[] items)
Generates a hash set from a one-dimensional array of items. The net effect is that duplicates are removed.

Type Parameters:
T - Generic-type.
Parameters:
items - array from which to generate Set.
Returns:
HashSet representation of the items array

exponent

public static int exponent(int value)
Returns the power of two of the given number. Example: exponent(8) returns 3. If the value is not an integral power of two, returns the next lowest power of two. So for 1024 (2^10), the return value is 10, but for 1023, the return value is 9.

Parameters:
value - to examine
Returns:
power of two of the number


CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads