pslib
Class PSTools

java.lang.Object
  extended by pslib.PSTools

public class PSTools
extends java.lang.Object

PSTools Class

The PSTools class provides a range of static utility functions.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.


Constructor Summary
PSTools()
           
 
Method Summary
static java.lang.String[] cleanStrings(java.lang.String[] s)
          Remove any empty entries from the specified string array
static java.lang.String combineStrings(java.lang.String[] s)
          Combine all the strings within the specified array and return the result
static java.lang.String combineStrings(java.lang.String[] sa, java.lang.String ss)
          Combine all the strings within the specified array with the specified spacer string and return the result
static float constrainFloat(float value, float min, float max)
          Constrain a float value between the specified minimum and maximum
static int constrainInt(int value, int min, int max)
          Constrain an integer value between the specified minimum and maximum
static java.lang.String[] copyStrings(java.lang.String[] str)
          Copy an array of strings and return the result
static PSColour randomColour()
          Return a Colour object with random component values
static PSColour randomColour(boolean alpha)
          Return a Colour object with random component values
static PSVector randomVector()
          Return a normalised PSVector object with random component values
static PSVector randomVector(float r)
          Return a PSVector object with random component values within the specified radius about the point (0, 0, 0)
static PSVector randomVector(float rmi, float rma)
          Return a PSVector object with random component values within the specified radii about the point (0, 0, 0)
static PSVector randomVector(PSVector r)
          Return a PSVector object with random component values within +/- the specified range about the point (0, 0, 0)
static java.lang.String[] readStrings(java.io.File f)
          Converts an input text file to an array of strings
static java.lang.String[] readStrings(java.lang.String f)
          Converts an input text file to an array of strings
static java.lang.String removeFileExtension(java.lang.String s)
          Removes a file extension from a string assuming the file.extension format
static java.lang.String removeFileName(java.lang.String s)
          Remove the file name from the specified string assuming the string adopts the File.separatorChar path character
static java.lang.String removeTokens(java.lang.String s, java.lang.String t)
          Remove the specified characters from a string
static java.lang.String removeWhiteSpace(java.lang.String str)
          Removes all spaces within a string
static java.lang.String[] splitTokens(java.lang.String s, java.lang.String t)
          Split a string using the specified tokens
static java.lang.String stringNumberFormat(java.lang.String s, char c, int n)
          Replaces instances of a specified character within a string with a formatted number
static java.lang.String stringNumberFormat(java.lang.String s, int n)
          Replaces instances of the character # within a string with a formatted number
static java.lang.String stripQuotes(java.lang.String str)
          Removes quotations from a string by removing the first and last characters
static boolean writeStrings(java.lang.String[] sa, java.io.File f)
          Write an array of strings to the specified file
static boolean writeStrings(java.lang.String[] sa, java.lang.String f)
          Write an array of strings to the specified file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PSTools

public PSTools()
Method Detail

readStrings

public static java.lang.String[] readStrings(java.lang.String f)
Converts an input text file to an array of strings

If the input file cannot be parsed a null value will be returned.

Parameters:
f - file
Returns:
string array

readStrings

public static java.lang.String[] readStrings(java.io.File f)
Converts an input text file to an array of strings

If the input file cannot be parsed a null value will be returned.

Parameters:
f - file
Returns:
string array

writeStrings

public static boolean writeStrings(java.lang.String[] sa,
                                   java.lang.String f)
Write an array of strings to the specified file

Parameters:
sa - string array
f - output file
Returns:
true if the file was successfully written

writeStrings

public static boolean writeStrings(java.lang.String[] sa,
                                   java.io.File f)
Write an array of strings to the specified file

Parameters:
sa - string array
f - output file
Returns:
true if the file was successfully written

combineStrings

public static java.lang.String combineStrings(java.lang.String[] s)
Combine all the strings within the specified array and return the result

Parameters:
s - array of strings
Returns:
a single combined string

combineStrings

public static java.lang.String combineStrings(java.lang.String[] sa,
                                              java.lang.String ss)
Combine all the strings within the specified array with the specified spacer string and return the result

Parameters:
sa - array of strings
ss - spacer string
Returns:
a single combined string

stringNumberFormat

public static java.lang.String stringNumberFormat(java.lang.String s,
                                                  int n)
Replaces instances of the character # within a string with a formatted number

Parameters:
s - a string
n - an integer
Returns:
the formatted string

stringNumberFormat

public static java.lang.String stringNumberFormat(java.lang.String s,
                                                  char c,
                                                  int n)
Replaces instances of a specified character within a string with a formatted number

Parameters:
s - a string
c - the character to be replaced
n - an integer
Returns:
the formatted string

splitTokens

public static java.lang.String[] splitTokens(java.lang.String s,
                                             java.lang.String t)
Split a string using the specified tokens

Parameters:
s - string
t - tokens
Returns:
string array

cleanStrings

public static java.lang.String[] cleanStrings(java.lang.String[] s)
Remove any empty entries from the specified string array

Parameters:
s - string array
Returns:
the formatted string array

removeTokens

public static java.lang.String removeTokens(java.lang.String s,
                                            java.lang.String t)
Remove the specified characters from a string

Parameters:
s - string
t - tokens
Returns:
the formatted string

removeFileExtension

public static java.lang.String removeFileExtension(java.lang.String s)
Removes a file extension from a string assuming the file.extension format

Parameters:
s - a file name as a string
Returns:
the formatted string

removeFileName

public static java.lang.String removeFileName(java.lang.String s)
Remove the file name from the specified string assuming the string adopts the File.separatorChar path character

Parameters:
s - file
Returns:
the formatted string

stripQuotes

public static java.lang.String stripQuotes(java.lang.String str)
Removes quotations from a string by removing the first and last characters

Parameters:
str - the string to be formatted
Returns:
the formatted string

removeWhiteSpace

public static java.lang.String removeWhiteSpace(java.lang.String str)
Removes all spaces within a string

Parameters:
str - the string to be formatted
Returns:
the formatted string

copyStrings

public static java.lang.String[] copyStrings(java.lang.String[] str)
Copy an array of strings and return the result

Parameters:
str - string array
Returns:
the copied string array

constrainInt

public static int constrainInt(int value,
                               int min,
                               int max)
Constrain an integer value between the specified minimum and maximum

Parameters:
value - input value
min - lower limit
max - upper limit
Returns:
constrained value

constrainFloat

public static float constrainFloat(float value,
                                   float min,
                                   float max)
Constrain a float value between the specified minimum and maximum

Parameters:
value - input value
min - lower limit
max - upper limit
Returns:
constrained value

randomColour

public static PSColour randomColour()
Return a Colour object with random component values

Returns:
a Colour object with random component values

randomColour

public static PSColour randomColour(boolean alpha)
Return a Colour object with random component values

Parameters:
alpha - alpha component toggle (true = random alpha)
Returns:
a Colour object with random component values

randomVector

public static PSVector randomVector()
Return a normalised PSVector object with random component values

Returns:
a PSVector object with random component values

randomVector

public static PSVector randomVector(float r)
Return a PSVector object with random component values within the specified radius about the point (0, 0, 0)

Parameters:
r - radius
Returns:
a PSVector object with random component values

randomVector

public static PSVector randomVector(float rmi,
                                    float rma)
Return a PSVector object with random component values within the specified radii about the point (0, 0, 0)

Parameters:
rmi - minimum radius
rma - maximum radius
Returns:
a PSVector object with random component values

randomVector

public static PSVector randomVector(PSVector r)
Return a PSVector object with random component values within +/- the specified range about the point (0, 0, 0)

Parameters:
r - range
Returns:
a PSVector object with random component values