From ff14e0fc4e3fe4f5b8a67640d28850064661d7ab Mon Sep 17 00:00:00 2001 From: Matthias Jaros Date: Wed, 12 Aug 2026 13:24:27 +0200 Subject: Major refactoring of package structure --- src/main/java/com/it_jaros/jscanner/PortRange.java | 78 ---------------------- 1 file changed, 78 deletions(-) delete mode 100644 src/main/java/com/it_jaros/jscanner/PortRange.java (limited to 'src/main/java/com/it_jaros/jscanner/PortRange.java') diff --git a/src/main/java/com/it_jaros/jscanner/PortRange.java b/src/main/java/com/it_jaros/jscanner/PortRange.java deleted file mode 100644 index 8969b8f..0000000 --- a/src/main/java/com/it_jaros/jscanner/PortRange.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.it_jaros.jscanner; - -import java.util.BitSet; -import java.util.Iterator; - -public class PortRange { - - public static final int MIN_PORT = 1; - public static final int MAX_PORT = 65535; - private final BitSet specifiedPorts = new BitSet(MAX_PORT); - - public PortRange(String ports) { - if (ports == null || "".equals(ports)) { - specifiedPorts.set(MIN_PORT, 1024); - } else if ("all".equalsIgnoreCase(ports)) { - specifiedPorts.set(MIN_PORT, MAX_PORT + 1); - } else { - parsePortRange(ports); - } - } - - /** - * Possible values are 1,10 or 1-10 or a mix of 1,5-10 - * So we treat , stronger and handle them first and then check for - - * - * @param ports - */ - private void parsePortRange(String ports) { - String[] splitComma = ports.split(","); - for (String commaValue : splitComma) { - String[] rangeValue = commaValue.split("-"); - - // more then two values are not possible - if (rangeValue.length > 2) { - throw new IllegalArgumentException(String.format("Argument contains too many '-'' %s", commaValue)); - } - - // no range given, only single port - int port = Integer.parseInt(rangeValue[0]); - if (rangeValue.length == 1) { - checkValue(port); - specifiedPorts.set(port); - continue; - } - - // range given - int end = Integer.parseInt(rangeValue[1]); - checkValues(port, end); - specifiedPorts.set(port, end + 1); - } - } - - private void checkValues(int start, int end) { - checkValue(start); - checkValue(end); - - if (start >= end) { - throw new IllegalArgumentException( - String.format("Start value cannot be equal or bigger than end value '%s >= %s'", start, end)); - } - } - - private void checkValue(int port) { - if (port < MIN_PORT) { - throw new IllegalArgumentException( - String.format("Port value is too low: %s < %s", port, MIN_PORT)); - } - - if (port > MAX_PORT) { - throw new IllegalArgumentException( - String.format("Port value is too high: %s > %s", port, MAX_PORT)); - } - } - - public Iterator iterator() { - return new PortRangeIterator(specifiedPorts); - } -} \ No newline at end of file -- cgit v1.3.1