package net.jtank.util; import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.awt.Color; import net.jtank.io.*; /** * Some useful stand-alone miscellaneous methods. * *
Delegate was created by William Denniss on 5 April 2001. *
This class has a range of handy methods * *
William Denniss has asserted his right under the Copyright, Designs and Patents Act 1988 to be identified as the author of this work.
*
* This text is distributed under the WIL license. I
* If you don't agree with its terms, then please remove all WIL protected software now.
* @version 1.3 - 4 April 2002
* @author William Denniss
*
*/
public class Delegate {
public static final String PROGRAM_NAME = "Delegate";
public static final String VERSION_NUMBER = "1.2";
public static final String DATE_CREATED = "5 April 2001";
public static final String DATE_UPDATED = "21 June 2001";
public static final String AUTHOR = "William Denniss";
/** Causes the current thread to temporarily cease execution for the given number of milliseconds.
* Unlike the wait or sleep methods, no InterrupedException is thrown.
* @param milliseconds the number of milliseconds you want the current thread to temporarily cease execution.
*/
public static void doze (int milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException ie) {
}
}
/** Adjusts a integer to a given scale, returning an integer.
* This method is a quick way to scale and round an integer. Normally, when an integer is scaled the returned result is a double, which is not always desired.
* @param number the integer you want to scale.
* @param scale the number the integer is to be scaled too.
* @return The given number that has been scaled, and rounded to the nearest integer.
*/
public static int scaleAndRound (int number, double scale) {
return (int) Math.round(number * scale);
}
/** Compares a single character of one string, with the entire string of another ignoreing case
*
*@depreciated Due to the fact, it is better to add "" to a char, rarther than using Character.toString()
*
*/
public static boolean equals (String parsedString, int position, String compareString) {
boolean resault = new Character(parsedString.charAt(position)).toString().equalsIgnoreCase(compareString);
return new Character(parsedString.charAt(position)).toString().equalsIgnoreCase(compareString);
}
/** Return the string at the given position, using the default delimeter
*/
public static String carvePos(String uncarved, int position) {
return carvePos(uncarved, position, " ");
}
/** Return the string at the given position, using the parsed delimeter
*/
public static String carvePos(String uncarved, int position, String delimeter) throws NullPointerException, NoSuchElementException{
String carved = "";
try {
StringTokenizer st = new StringTokenizer(uncarved,delimeter);
for (int i=0; i<=position; i++) {
carved = st.nextToken();
}
} catch (NoSuchElementException e) {
carved = "";
}
return carved;
}
/** Return an array of Strings, split using the default delimeter
*/
public static String [] stringCarver (String uncarved) throws NullPointerException{
return stringCarver(uncarved, " ");
}
/** Return an array of Strings, split using the parsed delimeter
*/
public static String [] stringCarver (String uncarved, String delimeter) throws NullPointerException{
int counter=0;
String waste;
StringTokenizer st = new StringTokenizer(uncarved,delimeter);
while (st.hasMoreTokens()){
waste = st.nextToken();
counter++;
}
st = new StringTokenizer(uncarved,delimeter);
String [] carved = new String [counter];
for (int i = 0; i