com.babaroga.test
Class Utility

java.lang.Object
  extended by com.babaroga.test.Utility

public final class Utility
extends java.lang.Object

Utility class for general helper methods.


Method Summary
static java.util.List<java.lang.String> getLinesFromFile(java.lang.String filename)
          Retrieves each line from a text file as a list of Strings.
static boolean isValidImageWriterFormat(java.lang.String format)
          Determines if the specified image format can be written.
static int nextPowOf2(int n)
          Finds the bitwise next highest power-of-2 of a non-power-of-2 integer.
static int totalArea(java.util.Collection<java.awt.Rectangle> rectangles)
          Calculates the sum of the areas of a collection of rectangles.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

nextPowOf2

public static int nextPowOf2(int n)
Finds the bitwise next highest power-of-2 of a non-power-of-2 integer. If n is already a power-of-2 it will be returned as-is. Note: Since int is a signed integer if n is Integer.MAX_VALUE (0x7FFFFFFF), the next highest power of 2 is Integer.MIN_VALUE (0x80000000). Similarly, any negative integer will overflow to zero.

Parameters:
n - A non-power-of-2 integer.
Returns:
The integer after n that is a power-of-2.
See Also:
http://en.wikipedia.org/wiki/Power_of_two

isValidImageWriterFormat

public static boolean isValidImageWriterFormat(java.lang.String format)
Determines if the specified image format can be written.

Parameters:
format - The format extension (e.g. "bmp").
Returns:
true if format is a valid image extension.

totalArea

public static int totalArea(java.util.Collection<java.awt.Rectangle> rectangles)
Calculates the sum of the areas of a collection of rectangles.

Parameters:
rectangles - The rectangles whose areas will be summed.
Returns:
the sum of all areas of the specified rectangles.

getLinesFromFile

public static java.util.List<java.lang.String> getLinesFromFile(java.lang.String filename)
Retrieves each line from a text file as a list of Strings.

Parameters:
filename - The name of the text file.
Returns:
A lines of the text file.