gr.demokritos.iit.jinsect
Class utils

java.lang.Object
  extended by gr.demokritos.iit.jinsect.utils

public final class utils
extends java.lang.Object

A class including a set of useful, general purpose functions.


Constructor Summary
utils()
           
 
Method Summary
static double abs(double dNum)
          Math.abs reimplemented.
static void bubbleSortArray(java.lang.Comparable[] aArr)
          Bubble-sorts an array of comparable items.
static java.util.List bubbleSortVerticesByStringLength(java.util.List l)
          Bubble sorts the strings in a given String list, where the longest string is the first checked.
static double factorial(int n)
          Returns the factorial
static double factorial(int m, int n)
          Returns the factorial
static Union getCombinationsBy(java.lang.Object oObj, int iBySize)
          Creates a Union of combinations of elements taken from a given list for a given number of elements per combined set.
static int getConstructor(java.lang.String sClassName, int iParams)
          Returns the index of the constructor of a class, given its parameter count.
static java.lang.String getFilenameOnly(java.lang.String sFilepath)
          Returns the portion of filename after the last directory separator.
 double getHistogramTotal(java.util.HashMap hHist)
           
static java.util.List getIncomingEdges(Graph gGraph, salvo.jesus.graph.Vertex vTail)
          Gets the incoming edges to a given vertex in a directed graph.
static java.util.List getOutgoingEdges(Graph gGraph, salvo.jesus.graph.Vertex vHead)
          Gets the outgoing edges of a given vertex in a directed graph.
static Union getSubStrings(java.lang.String sStr, int iMaxSubStringSize, IMatching isMatcher)
          Calculates the substrings matching particular requirements in a given string, given a maximum substring size.
static Union getSubStrings(java.lang.String sStr, int iMaxSubStringSize, IMatching isMatcher, int iMaxDepth)
          Calculates the substrings matching particular requirements in a given string, given a maximum substring size.
static Union getSubStrings(java.lang.String sStr, int iMaxSubStringSize, IMatching isMatcher, int iMaxDepth, int iCurDepth)
          Helper function.
static java.lang.String getSwitch(java.util.Hashtable hSwitches, java.lang.String sOption, java.lang.String sDefault)
          Given a Hashtable and a given option string, this function returns either the option set in the hashtable, or a given default if the option has not been set.
static java.lang.String getSystemEncoding()
          Returns the system encoding String.
static java.lang.String graphToDot(Graph gTree, boolean bDirected)
          Renders a graph to its DOT representation (See GraphViz for more info on the format).
static java.lang.String graphToDot(Graph gTree, boolean bDirected, java.util.Map hEdgeDistros)
          Renders a graph to its DOT representation (See GraphViz for more info on the format).
static java.lang.String loadFileToString(java.lang.String sFilename)
           
static java.lang.String loadFileToStringWithNewlines(java.lang.String sFilename)
           
static salvo.jesus.graph.Edge locateDirectedEdgeInGraph(Graph gGraph, salvo.jesus.graph.Vertex vHead, salvo.jesus.graph.Vertex vTail)
          Looks up a given directed edge in a selected graph.
static salvo.jesus.graph.Edge locateEdgeInGraph(Graph gGraph, java.lang.String sHead, java.lang.String sTail)
          Looks up a given (undirected) edge in a selected graph.
static salvo.jesus.graph.Edge locateEdgeInGraph(Graph gGraph, salvo.jesus.graph.Vertex vHead, salvo.jesus.graph.Vertex vTail)
          Looks up a given (undirected) edge in a selected graph.
static salvo.jesus.graph.Vertex locateVertexInGraph(Graph gGraph, java.lang.String sToFind)
          Looks up a vertex, based on its label, within a given graph.
static salvo.jesus.graph.Vertex locateVertexInGraph(Graph gGraph, salvo.jesus.graph.Vertex vToFind)
          Looks up a vertex in a given graph.
static double logX(double dNumber, double dBase)
          Calculates the logarithm of a number using a given base.
static void main(java.lang.String[] args)
          Testbench function.
static double max(double Num1, double Num2)
          Math.max reimplemented.
static java.lang.String millisToMinSecString(long lMillis)
          Converts milliseconds to a string representation of x hours, y min, z sec.
static double min(double Num1, double Num2)
          Math.min reimplemented.
static java.util.Hashtable parseCommandLineSwitches(java.lang.String[] sCommands)
          Parses the command line expecting values of either `-switch` or `-key=value` and returns corresponding Hashtable, with switches as keys and `TRUE` as value, or `key` as keys and `value` as values
