Serviceless rewrite, part 1
Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user