edu.iastate.metnet.utils
Class Utils

java.lang.Object
  extended by edu.iastate.metnet.utils.Utils

public class Utils
extends java.lang.Object

Utilitiy class

Author:
Jie Li

Field Summary
(package private) static org.apache.log4j.Logger logger
           
(package private) static int negativeSequence
          save the sequence
(package private) static java.net.ServerSocket socket
          socket for single instance testing
(package private) static Utils utils
          the database statement instance
 
Method Summary
 void applyTheme(java.lang.String themeName)
          regardless the user options, always use the Eve's look and feel for MetNet tools.
 void applyTheme2(java.lang.String themeName)
          apply the theme from the theme file based on metal theme
 java.util.Vector arrayToVector(java.lang.Object[] arr)
           
static java.lang.Object deepCopy(java.lang.Object orig)
          Returns a copy of the object, or null if the object cannot be serialized.
 void dummyLabel(java.awt.Container panel, int num_cols, int num_rows)
           
static java.lang.String escapeXML(java.lang.String input)
          replace all sensitive chars to special XML strings
static java.lang.String[] explode(java.lang.String template, java.lang.String delim)
          similar to StringTokenize, split string by delim
static java.lang.String generateGUID(java.lang.Object o)
          A 32 byte GUID generator (Globally Unique ID).
static int generateNegativeBasedUUID()
          get the next unique id for the null vertex
static java.lang.String getCurrentSQLDate()
          get current data with 'yyyy-mm-dd' format
static java.lang.String getDB()
           
static java.util.List getDifferenceWithCase(java.util.List a, java.util.List b)
          get differnece a-b, case sensitive
static java.util.List getDifferenceWithoutCase(java.util.List a, java.util.List b)
          get the difference a-b, case insensitive
static java.util.List getDifferenceXWithCase(java.util.List a, java.util.List b)
          get differnece of (a-b) + (b-a), case sensitive
static java.util.List getDifferenceXWithoutCase(java.util.List a, java.util.List b)
          get the difference (a-b) + (b-a), case insensitive
static java.lang.Object getFirst(java.util.Map map, java.lang.Object key)
           
 java.awt.Font getFont(java.lang.String name, int type, int size)
           
static Utils getInstance()
           
static java.util.List getIntersectionWithCase(java.util.List a, java.util.List b)
          get unique intersection of two vectors, case sensitive for string
static java.util.List getIntersectionWithoutCase(java.util.List a, java.util.List b)
          get the intersection of two vectors, case insensitive
 java.lang.String getResource(java.lang.String key)
           
 java.util.Vector getResourceVector(java.lang.String key)
           
static java.lang.String getServer()
          get the web server and database server host
 java.util.Collection getSessionOrganism()
          get the organism that the curator can edit
 int getSessionUserLevel()
          current user level
 java.lang.String getSessionUsername()
          current user name
static java.util.List getUnionWithCase(java.util.List a, java.util.List b)
          get unique union of two vectors, case sensitive for strings
static java.util.List getUnionWithoutCase(java.util.List a, java.util.List b)
          get the union of two vectors, case insensitive
static java.util.List getUniqueWithCase(java.util.List a)
          get the unique element in a colleciton, case sensitive
static java.util.List getUniqueWithoutCase(java.util.List a)
          case insensitive, only used for String object, to return the unique element in a collection
static java.util.Map hashSet(java.util.Map map, java.lang.Object key, java.lang.Object value)
           
static java.lang.reflect.Method hasMethod(java.lang.Object object, java.lang.String methodName)
          detect if the method exists or not
static java.lang.String implode(java.lang.Object[] v, java.lang.String d)
           
static java.lang.String implode(java.lang.String[] v)
          join string from array
static java.lang.String implode(java.lang.String[] value, java.lang.String delim)
          join the string by delim
static boolean isFirstRunning()
          test if there is an instance of the application already
static boolean isValid(java.lang.String s)
           
static java.lang.String join(java.util.Collection collection)
          turn the vector of object to comma separate string, notice only applying for integer, not string, otherwise the string should contain the double quota already.