static java.lang.String printList(java.util.List lToPrint)
          Creates a formatted string representation of a (possibly nested) list, taking into account Union and Concatenation objects.
static java.lang.String printList(java.util.List lToPrint, java.lang.String sSeparator)
          Creates a formatted string representation of a (possibly nested) list, taking into account Union and Concatenation objects and using a given separator.
static java.lang.String repeatString(java.lang.String sStr, int iTimes)
          Repeats a given string a specified number of times.
static java.util.List reverseList(java.util.List l)
          Returns a reversed (by means of item index) version of a given list.
static void shuffleList(java.util.List l)
          Randomizes the order of items in a given list.
static double sign(double dNum)
          The sign function.
static java.lang.String[] splitToWords(java.lang.String sStr)
          Splits a given string to its words, without stemming.
static java.lang.String[] splitToWords(java.lang.String sStr, boolean bStem)
          Splits a given string to its words, without stemming.
static int sumFromTo(int iStart, int iEnd)
          Returns the sum of a sequence of numbers in a specified range
static java.lang.String toUTF8(java.lang.String sStr)
          Converts a string to UTF-8 encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

utils

public utils()
Method Detail

max

public static final double max(double Num1,
                               double Num2)
Math.max reimplemented.


min

public static final double min(double Num1,
                               double Num2)
Math.min reimplemented.


abs

public static final double abs(double dNum)
Math.abs reimplemented.


locateEdgeInGraph

public static final salvo.jesus.graph.Edge locateEdgeInGraph(Graph gGraph,
                                                             java.lang.String sHead,
                                                             java.lang.String sTail)
Looks up a given (undirected) edge in a selected graph. The edge is described based on the label of its vertices.

Parameters:
gGraph - The graph to use.
sHead - The label of the head or tail vertex of the edge.
sTail - The label of the tail or tail vertex of the edge.
Returns:
The edge, if found, otherwise null.

locateVertexInGraph

public static final salvo.jesus.graph.Vertex locateVertexInGraph(Graph gGraph,
                                                                 java.lang.String sToFind)
Looks up a vertex, based on its label, within a given graph.

Parameters:
gGraph - The graph to use.
sToFind - The label of the desired vertex.
Returns:
The vertex, if found, otherwise null.

locateVertexInGraph

public static final salvo.jesus.graph.Vertex locateVertexInGraph(Graph gGraph,
                                                                 salvo.jesus.graph.Vertex vToFind)
Looks up a vertex in a given graph.

Parameters:
gGraph - The graph to use.
vToFind - The vertex to locate.
Returns:
The vertex, if found, otherwise null.

locateEdgeInGraph

public static final salvo.jesus.graph.Edge locateEdgeInGraph(Graph gGraph,
                                                             salvo.jesus.graph.Vertex vHead,
                                                             salvo.jesus.graph.Vertex vTail)
Looks up a given (undirected) edge in a selected graph. The edge is described based on the label of its vertices.

Parameters:
gGraph - The graph to use.
vHead - A vertex with the desired label for the head or tail of the edge.
vTail - A vertex with the desired label for the tail or tail of the edge.
Returns:
The edge, if found, otherwise null.

locateDirectedEdgeInGraph

public static final salvo.jesus.graph.Edge locateDirectedEdgeInGraph(Graph gGraph,
                                                                     salvo.jesus.graph.Vertex vHead,
                                                                     salvo.jesus.graph.Vertex vTail)
Looks up a given directed edge in a selected graph. The edge is described based on the label of its vertices.

Parameters:
gGraph - The graph to use.
vHead - A vertex with the desired label for the head of the edge.
vTail - A vertex with the desired label for the tail of the edge.
Returns:
The edge, if found, otherwise null.

getOutgoingEdges

public static final java.util.List getOutgoingEdges(Graph gGraph,
                                                    salvo.jesus.graph.Vertex vHead)
Gets the outgoing edges of a given vertex in a directed graph.

Parameters:
gGraph - The graph to use.
vHead - A vertex with the desired label for the head of the edge.
Returns:
A list of outgoing edges from vHead. If no such edges exist returns an empty list.

getIncomingEdges

public static final java.util.List getIncomingEdges(Graph gGraph,
                                                    salvo.jesus.graph.Vertex vTail)
Gets the incoming edges to a given vertex in a directed graph.

Parameters:
gGraph - The graph to use.
vTail - A vertex with the desired label for the tail of the edge.
Returns:
A list of incoming edges to vTail. If no such edges exist returns an empty list.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Testbench function. Not to be used.

