org.ourgrid.common.util
Class StringUtil

java.lang.Object
  extended by org.ourgrid.common.util.StringUtil

public class StringUtil
extends java.lang.Object

This is a auxiliar class that incloses many util functionalities related to strings.


Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String fillWithChars(java.lang.String value, char character, int numChars)
          This method fills value with the characters at right.
static java.lang.String[] getArrayOfStrings(java.lang.String string, java.lang.String delimitator)
          Gets a array of strings after broken with the given delimitator
static java.lang.String getStringSeparatedByCommas(java.lang.String[] strings)
          Gets a array of string and return a string that contains the strings separated by commas
static java.lang.String insertSpace(java.lang.String expr, int i)
          Inserts a white space at a specific point.
static java.lang.String insertSpaces(java.lang.String expr)
          Insert spaces in the sentence expr.
static int parsePermissionString(java.lang.String permStr)
          This method parse a permissions file from stringo to int
static java.lang.String[] passToArrayStr(java.lang.String strToArray)
          Receives a simple String and returns a array containing all words of the String supressed the "," - it is the delimiter
static java.lang.String passToString(java.lang.String[] orig)
          Receives an array of String and returns a simple string of all separeted by a ","
static java.lang.String replace(java.lang.String str, java.lang.String subOld, java.lang.String subNew)
          Replaces at the a String a patter to another.
static java.lang.String replaceVariables(java.lang.String stringWithVariables, java.util.Map<java.lang.String,java.lang.String> envVars)
          This method does a job that is expected to be done by the shell: it converts variables to String literals.
static void writeStringOnFile(java.lang.String file, java.lang.String s)
          Writes the given string into the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

writeStringOnFile

public static void writeStringOnFile(java.lang.String file,
                                     java.lang.String s)
                              throws java.io.IOException
Writes the given string into the given file.

Parameters:
file - The file where the string have to be written (appended).
s - the string to be written into the file
Throws:
java.io.IOException - If the file could not be used (created) or any other I/O problem at the open, writte or close moment.

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String subOld,
                                       java.lang.String subNew)
Replaces at the a String a patter to another.

Parameters:
str - The String where will be made the changes.
subOld - The pattern that will be removed.
subNew - The pattern that will be inserted.
Returns:
the new string with the changes made if any was necessary, or the same string if any changes was needed.

passToString

public static java.lang.String passToString(java.lang.String[] orig)
Receives an array of String and returns a simple string of all separeted by a ","


passToArrayStr

public static java.lang.String[] passToArrayStr(java.lang.String strToArray)
Receives a simple String and returns a array containing all words of the String supressed the "," - it is the delimiter

Parameters:
strToArray - string that must be transformed to an array.
Returns:
an array of strings based on the string parameter.

insertSpace

public static java.lang.String insertSpace(java.lang.String expr,
                                           int i)
Inserts a white space at a specific point.

Parameters:
expr - the string where the space have to be inserted.
i - the specific point where the space have to be inserted
Returns:
the changed string if the position is valid or the same string otherwise.

fillWithChars

public static java.lang.String fillWithChars(java.lang.String value,
                                             char character,
                                             int numChars)
This method fills value with the characters at right.

Parameters:
value - - The string to be filled with white space caracters
character - - The character to be used in the filling of the string
numChars - - The number of characters to insert in the string.

insertSpaces

public static java.lang.String insertSpaces(java.lang.String expr)
Insert spaces in the sentence expr. This is necessary in order to StringTokenizer can function properlly when matching sentence of the task.

Parameters:
expr - The sentence that spaces will be inserted
Returns:
The modified sentence (with spaces)

replaceVariables

public static java.lang.String replaceVariables(java.lang.String stringWithVariables,
                                                java.util.Map<java.lang.String,java.lang.String> envVars)
This method does a job that is expected to be done by the shell: it converts variables to String literals.

Parameters:
stringWithVariables - A string with 0 or more variables.
Returns:
A String without any variables.

parsePermissionString

public static int parsePermissionString(java.lang.String permStr)
This method parse a permissions file from stringo to int

Parameters:
permStr - The file permission as drwxrwxrwx
Returns:
int

getStringSeparatedByCommas

public static java.lang.String getStringSeparatedByCommas(java.lang.String[] strings)
Gets a array of string and return a string that contains the strings separated by commas

Parameters:
strings - The array of strings
Returns:
A string with strings separated by commas

getArrayOfStrings

public static java.lang.String[] getArrayOfStrings(java.lang.String string,
                                                   java.lang.String delimitator)
Gets a array of strings after broken with the given delimitator

Parameters:
string - A string that will broken in an array of strings
delimitator - The delimitator between strings
Returns:
An array with the strings of "string" parameter