static java.lang.String join(java.util.Collection collection, java.lang.String delimit)
          turn the vector of object to comma separate string, notice only applying for integer, not string, otherwise the string should contain the double quota already.
 void loadResource()
           
static java.lang.String makeValid(java.lang.String s)
           
static int maxIndex(double[] a)
           
static int minIndex(double[] a)
           
static java.lang.String mysqlEscape(java.lang.String insertString)
           
static java.lang.String mysqlOldPassword(java.lang.String plainText)
          compute the old style encrypted mysql password from the plain text
 java.lang.String parseDouble(java.lang.String inputString, java.lang.String defaultValue)
           
static java.lang.String prepare(java.lang.String t, java.lang.String v)
           
static java.lang.String prepare(java.lang.String template, java.lang.String[] value)
          prepare the template with default mark as ?
static java.lang.String prepare(java.lang.String t, java.lang.String v1, java.lang.String v2)
           
static java.lang.String prepare(java.lang.String t, java.lang.String d, java.lang.String[] v)
          replace the mark in the template string
static java.lang.String prepare(java.lang.String t, java.lang.String v1, java.lang.String v2, java.lang.String v3)
           
static java.lang.String prepare(java.lang.String t, java.lang.String v1, java.lang.String v2, java.lang.String v3, java.lang.String v4)
           
static java.lang.String prepare(java.lang.String t, java.lang.String v1, java.lang.String v2, java.lang.String v3, java.lang.String v4, java.lang.String v5)
           
 void removeColumn(javax.swing.JTable tbl, int col)
          hidden the column from JTable such as serial number, if used on multiple columns, do from largest one
 java.awt.GridBagConstraints setConstraints(java.awt.GridBagConstraints layout, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty)
          set the value of the GridBagConstraints and reuse it
static java.lang.String splitEntity(java.lang.String entityName)
          to facility input, we use ,, to separate name and return in ()
static java.util.Vector splitEntityList(java.lang.String entityName)
           
static java.lang.Double string2Double(java.lang.String string)
          convert the string to double without throwing exception
static java.lang.Integer string2Integer(java.lang.String string)
          conver tth estring to integer without throwing exception
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger

utils

static Utils utils
the database statement instance


negativeSequence

static int negativeSequence
save the sequence


socket

static java.net.ServerSocket socket
socket for single instance testing

Method Detail

generateNegativeBasedUUID

public static final int generateNegativeBasedUUID()
get the next unique id for the null vertex


getInstance

public static Utils getInstance()

join

public static java.lang.String join(java.util.Collection collection)
turn the vector of object to comma separate string, notice only applying for integer, not string, otherwise the string should contain the double quota already. Do not contain any space to prevent ambiguous

Parameters:
collection - the collection of the objects
Returns:
the comma seaprated string

join

public static java.lang.String join(java.util.Collection collection,
                                    java.lang.String delimit)
turn the vector of object to comma separate string, notice only applying for integer, not string, otherwise the string should contain the double quota already. Do not contain any space to prevent ambiguous

Parameters:
collection - the collection of the objects
Returns:
the comma seaprated string

getIntersectionWithCase

public static java.util.List getIntersectionWithCase(java.util.List a,
                                                     java.util.List b)
get unique intersection of two vectors, case sensitive for string

Parameters:
a - first vector
b - second vector
Returns:
the intersction of two collections
See Also:
Set

hasMethod

public static java.lang.reflect.Method hasMethod(java.lang.Object object,
                                                 java.lang.String methodName)
detect if the method exists or not

Parameters:
object - the object
methodName - the name of the method
Returns:
the method or null if not exists

getIntersectionWithoutCase

public static java.util.List getIntersectionWithoutCase(java.util.List a,
                                                        java.util.List b)
get the intersection of two vectors, case insensitive

Parameters:
a - first vectot
b - second vector
Returns:
the intersection of two collections
See Also:
Set

getUnionWithCase

public static java.util.List getUnionWithCase(java.util.List a,
                                              java.util.List b)
get unique union of two vectors, case sensitive for strings

Parameters:
a - first vector
b - second vector
Returns:
union of two collections

getUnionWithoutCase