Throws:
java.lang.Exception

millisToMinSecString

public static final java.lang.String millisToMinSecString(long lMillis)
Converts milliseconds to a string representation of x hours, y min, z sec.

Parameters:
lMillis - The long number of milliseconds.
Returns:
The formated string.

shuffleList

public static final void shuffleList(java.util.List l)
Randomizes the order of items in a given list.

Parameters:
l - The input list that will be modified.

splitToWords

public static final java.lang.String[] splitToWords(java.lang.String sStr)
Splits a given string to its words, without stemming. Words are considered to be everything, but sequences of whitespace and punctuation.

Parameters:
sStr - The input string.
Returns:
An array of String containing the words of the given string.

splitToWords

public static final java.lang.String[] splitToWords(java.lang.String sStr,
                                                    boolean bStem)
Splits a given string to its words, without stemming. Words are considered to be everything, but sequences of whitespace and punctuation.

Parameters:
sStr - The input string.
bStem - True if stemming should be performed to the input words, otherwise false.
Returns:
An array of String containing the (possibly stemmed) words of the given string.

logX

public static final double logX(double dNumber,
                                double dBase)
Calculates the logarithm of a number using a given base.

Parameters:
dNumber - The number whose logarithm is meant to be calculated.
dBase - The base of the logarithm.
Returns:
The logarithm base dBase of dNumber.

printList

public static final java.lang.String printList(java.util.List lToPrint,
                                               java.lang.String sSeparator)
Creates a formatted string representation of a (possibly nested) list, taking into account Union and Concatenation objects and using a given separator.

Parameters:
lToPrint - The (possibly nested) list.
sSeparator - The separator to use for elements of the same level.
Returns:
The string representation of the (possibly nested) list.

printList

public static final java.lang.String printList(java.util.List lToPrint)
Creates a formatted string representation of a (possibly nested) list, taking into account Union and Concatenation objects.

Parameters:
lToPrint - The (possibly nested) list.
Returns:
The string representation of the (possibly nested) list.

getCombinationsBy

public static final Union getCombinationsBy(java.lang.Object oObj,
                                            int iBySize)
Creates a Union of combinations of elements taken from a given list for a given number of elements per combined set.

Parameters:
oObj - The input list.
iBySize - The size of elements to use in every combination returned.
Returns:
The Union of combination alternatives.

getSubStrings

public static final Union getSubStrings(java.lang.String sStr,
                                        int iMaxSubStringSize,
                                        IMatching isMatcher)
Calculates the substrings matching particular requirements in a given string, given a maximum substring size. If a string of a particular size is not matched, then it is broken into its substrings, which in turn are attempted to be matched. Every matched substring is not analysed further.

Parameters:
sStr - The input string.
iMaxSubStringSize - The maximum substring size to take into account.
isMatcher - A matcher of type IMatching to use, in order to take into account a given substring or not.
Returns:
A Union of the matched substrings within the given string.

getSubStrings

public static final Union getSubStrings(java.lang.String sStr,
                                        int iMaxSubStringSize,
                                        IMatching isMatcher,
                                        int iMaxDepth)
Calculates the substrings matching particular requirements in a given string, given a maximum substring size. If a string of a particular size is not matched, then it is broken into its substrings, which in turn are attempted to be matched. Every matched substring is not analysed further. The string will also not be analyzed further from a given depth of analysis (break-downs).

Parameters:
sStr - The input string.
iMaxSubStringSize - The maximum substring size to take into account.
isMatcher - A matcher of type IMatching to use, in order to take into account a given substring or not.
iMaxDepth - The maximum depth of analysis to use for the substring analysis.
Returns:
A Union of the matched substrings within the given string.

getSubStrings

public static final Union getSubStrings(java.lang.String sStr,
                                        int iMaxSubStringSize,
                                        IMatching isMatcher,
                                        int iMaxDepth,
                                        int iCurDepth)
Helper function. Calculates the substrings matching particular requirements in a given string, given a maximum substring size. If a string of a particular size is not matched, then it is broken into its substrings, which in turn are attempted to be matched. Every matched substring is not analysed further. The string will also not be analyzed further from a given depth of analysis (break-downs).

Parameters:
sStr - The input string.
iMaxSubStringSize - The maximum substring size to take into account.
isMatcher - A matcher of type IMatching to use, in order to take into account a given substring or not.
iMaxDepth - The maximum depth of analysis to use for the substring analysis.
iCurDepth - The current reached depth.
Returns:
A Union of the matched substrings within the given string.

getSystemEncoding

