Serviceless rewrite, part 1

Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
Samuel Holland
2018-01-06 04:09:29 -06:00
parent 4c0869393e
commit 609194fae2
68 changed files with 2564 additions and 2296 deletions
@@ -21,38 +21,38 @@ enum Attribute {
PRIVATE_KEY("PrivateKey"),
PUBLIC_KEY("PublicKey");
private static final Map<String, Attribute> map;
private static final Map<String, Attribute> KEY_MAP;
private static final Pattern SEPARATOR_PATTERN = Pattern.compile("\\s|=");
static {
map = new HashMap<>(Attribute.values().length);
for (final Attribute key : Attribute.values())
map.put(key.getToken(), key);
KEY_MAP = new HashMap<>(Attribute.values().length);
for (final Attribute key : Attribute.values()) {
KEY_MAP.put(key.token, key);
}
}
public static Attribute match(final String line) {
return map.get(line.split("\\s|=")[0]);
}
private final String token;
private final Pattern pattern;
private final String token;
Attribute(final String token) {
pattern = Pattern.compile(token + "\\s*=\\s*(\\S.*)");
this.token = token;
}
public String composeWith(final String value) {
return token + " = " + value + "\n";
public static Attribute match(final CharSequence line) {
return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0]);
}
public String composeWith(final Object value) {
return String.format("%s = %s%n", token, value);
}
public String getToken() {
return token;
}
public String parseFrom(final String line) {
public String parse(final CharSequence line) {
final Matcher matcher = pattern.matcher(line);
if (matcher.matches())
return matcher.group(1);
return null;
return matcher.matches() ? matcher.group(1) : null;
}
}