2014-08-12 15:38:23 +00:00
|
|
|
package com.moandjiezana.toml;
|
|
|
|
|
2014-08-13 12:31:50 +00:00
|
|
|
import static com.moandjiezana.toml.ValueConverterUtils.INVALID;
|
2014-08-13 14:01:31 +00:00
|
|
|
import static com.moandjiezana.toml.ValueConverterUtils.parse;
|
|
|
|
import static com.moandjiezana.toml.ValueConverterUtils.parser;
|
2014-08-12 14:44:47 +00:00
|
|
|
|
2014-08-13 12:27:23 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-08-13 12:31:50 +00:00
|
|
|
class BooleanConverter implements ValueConverter {
|
2014-08-12 14:44:47 +00:00
|
|
|
|
2014-08-13 12:31:50 +00:00
|
|
|
static final BooleanConverter BOOLEAN_PARSER = new BooleanConverter();
|
2014-08-12 14:44:47 +00:00
|
|
|
|
|
|
|
@Override
|
2014-08-13 12:31:50 +00:00
|
|
|
public boolean canConvert(String s) {
|
2014-08-12 14:44:47 +00:00
|
|
|
return s.startsWith("true") || s.startsWith("false");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-08-13 12:31:50 +00:00
|
|
|
public Object convert(String s) {
|
2014-08-13 14:01:31 +00:00
|
|
|
List<String> resultValue = parse(parser().Boolean(), s);
|
2014-08-13 12:27:23 +00:00
|
|
|
|
|
|
|
if (resultValue == null) {
|
2014-08-12 15:38:23 +00:00
|
|
|
return INVALID;
|
2014-08-12 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-13 12:27:23 +00:00
|
|
|
return Boolean.valueOf(resultValue.get(0));
|
2014-08-12 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-13 12:31:50 +00:00
|
|
|
private BooleanConverter() {}
|
2014-08-12 14:44:47 +00:00
|
|
|
}
|