public static java.util.List getUnionWithoutCase(java.util.List a,
                                                 java.util.List b)
get the union of two vectors, case insensitive

Parameters:
a - first vector
b - second vector
Returns:
union of two collections
See Also:
Set

getDifferenceWithCase

public static java.util.List getDifferenceWithCase(java.util.List a,
                                                   java.util.List b)
get differnece a-b, case sensitive

Parameters:
a - first vector
b - second vector
Returns:
the collection in which the element only exosts in the first vector

getDifferenceWithoutCase

public static java.util.List getDifferenceWithoutCase(java.util.List a,
                                                      java.util.List b)
get the difference a-b, case insensitive

Parameters:
a - first vector
b - second vector
Returns:
collections in which the element only exosts in the first vector

getDifferenceXWithCase

public static java.util.List getDifferenceXWithCase(java.util.List a,
                                                    java.util.List b)
get differnece of (a-b) + (b-a), case sensitive

Parameters:
a - first vector
b - second vector
Returns:
collections in which the element only exists one of the two collections

getDifferenceXWithoutCase

public static java.util.List getDifferenceXWithoutCase(java.util.List a,
                                                       java.util.List b)
get the difference (a-b) + (b-a), case insensitive

Parameters:
a - first vector
b - second vector
Returns:
collections in which the element only exists in one of the two collections

setConstraints

public java.awt.GridBagConstraints setConstraints(java.awt.GridBagConstraints layout,
                                                  int gridx,
                                                  int gridy,
                                                  int gridwidth,
                                                  int gridheight,
                                                  double weightx,
                                                  double weighty)
set the value of the GridBagConstraints and reuse it

Parameters:
layout - the layout instance to be reused
gridx - x position in the container
gridy - y position in the container
gridwidth - span width of the control
gridheight - span height of the control
weightx - weight of x direction when the size is changed
weighty - weight of y direction when the size is changed
Returns:
the new instance of layout

getUniqueWithCase

public static java.util.List getUniqueWithCase(java.util.List a)
get the unique element in a colleciton, case sensitive

Parameters:
a - the collection
Returns:
the unique elements in the collection

getUniqueWithoutCase

public static java.util.List getUniqueWithoutCase(java.util.List a)
case insensitive, only used for String object, to return the unique element in a collection

Parameters:
a - the colleciton
Returns:
the unique element in the collection

removeColumn

public void removeColumn(javax.swing.JTable tbl,
                         int col)
hidden the column from JTable such as serial number, if used on multiple columns, do from largest one

Parameters:
tbl - the table need to hide one of the columns
col - the index of the column, zero based

getCurrentSQLDate

public static java.lang.String getCurrentSQLDate()
get current data with 'yyyy-mm-dd' format

Returns:
return the MySQL format of current date

getSessionUserLevel

public int getSessionUserLevel()
current user level

Returns:
current user level

getSessionUsername

public java.lang.String getSessionUsername()
current user name

Returns:
current user name

getSessionOrganism

public java.util.Collection getSessionOrganism()
get the organism that the curator can edit

Returns:
the session organism can be edit

applyTheme

public void applyTheme(java.lang.String themeName)
regardless the user options, always use the Eve's look and feel for MetNet tools.

Parameters:
themeName - never used but leave it for compatability

applyTheme2

public void applyTheme2(java.lang.String themeName)
apply the theme from the theme file based on metal theme


loadResource

public void loadResource()

getResource

public java.lang.String getResource(java.lang.String key)

getResourceVector

public java.util.Vector getResourceVector(java.lang.String key)

isValid

public static boolean isValid(java.lang.String s)

makeValid

public static java.lang.String makeValid(java.lang.String s)

parseDouble

public java.lang.String parseDouble(java.lang.String inputString,
                                    java.lang.String defaultValue)

getFirst

public static java.lang.Object getFirst(java.util.Map map,
                                        java.lang.Object key)

hashSet

public static java.util.Map hashSet(java.util.Map map,
                                    java.lang.Object key,
                                    java.lang.Object value)

prepare

public static java.lang.String prepare(java.lang.String t,
                                       java.lang.String d,
                                       java.lang.String[] v)
