edu.umbc.cs.maple.utils
Class JavaUtils

java.lang.Object
  extended by edu.umbc.cs.maple.utils.JavaUtils

public class JavaUtils
extends java.lang.Object

Various utility functions for Java.

Copyright (c) 2008 Eric Eaton

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Version:
0.1
Author:
Eric Eaton (EricEaton@umbc.edu)
University of Maryland Baltimore County

Field Summary
static java.text.DecimalFormat format1DecimalPlace
           
static java.text.DecimalFormat format2DecimalPlaces
           
static java.text.DecimalFormat format3DecimalPlaces
           
static java.text.DecimalFormat format4DecimalPlaces
           
 
Constructor Summary
JavaUtils()
           
 
Method Summary
static int[] arrayAppend(int[] objs, int newObj)
          Appends an element to an array.
static
<T> T[]
arrayAppend(T[] objs, T newObj)
          Appends an element to an array.
static double[] arrayCopy(double[] objs)
          Copy the given array.
static int[] arrayCopy(int[] objs)
          Copy the given array.
static
<T> T[]
arrayCopy(T[] objs)
          Copy the given array.
static
<T> T[]
arrayDelete(T[] objs, int indexToDelete)
          Delete the specified element from the array.
static
<T> T[]
arrayReverse(T[] array)
          Reverses the given array.
static java.lang.String arrayToString(double[] v)
           
static java.lang.String arrayToString(double[] v, java.text.DecimalFormat df)
           
static java.lang.String arrayToString(java.lang.String[] v)
           
static double[] collectionToPrimitiveArray(java.util.Collection<java.lang.Double> collection)
           
static int[] collectionToPrimitiveArray(java.util.Collection<java.lang.Integer> collection)
           
static java.awt.image.BufferedImage getBufferedImage(java.awt.Image img)
           
static byte[] getBytesFromFile(java.io.File file)
           
static java.lang.String[] parseFileToStringArray(java.lang.String filename)
          Opens a file and generates an array of strings.
static long totalMemoryMB()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

format1DecimalPlace

public static java.text.DecimalFormat format1DecimalPlace

format2DecimalPlaces

public static java.text.DecimalFormat format2DecimalPlaces

format3DecimalPlaces

public static java.text.DecimalFormat format3DecimalPlaces

format4DecimalPlaces

public static java.text.DecimalFormat format4DecimalPlaces
Constructor Detail

JavaUtils

public JavaUtils()
Method Detail

arrayAppend

public static <T> T[] arrayAppend(T[] objs,
                                  T newObj)
Appends an element to an array.

Type Parameters:
T - the generic type of the array.
Parameters:
objs - the array.
newObj - the object to append the the array.
Returns:
the array with the specified element appended

arrayAppend

public static int[] arrayAppend(int[] objs,
                                int newObj)
Appends an element to an array.

Parameters:
objs - the array.
newObj - the object to append the the array.
Returns:
the array with the specified element appended

arrayCopy

public static <T> T[] arrayCopy(T[] objs)
Copy the given array.

Type Parameters:
T - the generic type of the array.
Parameters:
objs - the array.
Returns:
a copy of the array, null if the array is null.

arrayCopy

public static int[] arrayCopy(int[] objs)
Copy the given array.

Parameters:
objs - the array.
Returns:
a copy of the array, null if the array is null.

arrayCopy

public static double[] arrayCopy(double[] objs)
Copy the given array.

Parameters:
objs - the array.
Returns:
a copy of the array, null if the array is null.

arrayDelete

public static <T> T[] arrayDelete(T[] objs,
                                  int indexToDelete)
Delete the specified element from the array.

Type Parameters:
T - the generic type of the array.
Parameters:
objs - the array.
indexToDelete - the index to delete from the array.
Returns:
the array with the specified element deleted.

arrayReverse

public static <T> T[] arrayReverse(T[] array)
Reverses the given array.

Type Parameters:
T - the generic type of the array.
Parameters:
array - the array.
Returns:
the array with the elements in reverse order

collectionToPrimitiveArray

public static double[] collectionToPrimitiveArray(java.util.Collection<java.lang.Double> collection)

collectionToPrimitiveArray

public static int[] collectionToPrimitiveArray(java.util.Collection<java.lang.Integer> collection)

arrayToString

public static java.lang.String arrayToString(double[] v)

arrayToString

public static java.lang.String arrayToString(double[] v,
                                             java.text.DecimalFormat df)

arrayToString

public static java.lang.String arrayToString(java.lang.String[] v)

parseFileToStringArray

public static java.lang.String[] parseFileToStringArray(java.lang.String filename)
Opens a file and generates an array of strings. Each string in the array is a non-comment, non-blank line from the file

Parameters:
filename - - the name of the file to open
Returns:
- an array strings representing the meaningful lines in the file

getBytesFromFile

public static byte[] getBytesFromFile(java.io.File file)
                               throws java.io.IOException
Throws:
java.io.IOException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.awt.Image img)

totalMemoryMB

public static long totalMemoryMB()