* @since 2.0
*/
static final public RateOptions parseRateOptions(final boolean rate,
final String spec) {
if (!rate || spec.length() == 4) {
return new RateOptions(false, Long.MAX_VALUE,
RateOptions.DEFAULT_RESET_VALUE);
}
if (spec.length() < 6) {
throw new BadRequestException("Invalid rate options specification: "
+ spec);
}
String[] parts = Tags
.splitString(spec.substring(5, spec.length() - 1), ',');
if (parts.length < 1 || parts.length > 3) {
throw new BadRequestException(
"Incorrect number of values in rate options specification, must be " +
"counter[,counter max value,reset value], recieved: "
+ parts.length + " parts");
}
final boolean counter = "counter".equals(parts[0]);
try {
final long max = (parts.length >= 2 && parts[1].length() > 0 ? Long
.parseLong(parts[1]) : Long.MAX_VALUE);
try {
final long reset = (parts.length >= 3 && parts[2].length() > 0 ? Long
.parseLong(parts[2]) : RateOptions.DEFAULT_RESET_VALUE);
return new RateOptions(counter, max, reset);
} catch (NumberFormatException e) {
throw new BadRequestException(
"Reset value of counter was not a number, received '" + parts[2]
+ "'");
}