com.miginfocom.util
Class MigUtil

java.lang.Object
  extended by com.miginfocom.util.MigUtil

public class MigUtil
extends java.lang.Object

Generic utility class.


Field Summary
static int BIG_INT
          Use instead of Integer.MAX_VALUE to denote some generic big value.
static long BIG_LONG
          Use instead of Integer.MAX_VALUE to denote some generic big value.
static boolean DEBUG
           
static javax.swing.JFrame dFrame
           
static java.awt.Rectangle[] EMPTY_RECT_ARRAY
          Rectangle[0].
static boolean NEW_SIZE_CALCULATIONS
          Set this to false to get the row and activity size calculations that existed pre v6.5
static int SMALL_INT
          Use instead of Integer.MAX_VALUE to denote some generic small value.
static long SMALL_LONG
          Use instead of Integer.MAX_VALUE to denote some generic small value.
 
Constructor Summary
MigUtil()
           
 
Method Summary
static int[] addToArray(int[] source, int o, int index)
          Creates a new array, copy the source array but insets o at index.
static java.lang.Object[] addToArray(java.lang.Object[] source, java.lang.Object o, int index)
          Creates a new array, copy the source array but insets o at index.
static boolean canHandleThreads()
          Returns if there is enough permissions to start/stop threads.
Caches check so it will be really fast from 2:nd call..
static void checkComponentVersion(int version)
          Check for a certain version and throws a IllegalAccessException if the version is too small.
static void drawDebugRect(java.awt.Graphics2D g, java.awt.Shape s, java.awt.Color c)
          Draws a red rectanlge at the exact bounds
static boolean equals(java.lang.Object o1, java.lang.Object o2)
          Compares two objects for equality but in a safe way considering null values
static boolean equalsLenient(java.lang.Object o1, java.lang.Object o2)
          Compares two objects for equality but in a safe way considering null values.
static int findIndex(java.lang.Object[] a, java.lang.Object o, boolean ref)
          Returns the index if the element that equals or is same as o.
static java.lang.String[] flatten(java.lang.String[][] str)
          Flattens the two dimensional array into one with all possible combinations.
static java.lang.String getFirstUpperCase(java.lang.String s)
          Makes sure the first character is upper case.
static java.lang.String getSimpleClassName(java.lang.Class c)
          Returns the simple class name of the class without the package hierarchy.
static java.lang.String getStackTrace()
          Returns the stach trace for the current thread.
static java.lang.String getStackTrace(java.lang.Throwable t)
          Returns the stach trace for the current thread.
static boolean inCSString(java.lang.String str, java.lang.String csStr)
          Returns if a string is in a comma separaded string.
static java.lang.String intToString(int i, int numChars)
          Returns a string with at least length numChars by adding zeros before.
static boolean isAqua(java.lang.String atLeastVersion)
           
static boolean isAtLeastJRE6()
           
static boolean isSandbox()
          Returns is we are currently running in a sandbox by checking if we can read system properties.
Caches check so it will be really fast from 2:nd call..
static boolean isTrue(java.lang.Object o)
          Return true if v is a Boolean that is true OR a when converted to a String it equals (ignoring case) "true".
static void printToDebugDialog(java.lang.String s)
           
static java.lang.Object[] removeFromArray(java.lang.Object[] arr, int index)
          Creates a new array that is one lement shorer and doesn't have element at index.
static java.lang.Object[] removeFromArray(java.lang.Object[] arr, java.lang.Object o, boolean ref)
          Returns an array that is either new but same as arr with o removed or returns arr itself if o wasn't found.
static java.lang.Object[] removeNullArrayElements(java.lang.Object[] arr)
          Remove all null elements and return the cleaned array.
static void removeNullElements(java.util.List list)
          Remove all null elements from the list
static java.util.ArrayList removeNullElements(java.lang.Object[] arr)
          Remove all null elements and return the elements in a list
static int toBounds(int c, int min, int max)
          Returns a cell index within bounds.
static java.lang.String toCSString(java.lang.String[] strings)
          Returns a comma separated string.
static java.lang.String toCSString(java.lang.String[] strings, java.lang.String elementPrefix, java.lang.String elementSuffix)
          Returns a comma separated string.
static int[] toIntArray(java.lang.String s, char sep)
          Parses a string and returns it in those parts of the string that are separated with a sep converted to ints.
static java.lang.String[] toTokens(java.lang.String s, char sep)
          Parses a string and returns it in those parts of the string that are separated with a sep
