package versusSNP.util;
import versusSNP.gui.UICaption;
import versusSNP.io.BadCharException;
public final class Utils {
public static int toIntegar(String str) throws NumberFormatException {
StringBuffer buf = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
if (Character.isDigit(ch=str.charAt(i)))
buf.append(ch);
}
return Integer.parseInt(buf.toString());
}
public static float toFloat(String str) throws NumberFormatException {
StringBuffer buf = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
ch = str.charAt(i);
if (Character.isDigit(ch) || ch == '.')
buf.append(ch);
}
return Float.parseFloat(buf.toString());
}
public static boolean toStrand(char ch) throws BadCharException {
if (ch == '+')
return true;
else if (ch == '-')
return false;
else
throw new BadCharException(UICaption.dialog_exception_strand_bad_char);
}
public static boolean toStrand(String str) throws BadCharException {
return toStrand(str.charAt(0));
}
public static String removeSpaceFromBegin(String str) {
StringBuffer buf = new StringBuffer();
char ch;
boolean isRemovable = true;
for (int i = 0; i < str.length(); i++) {
ch = str.charAt(i);
if (isRemovable)
isRemovable &= Character.isWhitespace(ch);
if (!isRemovable)
buf.append(ch);
}
return buf.toString();
}
/**
* Tests if the given object is in the array
* @param object - the desired object
* @param array - the array to search in
* @return true if in this array; false otherwise
*/
public static boolean isInArray(Object object, Object[] array) {
for (Object obj : array) {
if (object.equals(obj))
return true;
}
return false;
}
public static boolean isDigit(String str) {
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(0)))
return false;
}
return true;
}
public static int[] arraycopy(int[] src) {
int[] dest = new int[src.length];
System.arraycopy(src, 0, dest, 0, src.length);
return dest;
}
}