}
protected static ConversionResult makeDuration(CharSequence s, boolean allowYM, boolean allowDT) {
int years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, microseconds = 0;
boolean negative = false;
StringTokenizer tok = new StringTokenizer(Whitespace.trimWhitespace(s).toString(), "-+.PYMDTHS", true);
int components = 0;
if (!tok.hasMoreElements()) {
return badDuration("empty string", s);
}
String part = (String)tok.nextElement();
if ("+".equals(part)) {
return badDuration("+ sign not allowed in a duration", s);
} else if ("-".equals(part)) {
negative = true;
part = (String)tok.nextElement();
}
if (!"P".equals(part)) {
return badDuration("missing 'P'", s);
}
int state = 0;
while (tok.hasMoreElements()) {
part = (String)tok.nextElement();
if ("T".equals(part)) {
state = 4;
if (!tok.hasMoreElements()) {
return badDuration("T must be followed by time components", s);
}
part = (String)tok.nextElement();
}
int value = simpleInteger(part);
if (value < 0) {
if (part.length() > 8) {
return badDuration("component invalid or too large", s);
} else {
return badDuration("non-numeric component", s);
}
}
if (!tok.hasMoreElements()) {
return badDuration("missing unit letter at end", s);
}
char delim = ((String)tok.nextElement()).charAt(0);
switch (delim) {
case'Y':
if (state > 0) {
return badDuration("Y is out of sequence", s);
}