commit c5568eec63f21c325f8122ea8a67943c5ee0ce41 Author: Karsten Loesing karsten.loesing@gmx.net Date: Mon Aug 20 12:22:16 2018 +0200
Use Java 5 and 7 idioms in more places. --- .../java/org/torproject/descriptor/impl/DescriptorImpl.java | 2 +- .../torproject/descriptor/impl/ExtraInfoDescriptorImpl.java | 2 +- .../org/torproject/descriptor/impl/MicrodescriptorImpl.java | 4 ++-- .../org/torproject/descriptor/impl/NetworkStatusEntryImpl.java | 4 ++-- src/main/java/org/torproject/descriptor/impl/ParseHelper.java | 10 +++++----- .../org/torproject/descriptor/impl/RelayDirectoryImpl.java | 3 +-- .../org/torproject/descriptor/impl/ServerDescriptorImpl.java | 4 ++-- .../java/org/torproject/descriptor/impl/TorperfResultImpl.java | 3 +-- .../descriptor/index/DescriptorIndexCollectorTest.java | 2 +- 9 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java index a6acee7..2e7b0f9 100644 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java @@ -189,7 +189,7 @@ public abstract class DescriptorImpl implements Descriptor {
@Override public List<String> getUnrecognizedLines() { - return this.unrecognizedLines == null ? new ArrayList<String>() + return this.unrecognizedLines == null ? new ArrayList<>() : new ArrayList<>(this.unrecognizedLines); }
diff --git a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java index d0e3d7e..ade341b 100644 --- a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java @@ -605,7 +605,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl private SortedMap<String, Long> sortByPorts( SortedMap<String, Long> naturalOrder) { SortedMap<String, Long> byPortNumber = - new TreeMap<String, Long>(new Comparator<String>() { + new TreeMap<>(new Comparator<String>() { public int compare(String arg0, String arg1) { int port0 = 0; int port1 = 0; diff --git a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java index f91362e..44c25a2 100644 --- a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java @@ -170,8 +170,8 @@ public class MicrodescriptorImpl extends DescriptorImpl case "accept": case "reject": String[] ports = parts[2].split(",", -1); - for (int i = 0; i < ports.length; i++) { - if (ports[i].length() < 1) { + for (String port : ports) { + if (port.length() < 1) { isValid = false; break; } diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java index 4472875..3c0c1af 100644 --- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java @@ -235,8 +235,8 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry { this.defaultPolicy = parts[1]; this.portList = parts[2]; String[] ports = parts[2].split(",", -1); - for (int i = 0; i < ports.length; i++) { - if (ports[i].length() < 1) { + for (String port : ports) { + if (port.length() < 1) { isValid = false; break; } diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java index 49a3430..93ad610 100644 --- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java +++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java @@ -252,14 +252,14 @@ public class ParseHelper { protected static SortedMap<String, String> parseKeyValueStringPairs( String line, String[] parts, int startIndex) throws DescriptorParseException { - return (new KeyValueMap<String>(String.class)) + return (new KeyValueMap<>(String.class)) .parseKeyValueList(line, parts, startIndex, 0, " "); }
protected static SortedMap<String, Integer> parseKeyValueIntegerPairs( String line, String[] parts, int startIndex) throws DescriptorParseException { - return (new KeyValueMap<Integer>(Integer.class)) + return (new KeyValueMap<>(Integer.class)) .parseKeyValueList(line, parts, startIndex, 0, " "); }
@@ -354,7 +354,7 @@ public class ParseHelper { parseCommaSeparatedKeyLongValueList(String line, String[] partsNoOpt, int index, int keyLength) throws DescriptorParseException { - return (new KeyValueMap<Long>(Long.class)) + return (new KeyValueMap<>(Long.class)) .parseKeyValueList(line, partsNoOpt, index, keyLength, ","); }
@@ -410,7 +410,7 @@ public class ParseHelper { parseSpaceSeparatedStringKeyDoubleValueMap(String line, String[] partsNoOpt, int startIndex) throws DescriptorParseException { - return (new KeyValueMap<Double>(Double.class)) + return (new KeyValueMap<>(Double.class)) .parseKeyValueList(line, partsNoOpt, startIndex, -1, " "); }
@@ -418,7 +418,7 @@ public class ParseHelper { parseSpaceSeparatedStringKeyLongValueMap(String line, String[] partsNoOpt, int startIndex) throws DescriptorParseException { - return (new KeyValueMap<Long>(Long.class)) + return (new KeyValueMap<>(Long.class)) .parseKeyValueList(line, partsNoOpt, startIndex, -1, " "); }
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java index 590b7ab..802469f 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java @@ -284,8 +284,7 @@ public class RelayDirectoryImpl extends DescriptorImpl + "'."); } else if (partsNoOpt.length == 2) { String[] versions = partsNoOpt[1].split(",", -1); - for (int i = 0; i < versions.length; i++) { - String version = versions[i]; + for (String version : versions) { if (version.length() < 1) { throw new DescriptorParseException("Illegal versions line '" + line + "'."); diff --git a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java index e3b2a17..804976f 100644 --- a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java @@ -546,8 +546,8 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl this.ipv6DefaultPolicy = partsNoOpt[1]; this.ipv6PortList = partsNoOpt[2]; String[] ports = partsNoOpt[2].split(",", -1); - for (int i = 0; i < ports.length; i++) { - if (ports[i].length() < 1) { + for (String port : ports) { + if (port.length() < 1) { isValid = false; break; } diff --git a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java index de436b5..92b7750 100644 --- a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java @@ -74,8 +74,7 @@ public class TorperfResultImpl extends DescriptorImpl throw new DescriptorParseException("Blank lines are not allowed."); } String[] parts = line.split(" "); - for (int i = 0; i < parts.length; i++) { - String keyValue = parts[i]; + for (String keyValue : parts) { String[] keyValueParts = keyValue.split("="); if (keyValueParts.length != 2) { throw new DescriptorParseException("Illegal key-value pair in " diff --git a/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java b/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java index 1180301..bde64d6 100644 --- a/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java +++ b/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java @@ -288,7 +288,7 @@ public class DescriptorIndexCollectorTest { SortedMap<String, FileNode> fm = new TreeMap<>(); fm.put("readonly", new FileNode("w", 2L, "2100-01-01 01:01")); new DescriptorIndexCollector() - .fetchRemoteFiles("", fm, 100L, dir, new TreeMap<String, Long>()); + .fetchRemoteFiles("", fm, 100L, dir, new TreeMap<>()); } }
tor-commits@lists.torproject.org