Strings.java
package edu.udel.cis.vsl.tass.util;
public class Strings {
/**
* Extracts a substring of the given string. The substring starts after the
* last occurrence of a '/' character (or at character 0 if there is no '/'
* character present in filename) and ends just before the last '.'
* character (or at the final character if there is no '.' character present
* in filename). This is the default choice of name for a model, given the
* file in which the model occurs.
*/
public static String rootName(String filename) {
int first = filename.lastIndexOf('/');
int last;
if (first < 0)
first = 0;
else
first++;
last = filename.lastIndexOf('.');
if (last <= first)
last = filename.length();
return filename.substring(first, last);
}
/**
* Given a string s containing ".", s must have the form X.Y, where X is a
* string and Y is a string that does not contain "."; this method returns
* Y. If s does not contain ".", this returns null.
*
* @param filename
* the given string s
* @return the substring following the last occurrence of ".", or null
*/
public static String getSuffix(String filename) {
int position = filename.lastIndexOf('.');
if (position < 0)
return null;
return filename.substring(position + 1);
}
/**
* Returns string identical to given string except that first letter is
* capitalized.
*
* @throws TASSInternalException
* if the string is empty
* */
public static String capitalizeFirstLetter(String string) {
if (string.length() < 1) {
throw new TASSInternalException("Empty name");
} else {
String first = string.substring(0, 1).toUpperCase();
String rest = string.substring(1);
String result = first.concat(rest);
return result;
}
}
}