replace the mark in the template string

Parameters:
t - [in] the template
d - [in] the delim
v - [in] the value for the markers
Returns:
the string after the replacement

mysqlEscape

public static java.lang.String mysqlEscape(java.lang.String insertString)

escapeXML

public static java.lang.String escapeXML(java.lang.String input)
replace all sensitive chars to special XML strings

Parameters:
input - the input raw string
Returns:
the escaped string

splitEntity

public static java.lang.String splitEntity(java.lang.String entityName)
to facility input, we use ,, to separate name and return in ()

Parameters:
the - entity name list to be splited
Returns:
the splited entity name?

splitEntityList

public static java.util.Vector splitEntityList(java.lang.String entityName)

minIndex

public static int minIndex(double[] a)

maxIndex

public static int maxIndex(double[] a)

prepare

public static java.lang.String prepare(java.lang.String t,
                                       java.lang.String v1,
                                       java.lang.String v2,
                                       java.lang.String v3)

prepare

public static java.lang.String prepare(java.lang.String t,
                                       java.lang.String v1,
                                       java.lang.String v2,
                                       java.lang.String v3,
                                       java.lang.String v4)

prepare

public static java.lang.String prepare(java.lang.String t,
                                       java.lang.String v1,
                                       java.lang.String v2,
                                       java.lang.String v3,
                                       java.lang.String v4,
                                       java.lang.String v5)

prepare

public static java.lang.String prepare(java.lang.String t,
                                       java.lang.String v1,
                                       java.lang.String v2)

prepare

public static java.lang.String prepare(java.lang.String t,
                                       java.lang.String v)

prepare

public static java.lang.String prepare(java.lang.String template,
                                       java.lang.String[] value)
prepare the template with default mark as ?


explode

public static java.lang.String[] explode(java.lang.String template,
                                         java.lang.String delim)
similar to StringTokenize, split string by delim

Parameters:
template - [in] the template
delim - [in] the delim
Returns:
the splitted string array

implode

public static java.lang.String implode(java.lang.String[] value,
                                       java.lang.String delim)
join the string by delim

Parameters:
value - [in] the array of the string
delim - [in] delim used for joining
Returns:
the joined string

implode

public static java.lang.String implode(java.lang.Object[] v,
                                       java.lang.String d)

implode

public static java.lang.String implode(java.lang.String[] v)
join string from array

Parameters:
v - the strings to be joined
Returns:
the joined string

getDB

public static java.lang.String getDB()

getServer

public static java.lang.String getServer()
get the web server and database server host

Returns:
the server address

arrayToVector

public java.util.Vector arrayToVector(java.lang.Object[] arr)

getFont

public java.awt.Font getFont(java.lang.String name,
                             int type,
                             int size)

dummyLabel

public void dummyLabel(java.awt.Container panel,
                       int num_cols,
                       int num_rows)

string2Double

public static java.lang.Double string2Double(java.lang.String string)
convert the string to double without throwing exception

Parameters:
string - any string to be converted
Returns:
double object or null if invalid

string2Integer

public static java.lang.Integer string2Integer(java.lang.String string)
conver tth estring to integer without throwing exception

Parameters:
string - any string to be converted
Returns:
integer object or null if invalid

mysqlOldPassword

public static java.lang.String mysqlOldPassword(java.lang.String plainText)
compute the old style encrypted mysql password from the plain text

Parameters:
plainText - the plain style password
Returns:
the encrypted password by version prior 4.1

deepCopy

public static java.lang.Object deepCopy(java.lang.Object orig)
Returns a copy of the object, or null if the object cannot be serialized.

Parameters:
orig - original object
Returns:
the new object without same reference

generateGUID

public static final java.lang.String generateGUID(java.lang.Object o)
A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD NOT be seen by the user, not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs. Usage: Add an id field (type java.lang.String) to your EJB, and add setId(XXXUtil.generateGUID(this)); to the ejbCreate method.

Parameters:
o - the object instance
Returns:
the guid for the object

isFirstRunning

public static boolean isFirstRunning()
test if there is an instance of the application already