public static java.lang.String getSystemEncoding()
Returns the system encoding String.

Returns:
A String indicating the System default encoding.

toUTF8

public static java.lang.String toUTF8(java.lang.String sStr)
Converts a string to UTF-8 encoding.

Parameters:
sStr - The input string.
Returns:
A UTF-8 encoded version of the input string.

sign

public static double sign(double dNum)
The sign function.

Parameters:
dNum - The input number.
Returns:
1 if the input number is positive, -1 if negative and zero otherwise.

bubbleSortArray

public static final void bubbleSortArray(java.lang.Comparable[] aArr)
Bubble-sorts an array of comparable items.

Parameters:
aArr - An array of Comparable objects.

bubbleSortVerticesByStringLength

public static final java.util.List bubbleSortVerticesByStringLength(java.util.List l)
Bubble sorts the strings in a given String list, where the longest string is the first checked.

Parameters:
l - The input list.
Returns:
The sorted list.

parseCommandLineSwitches

public static java.util.Hashtable parseCommandLineSwitches(java.lang.String[] sCommands)
Parses the command line expecting values of either `-switch` or `-key=value` and returns corresponding Hashtable, with switches as keys and `TRUE` as value, or `key` as keys and `value` as values

Parameters:
sCommands - The command line array of Strings.
Returns:
The described hashtable.

getSwitch

public static java.lang.String getSwitch(java.util.Hashtable hSwitches,
                                         java.lang.String sOption,
                                         java.lang.String sDefault)
Given a Hashtable and a given option string, this function returns either the option set in the hashtable, or a given default if the option has not been set.

Parameters:
hSwitches - The hashtable of switches (see also parseCommandLineSwitches).
sOption - The name of the option of interest.
sDefault - The default value to be used if the option has not been set.
Returns:
The value of the switch, or the default value if no value has been set.

sumFromTo

public static int sumFromTo(int iStart,
                            int iEnd)
Returns the sum of a sequence of numbers in a specified range

Parameters:
iStart - The minimum term of the sequence
iEnd - The maximum term of the sequence

getHistogramTotal

public double getHistogramTotal(java.util.HashMap hHist)

graphToDot

public static java.lang.String graphToDot(Graph gTree,
                                          boolean bDirected)
Renders a graph to its DOT representation (See GraphViz for more info on the format).

Parameters:
gTree - The input graph.
bDirected - Indicate whether the graph should be described as a directed graph or not.
Returns:
The DOT formatted string representation of the graph.

graphToDot

public static java.lang.String graphToDot(Graph gTree,
                                          boolean bDirected,
                                          java.util.Map hEdgeDistros)
Renders a graph to its DOT representation (See GraphViz for more info on the format).

Parameters:
gTree - The input graph.
bDirected - Indicate whether the graph should be described as a directed graph or not.
hEdgeDistros - The map between edges and their distributions
Returns:
The DOT formatted string representation of the graph.

loadFileToString

public static java.lang.String loadFileToString(java.lang.String sFilename)

loadFileToStringWithNewlines

public static java.lang.String loadFileToStringWithNewlines(java.lang.String sFilename)

repeatString

public static final java.lang.String repeatString(java.lang.String sStr,
                                                  int iTimes)
Repeats a given string a specified number of times.

Parameters:
sStr - The string to repeat.
iTimes - The times to repeat the string.
Returns:
A string containing the given string concatenated the specified number of times.

factorial

public static final double factorial(int n)
Returns the factorial
1*2*...*(n-1)*n
.

Parameters:
n - The highest number of the factorial.
Returns:
The factorial.

factorial

public static final double factorial(int m,
                                     int n)
Returns the factorial
m*(m+1)*...*(n-1)*n
.

Parameters:
m - The lowest number of the factorial.
n - The highest number of the factorial.
Returns:
The factorial.

reverseList

public static java.util.List reverseList(java.util.List l)
Returns a reversed (by means of item index) version of a given list.

Parameters:
l - The list to reverse.
Returns:
The reversed list.

getFilenameOnly

public static final java.lang.String getFilenameOnly(java.lang.String sFilepath)
Returns the portion of filename after the last directory separator. If there is no file name there, an empty string is returned.

Parameters:
sFilepath - The path to the file.
Returns:
The filename stripped of directories.

getConstructor

public static final int getConstructor(java.lang.String sClassName,
                                       int iParams)
Returns the index of the constructor of a class, given its parameter count.

Parameters:
sClassName - The class name of interest.
iParams - The parameter count to look for.
Returns:
The index of the constructor in the Class.forName(sClassName).getConstructors() array.