Methods Summary |
---|
private void | addHours(long hours)Adds the given number of hours to the total clock value.
millis += (hours * MILLIS_PER_HOUR);
|
private void | addMillis(long ms)Adds the given number of milliseconds to the total clock value.
millis += ms;
|
private void | addMinutes(long minutes)Adds the given number of minutes to the total clock value.
millis += (minutes * MILLIS_PER_MINUTE);
|
private void | addSeconds(long seconds)Adds the given number of seconds to the total clock value.
millis += (seconds * MILLIS_PER_SECOND);
|
public long | parseClock(java.lang.String clockString)Parses a clock value. This method throws an
IllegalArgumentException if the input argument's
syntax does not conform to that of a clock value, as defined
by the SMIL specification.
setString(clockString);
current = read();
return parseClock(true);
|
protected long | parseClock(boolean eos)Parses a clock value, beginning at the current character.
millis = 0L;
int[] wholeParts = new int[3];
float fractionPart = 0.0f;
int numWholeParts = 0;
int tmp = 0;
boolean isTimeCountVal = true;
boolean isFirstDigitInferiorToSix = false;
boolean hasFractionPart = false;
// first digit (could be part of full, partial, or count)
m1: switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4": case '5":
isFirstDigitInferiorToSix = true;
break m1;
case '6": case '7": case '8": case '9":
break m1;
}
tmp = tmp * 10 + (current - '0");
current = read();
m2: switch (current) {
default:
throw new IllegalArgumentException();
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m2;
case ':":
if (isFirstDigitInferiorToSix) {
isTimeCountVal = false;
wholeParts[numWholeParts++] = tmp;
tmp = 0;
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4": case '5":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case ':":
wholeParts[numWholeParts++] = tmp;
tmp = 0;
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2":
case '3": case '4": case '5":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3":
case '4": case '5": case '6": case '7":
case '8": case '9":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '.":
break m2;
case 0x20: case 0x09:
case 0x0D: case 0x0A:
case ';":
if (eos) {
throw
new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m2;
}
}
}
}
}
}
}
break m2;
case '.": case 'h": case 'm": case 's":
break m2;
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
if (isFirstDigitInferiorToSix) {
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m2;
case '.": case 'h": case 'm": case 's":
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
break m2;
case ':":
isTimeCountVal = false;
wholeParts[numWholeParts++] = tmp;
tmp = 0;
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4": case '5":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '.":
break m2;
case 0x20: case 0x09: case 0x0D: case 0x0A:
case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m2;
case ':":
wholeParts[numWholeParts++] = tmp;
tmp = 0;
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2":
case '3": case '4": case '5":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3":
case '4": case '5": case '6": case '7":
case '8": case '9":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw
new IllegalArgumentException();
case '.":
break m2;
case 0x20: case 0x09:
case 0x0D: case 0x0A:
case ';":
if (eos) {
throw
new
IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m2;
}
}
}
}
}
}
}
}
}
m3: switch (current) {
default:
throw new IllegalArgumentException();
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
break m3;
case ':": case '.": case 'h": case 'm": case 's":
break m3;
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
// must be in the hours field; loop until we reach the colon
for (;;) {
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m3;
case ':": case '.": case 'h": case 'm": case 's":
break m3;
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
}
}
}
m4: switch (current) {
default:
throw new IllegalArgumentException();
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
break m4;
case '.": case 'h": case 'm": case 's":
break m4;
case ':":
isTimeCountVal = false;
wholeParts[numWholeParts++] = tmp;
tmp = 0;
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4": case '5":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case ':":
wholeParts[numWholeParts++] = tmp;
tmp = 0;
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2":case '3":
case '4": case '5":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
tmp = tmp * 10 + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case '.":
break m4;
case 0x20: case 0x09: case 0x0D: case 0x0A:
case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
wholeParts[numWholeParts++] = tmp;
break m4;
}
}
}
}
}
}
}
m5: switch (current) {
default:
throw new IllegalArgumentException();
case '.":
wholeParts[numWholeParts++] = tmp;
hasFractionPart = true;
String frac = "0.";
current = read();
if (isTimeCountVal) {
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
for (;;) {
frac = frac + (current - '0");
current = read();
switch (current) {
default:
break m5;
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case 'h": case 'm": case 's": case -1:
fractionPart = Float.parseFloat(frac);
break m5;
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
}
}
}
} else {
switch (current) {
default:
throw new IllegalArgumentException();
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
for (;;) {
frac = frac + (current - '0");
current = read();
switch (current) {
default:
throw new IllegalArgumentException();
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
fractionPart = Float.parseFloat(frac);
break m5;
case '0": case '1": case '2": case '3": case '4":
case '5": case '6": case '7": case '8": case '9":
}
}
}
}
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case 'h": case 'm": case 's": case -1:
break m5;
}
switch (current) {
default:
throw new IllegalArgumentException();
case 'h":
numWholeParts = 0; // so we don't fall into the seconds case below
addHours(tmp);
addMillis((int) (fractionPart * MILLIS_PER_HOUR));
current = read();
break;
case 'm":
numWholeParts = 0; // so we don't fall into the seconds case below
current = read();
switch (current) {
case 'i":
current = read();
switch (current) {
case 'n":
addMinutes(tmp);
addMillis((int) (fractionPart * MILLIS_PER_MINUTE));
current = read();
break;
default:
throw new IllegalArgumentException();
}
break;
case 's":
addMillis(tmp);
current = read();
break;
default:
throw new IllegalArgumentException();
}
break;
case 's":
// seconds case is handled in the time count case below
if (!hasFractionPart) {
wholeParts[numWholeParts++] = tmp;
}
current = read();
break;
case 0x20: case 0x09: case 0x0D: case 0x0A: case ';":
if (eos) {
throw new IllegalArgumentException();
}
// FALLTHROUGH
case -1:
break;
}
if (eos) {
skipSpaces();
if (current != -1) {
throw new IllegalArgumentException();
}
}
switch (numWholeParts) {
case 0: // time count was already handled above, just break
break;
case 1: // time count (seconds)
addSeconds(wholeParts[0]);
addMillis((int) (fractionPart * MILLIS_PER_SECOND));
break;
case 2: // partial clock value
addMinutes(wholeParts[0]);
addSeconds(wholeParts[1]);
addMillis((int) (fractionPart * MILLIS_PER_SECOND));
break;
case 3: // full clock value
addHours(wholeParts[0]);
addMinutes(wholeParts[1]);
addSeconds(wholeParts[2]);
addMillis((int) (fractionPart * MILLIS_PER_SECOND));
break;
default:
throw new IllegalArgumentException("wrong number of whole parts");
}
return millis;
|