Package org.pathvisio.libgpml.util
Class Utils
java.lang.Object
org.pathvisio.libgpml.util.Utils
public class Utils
extends java.lang.Object
Various utility functions.
- Author:
- unknown
-
Field Summary
Fields Modifier and Type Field Description static int
OS_LINUX
static int
OS_MAC
static int
OS_UNSUPPORTED
static int
OS_WINDOWS
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
Modifier and Type Method Description static java.lang.String
collection2String(java.util.Collection<?> list, java.lang.String quote, java.lang.String sep)
Converts a list to a string.static boolean
containsCaseInsensitive(java.lang.String str, java.util.List<java.lang.String> strList)
Case insensitive contains method for List.static java.lang.String
encodeFont(java.awt.Font f)
Encodes a font to a string that can be converted back into a font object using Font.decode(String)static java.lang.String
formatExceptionMsg(java.lang.String msg)
Formats a message that will be displayed in a dialog, so it's not longer than 80 symbols in each linestatic int
getDirectionX(java.awt.geom.Point2D start, java.awt.geom.Point2D end)
Get the direction of the line on the x axisstatic int
getDirectionY(java.awt.geom.Point2D start, java.awt.geom.Point2D end)
Get the direction of the line on the y axisstatic int
getOS()
Returns the OS.static boolean
isEmpty(java.lang.String str)
Returns true if string is empty or null.static java.lang.String
join(java.lang.String sep, java.util.Collection<?> values)
Joins collection into a single string, with a separator between.static <U, V> void
multimapPut(java.util.Map<U,java.util.Set<V>> map, U key, V val)
For safely adding a value to a multimap (i.e.static <U, V> java.util.Set<V>
multimapValues(java.util.Map<U,java.util.Set<V>> map)
Returns a set of all unique values of a multimap (i.e.static <T> T
oneOf(java.util.Set<T> set)
Useful if you want to use one item from a set, and you don't care which one.static void
printx(java.io.PrintStream out, java.lang.String indent, java.lang.Object o)
Helper function to print the contents of maps or collections, or maps of maps, collections of maps, collections of collections etc.static <T> java.util.Set<T>
setOf(T val)
Creates a new Set of the given value(s)static boolean
stringEquals(java.lang.String str1, java.lang.String str2)
Compares two Strings, returningtrue
if they are equal.static boolean
stringNullEqualsEmpty(java.lang.String str1, java.lang.String str2)
Compares two Strings, returningtrue
if they are equal.static java.io.InputStream
stringToInputStream(java.lang.String str)
Converts a string to input stream.static java.lang.String
summary(PathwayObject elt)
Returns string summary information for a pathway object.private static void
summaryHelper(PathwayObject elt, java.lang.StringBuilder result, StaticProperty p, java.lang.String shortHand)
append a property to the summaryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
OS_UNSUPPORTED
public static final int OS_UNSUPPORTED- See Also:
- Constant Field Values
-
OS_WINDOWS
public static final int OS_WINDOWS- See Also:
- Constant Field Values
-
OS_LINUX
public static final int OS_LINUX- See Also:
- Constant Field Values
-
OS_MAC
public static final int OS_MAC- See Also:
- Constant Field Values
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
containsCaseInsensitive
public static boolean containsCaseInsensitive(java.lang.String str, java.util.List<java.lang.String> strList)Case insensitive contains method for List.- Parameters:
str
- the string.strList
- the string list.- Returns:
- true if string list contains given string regardless of case.
-
stringEquals
public static boolean stringEquals(java.lang.String str1, java.lang.String str2)Compares two Strings, returningtrue
if they are equal.- Parameters:
str1
- the first String, may be nullstr2
- the second String, may be null- Returns:
true
if the Strings are equal, case sensitive, or bothnull
- See Also:
String.equals(Object)
-
stringNullEqualsEmpty
public static boolean stringNullEqualsEmpty(java.lang.String str1, java.lang.String str2)Compares two Strings, returningtrue
if they are equal. In this case, null is considered equal to Empty.- Parameters:
str1
- the first String, may be null or emptystr2
- the second String, may be null or empty- Returns:
true
if the Strings are equal, case sensitive, or bothnull
or empty- See Also:
String.equals(Object)
-
isEmpty
public static boolean isEmpty(java.lang.String str)Returns true if string is empty or null.- Parameters:
str
- the string.- Returns:
- true if string is empty or null.
-
getDirectionX
public static int getDirectionX(java.awt.geom.Point2D start, java.awt.geom.Point2D end)Get the direction of the line on the x axis- Parameters:
start
- The start point of the lineend
- The end point of the line- Returns:
- 1 if the direction is positive (from left to right), -1 if the direction is negative (from right to left)
-
getDirectionY
public static int getDirectionY(java.awt.geom.Point2D start, java.awt.geom.Point2D end)Get the direction of the line on the y axis- Parameters:
start
- The start point of the lineend
- The end point of the line- Returns:
- 1 if the direction is positive (from top to bottom), -1 if the direction is negative (from bottom to top)
-
getOS
public static int getOS()Returns the OS.- Returns:
- the OS.
-
oneOf
public static <T> T oneOf(java.util.Set<T> set)Useful if you want to use one item from a set, and you don't care which one.- Parameters:
set
- a set that you want one element out of- Returns:
- null if the set is empty or null, or an element from the set otherwise.
-
setOf
public static <T> java.util.Set<T> setOf(T val)Creates a new Set of the given value(s) -
multimapPut
public static <U, V> void multimapPut(java.util.Map<U,java.util.Set<V>> map, U key, V val)For safely adding a value to a multimap (i.e. a map of sets). -
multimapValues
public static <U, V> java.util.Set<V> multimapValues(java.util.Map<U,java.util.Set<V>> map)Returns a set of all unique values of a multimap (i.e. a map of sets). -
formatExceptionMsg
public static java.lang.String formatExceptionMsg(java.lang.String msg)Formats a message that will be displayed in a dialog, so it's not longer than 80 symbols in each line- Parameters:
msg
- the message to format.
-
summaryHelper
private static void summaryHelper(PathwayObject elt, java.lang.StringBuilder result, StaticProperty p, java.lang.String shortHand)append a property to the summary -
summary
Returns string summary information for a pathway object. TODO- Parameters:
elt
-- Returns:
-
join
public static java.lang.String join(java.lang.String sep, java.util.Collection<?> values)Joins collection into a single string, with a separator between.- Parameters:
sep
-values
-- Returns:
-
collection2String
public static java.lang.String collection2String(java.util.Collection<?> list, java.lang.String quote, java.lang.String sep)Converts a list to a string.- Parameters:
list
- the list to convert to a stringquote
- a quote character to usesep
- the separator to use- Returns:
- a String representing the list with given seperator and quote (no parentheses)
-
stringToInputStream
public static java.io.InputStream stringToInputStream(java.lang.String str)Converts a string to input stream.- Parameters:
str
- the string.- Returns:
-
encodeFont
public static java.lang.String encodeFont(java.awt.Font f)Encodes a font to a string that can be converted back into a font object using Font.decode(String)- Parameters:
f
- the font.
-
printx
public static void printx(java.io.PrintStream out, java.lang.String indent, java.lang.Object o)Helper function to print the contents of maps or collections, or maps of maps, collections of maps, collections of collections etc. Useful for debugging. Similar in idea to the perl Data::Dumper module- Parameters:
indent
- is for recursive use, e.g. to prefix each line with "\t"
-