static void TRACE(java.lang.String errorMsg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_SIZE_CALCULATIONS

public static boolean NEW_SIZE_CALCULATIONS
Set this to false to get the row and activity size calculations that existed pre v6.5


EMPTY_RECT_ARRAY

public static final java.awt.Rectangle[] EMPTY_RECT_ARRAY
Rectangle[0].


BIG_INT

public static final int BIG_INT
Use instead of Integer.MAX_VALUE to denote some generic big value. Not Integer.MAX_VALUE since it's so close to overflow to negative...

See Also:
Constant Field Values

SMALL_INT

public static final int SMALL_INT
Use instead of Integer.MAX_VALUE to denote some generic small value. Not Integer.MIN_VALUE since it's so close to overflow to negative...

See Also:
Constant Field Values

BIG_LONG

public static final long BIG_LONG
Use instead of Integer.MAX_VALUE to denote some generic big value. Not Integer.MAX_VALUE since it's so close to overflow to negative...

See Also:
Constant Field Values

SMALL_LONG

public static final long SMALL_LONG
Use instead of Integer.MAX_VALUE to denote some generic small value. Not Integer.MIN_VALUE since it's so close to overflow to negative...

See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

dFrame

public static javax.swing.JFrame dFrame
Constructor Detail

MigUtil

public MigUtil()
Method Detail

TRACE

public static void TRACE(java.lang.String errorMsg)

isAtLeastJRE6

public static boolean isAtLeastJRE6()

isAqua

public static boolean isAqua(java.lang.String atLeastVersion)

checkComponentVersion

public static void checkComponentVersion(int version)
Check for a certain version and throws a IllegalAccessException if the version is too small.

Parameters:
version - E.g. 600 for ver 6.0.0.

getFirstUpperCase

public static java.lang.String getFirstUpperCase(java.lang.String s)
Makes sure the first character is upper case.

Parameters:
s - The string. May be "" or null in which case they are returned unchanged.
Returns:
The string with the first char uppercase.

getStackTrace

public static java.lang.String getStackTrace()
Returns the stach trace for the current thread.

Returns:
The stack trace.

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)
Returns the stach trace for the current thread.

Returns:
The stack trace.

isSandbox

public static final boolean isSandbox()
Returns is we are currently running in a sandbox by checking if we can read system properties.
Caches check so it will be really fast from 2:nd call..

Returns:
true is sandbox.

canHandleThreads

public static final boolean canHandleThreads()
Returns if there is enough permissions to start/stop threads.
Caches check so it will be really fast from 2:nd call..

Returns:
true if allowed.

addToArray

public static final int[] addToArray(int[] source,
                                     int o,
                                     int index)
Creates a new array, copy the source array but insets o at index.

