commit 83cf2bb101beac95fefaabc58e5f8e0f3bbd258d Author: iwakeh iwakeh@torproject.org Date: Thu Jun 1 08:44:35 2017 +0000
Minor readability and space changes. Removed check that cannot evaluate as true. --- src/main/java/org/torproject/descriptor/impl/KeyValueMap.java | 10 +++++----- src/main/java/org/torproject/descriptor/impl/ParseHelper.java | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/impl/KeyValueMap.java b/src/main/java/org/torproject/descriptor/impl/KeyValueMap.java index 7b918dc..a1eab05 100644 --- a/src/main/java/org/torproject/descriptor/impl/KeyValueMap.java +++ b/src/main/java/org/torproject/descriptor/impl/KeyValueMap.java @@ -24,8 +24,7 @@ public class KeyValueMap<T> extends TreeMap<String, T> { throw new DescriptorParseException("Line '" + line + "' contains " + "duplicate key '" + key + "'."); } - if (null == key || key.isEmpty() - || (keyLength > 0 && key.length() != keyLength)) { + if (key.isEmpty() || (keyLength > 0 && key.length() != keyLength)) { throw new DescriptorParseException("Line '" + line + "' contains an " + "illegal key in list element '" + listElement + "'."); } @@ -43,10 +42,11 @@ public class KeyValueMap<T> extends TreeMap<String, T> { if (startIndex >= partsNoOpt.length) { return this; } - String[] keysAndValues = " ".equals(separatorPattern) ? partsNoOpt + boolean usingSpacePattern = " ".equals(separatorPattern); + String[] keysAndValues = usingSpacePattern ? partsNoOpt : partsNoOpt[startIndex].split(separatorPattern, -1); - for (int i = " ".equals(separatorPattern) ? startIndex : 0; - i < keysAndValues.length; i++) { + for (int i = usingSpacePattern ? startIndex : 0; i < keysAndValues.length; + i++) { String listElement = keysAndValues[i]; String[] keyAndValue = listElement.split("="); String key = keyAndValue[0]; diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java index e89b59e..31454e5 100644 --- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java +++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java @@ -23,8 +23,7 @@ import javax.xml.bind.DatatypeConverter;
public class ParseHelper {
- private static Pattern keywordPattern = - Pattern.compile("^[A-Za-z0-9-]+$"); + private static Pattern keywordPattern = Pattern.compile("^[A-Za-z0-9-]+$");
protected static String parseKeyword(String line, String keyword) throws DescriptorParseException { @@ -35,8 +34,7 @@ public class ParseHelper { return keyword; }
- private static Pattern ipv4Pattern = - Pattern.compile("^[0-9\.]{7,15}$"); + private static Pattern ipv4Pattern = Pattern.compile("^[0-9\.]{7,15}$");
protected static String parseIpv4Address(String line, String address) throws DescriptorParseException {
tor-commits@lists.torproject.org