Optimized for smallish arrays (doesn't use System.arrayCopy().

Parameters:
source - The source array to copy. Not null.
o - The integer to insert. Might be null.
index - The index to insert o at. If larger than what fits in the new array it will be put last in it. A very big value can therefore be used to ensure it will be placed last.
Returns:
The newly created array.

addToArray

public static final java.lang.Object[] addToArray(java.lang.Object[] source,
                                                  java.lang.Object o,
                                                  int index)
Creates a new array, copy the source array but insets o at index.

Optimized for smallish arrays (doesn't use System.arrayCopy().

Parameters:
source - The source array to copy. Not null.
o - The object to insert. Might be null.
index - The index to insert o at. If larger than what fits in the new array it will be put last in it. A very big value can therefore be used to ensure it will be placed last.
Returns:
The newly created array.

removeFromArray

public static final java.lang.Object[] removeFromArray(java.lang.Object[] arr,
                                                       int index)
Creates a new array that is one lement shorer and doesn't have element at index.

Optimized for smallish arrays (doesn't use System.arrayCopy().

Parameters:
arr - The array to remove from and copy. Not null and length must be > 1.
index - The index of the element to remove. Must be a valid array index.
Returns:
The newly created array, excluding element at index.

removeFromArray

public static final java.lang.Object[] removeFromArray(java.lang.Object[] arr,
                                                       java.lang.Object o,
                                                       boolean ref)
Returns an array that is either new but same as arr with o removed or returns arr itself if o wasn't found.

Optimized for smallish arrays (doesn't use System.arrayCopy().

Parameters:
arr - The array to remove from and copy. Not null and length must be > 1.
o - The object to remove. Either by equals or the actual object.
ref - If true then == is used, otherquse .equals is used to check for equality.
Returns:
The newly created array, excluding element o. Returns arr if o couldn't be found.

findIndex

public static final int findIndex(java.lang.Object[] a,
                                  java.lang.Object o,
                                  boolean ref)
Returns the index if the element that equals or is same as o.

Parameters:
a - The array to check. Not null.
o - The object to check for. May be null. null == null and null equals null.
ref - If true then == is used, otherquse .equals is used to check for equality.
Returns:
If o is in, or equals, any element in the array that index is returned.

intToString

public static final java.lang.String intToString(int i,
                                                 int numChars)
Returns a string with at least length numChars by adding zeros before. e.g. toString(1, 3) returns "001" e.g.. toString(1234, 2) returns "1234"

Parameters:
i - The integer to return as a string
numChars - The least number of chars to return. Max 20.

flatten

public static final java.lang.String[] flatten(java.lang.String[][] str)
Flattens the two dimensional array into one with all possible combinations.
 Example:
 str = new String[][] {       // Internal arrays explanation:
        {"1", "2"},                 // ix[0] => 0, 1
        {"3", "4", "5"},            // ix[1] => 0, 1, 2, 0, 1, 2
        {"6", "7"}                  // ix[2] => 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
 };
  
Becomes: {"136", "137, "146, "147, "156, "257, "236", "237, "246, "247, "256, "257"}

Parameters:
str - The two dimentsional array. All arrays must be of length %gt 0!!.
Returns:
A flttened arrays with all concatenated string combinations

isTrue

public static final boolean isTrue(java.lang.Object o)
Return true if v is a Boolean that is true OR a when converted to a String it equals (ignoring case) "true".

Parameters:
o - The value to check if it if "true". null returns false.
Returns:
true or false...

toTokens

public static final java.lang.String[] toTokens(java.lang.String s,
                                                char sep)
Parses a string and returns it in those parts of the string that are separated with a sep

Parameters:
s - The string to parse. If it starts and/or ends with a sep the first and/or last element returned will be "". If two sep are next to eachother and empty element will be "between" the periods. The sep themselves will never be returned.
Returns:
Those parts of the string that are separated with sep. Never null and at least of size 1

toIntArray

public static final int[] toIntArray(java.lang.String s,
                                     char sep)
Parses a string and returns it in those parts of the string that are separated with a sep converted to ints.

Parameters:
s - The string to parse. all sep must be surrounded by integer strings. They do not need to be trimmed though, that will be done for each token.
Returns:
The integers in the spearated string. null if there was a parsing error or the string was empty.

toCSString

public static java.lang.String toCSString(java.lang.String[] strings)
Returns a comma separated string.

Parameters:
strings - The strings. null elements will be ignored. If null "" is returned
Returns:
E.g, "string1,string2"

toCSString

public static java.lang.String toCSString(java.lang.String[] strings,
                                          java.lang.String elementPrefix,
                                          java.lang.String elementSuffix)
Returns a comma separated string.

Parameters:
strings - The strings. null elements will be ignored. If null "" is returned
elementPrefix - Will be added first to every element. For instance \". null means no prefix.
elementSuffix - Will be added last to every element. For instance \" null means no suffix.
Returns:
E.g, "string1,string2"

getSimpleClassName

public static java.lang.String getSimpleClassName(java.lang.Class c)
Returns the simple class name of the class without the package hierarchy.

Parameters:
c - The class to return the name for. Not null.
Returns:
The simple class name of the class without the package hierarchy.

equals

public static final boolean equals(java.lang.Object o1,
                                   java.lang.Object o2)
Compares two objects for equality but in a safe way considering null values

Parameters:
o1 - the first object
o2 - the second object
Returns:
true if o1.equals(o2) or the obects are equals (==). null == null !

equalsLenient

public static final boolean equalsLenient(java.lang.Object o1,
                                          java.lang.Object o2)
Compares two objects for equality but in a safe way considering null values. Does the comparison in a lenient way so that:
null equals: null, "null", "false", "" and "0" using the .toString() method.

Parameters:
o1 - the first object
o2 - the second object
Returns:
true if o1.equals(o2) or the obects are equals (==). null == null !

inCSString

public static final boolean inCSString(java.lang.String str,
                                       java.lang.String csStr)
Returns if a string is in a comma separaded string.

Parameters:
str - The string to search for. Not null but can be empty. Must not contain commas.
csStr - A string with possibly comma separated sub-strings. Not null.
Returns:
If str is within csStr

toBounds

public static final int toBounds(int c,
                                 int min,
                                 int max)
Returns a cell index within bounds.

Parameters:
c - the cell that may be outside the bounds
min - The minimm value of c;
max - The maximum value of c;
Returns:
c but now less than min or more than max.

removeNullElements

public static final void removeNullElements(java.util.List list)
Remove all null elements from the list

Parameters:
list - The array that might contain null elements.

removeNullElements

public static final java.util.ArrayList removeNullElements(java.lang.Object[] arr)
Remove all null elements and return the elements in a list

Parameters:
arr - The array that might contain null elements.
Returns:
A list that contains all elements that is not null. Never null.

removeNullArrayElements

public static final java.lang.Object[] removeNullArrayElements(java.lang.Object[] arr)
Remove all null elements and return the cleaned array. If the arrays does not have null elements the original array will be returned. reflection is used to return an array of the corrent type.

Parameters:
arr - The array that might contain null elements.
Returns:
An arra that contains all elements that is not null. Never null. Might be arr.

drawDebugRect

public static final void drawDebugRect(java.awt.Graphics2D g,
                                       java.awt.Shape s,
                                       java.awt.Color c)
Draws a red rectanlge at the exact bounds


printToDebugDialog

public static void printToDebugDialog(java.lang.String s)


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.