@Test public void testParsePorts_portRange() { ArrayList<Integer> ports = ResourceUtil.parsePorts("ports(*):[8080-8082]"); assertEquals(3, ports.size()); assertEquals(8080, ports.get(0).intValue()); assertEquals(8081, ports.get(1).intValue()); assertEquals(8082, ports.get(2).intValue()); }
public static ArrayList<Integer> parsePorts(String mesosResourceString) { if (mesosResourceString == null) { throw new MinimesosException("Resource string is null"); } String portRangeString = mesosResourceString.replaceAll(".*ports\\(.+\\):\\[(.*)\\].*", "$1"); ArrayList<String> portRanges = new ArrayList<>(Arrays.asList(portRangeString.split(","))); ArrayList<Integer> returnList = new ArrayList<>(); for (String portRange : portRanges) { if (!portRange.matches("\\d+-\\d+")) { throw new MinimesosException("Resource string '" + mesosResourceString + "' is incorrect. We only support a single port range."); } String[] ports = portRange.split("-"); int startPort = Integer.valueOf(ports[0]); int endPort = Integer.valueOf(ports[1]); if (startPort > endPort) { throw new MinimesosException("Incorrect port range. Start port " + startPort + " is greater than end port " + endPort); } for (int i = startPort; i <= endPort; i++) { returnList.add(i); } } return returnList; }
ResourceUtil { public static ArrayList<Integer> parsePorts(String mesosResourceString) { if (mesosResourceString == null) { throw new MinimesosException("Resource string is null"); } String portRangeString = mesosResourceString.replaceAll(".*ports\\(.+\\):\\[(.*)\\].*", "$1"); ArrayList<String> portRanges = new ArrayList<>(Arrays.asList(portRangeString.split(","))); ArrayList<Integer> returnList = new ArrayList<>(); for (String portRange : portRanges) { if (!portRange.matches("\\d+-\\d+")) { throw new MinimesosException("Resource string '" + mesosResourceString + "' is incorrect. We only support a single port range."); } String[] ports = portRange.split("-"); int startPort = Integer.valueOf(ports[0]); int endPort = Integer.valueOf(ports[1]); if (startPort > endPort) { throw new MinimesosException("Incorrect port range. Start port " + startPort + " is greater than end port " + endPort); } for (int i = startPort; i <= endPort; i++) { returnList.add(i); } } return returnList; } }
ResourceUtil { public static ArrayList<Integer> parsePorts(String mesosResourceString) { if (mesosResourceString == null) { throw new MinimesosException("Resource string is null"); } String portRangeString = mesosResourceString.replaceAll(".*ports\\(.+\\):\\[(.*)\\].*", "$1"); ArrayList<String> portRanges = new ArrayList<>(Arrays.asList(portRangeString.split(","))); ArrayList<Integer> returnList = new ArrayList<>(); for (String portRange : portRanges) { if (!portRange.matches("\\d+-\\d+")) { throw new MinimesosException("Resource string '" + mesosResourceString + "' is incorrect. We only support a single port range."); } String[] ports = portRange.split("-"); int startPort = Integer.valueOf(ports[0]); int endPort = Integer.valueOf(ports[1]); if (startPort > endPort) { throw new MinimesosException("Incorrect port range. Start port " + startPort + " is greater than end port " + endPort); } for (int i = startPort; i <= endPort; i++) { returnList.add(i); } } return returnList; } private  ResourceUtil(); }
ResourceUtil { public static ArrayList<Integer> parsePorts(String mesosResourceString) { if (mesosResourceString == null) { throw new MinimesosException("Resource string is null"); } String portRangeString = mesosResourceString.replaceAll(".*ports\\(.+\\):\\[(.*)\\].*", "$1"); ArrayList<String> portRanges = new ArrayList<>(Arrays.asList(portRangeString.split(","))); ArrayList<Integer> returnList = new ArrayList<>(); for (String portRange : portRanges) { if (!portRange.matches("\\d+-\\d+")) { throw new MinimesosException("Resource string '" + mesosResourceString + "' is incorrect. We only support a single port range."); } String[] ports = portRange.split("-"); int startPort = Integer.valueOf(ports[0]); int endPort = Integer.valueOf(ports[1]); if (startPort > endPort) { throw new MinimesosException("Incorrect port range. Start port " + startPort + " is greater than end port " + endPort); } for (int i = startPort; i <= endPort; i++) { returnList.add(i); } } return returnList; } private  ResourceUtil(); static ArrayList<Integer> parsePorts(String mesosResourceString); }
ResourceUtil { public static ArrayList<Integer> parsePorts(String mesosResourceString) { if (mesosResourceString == null) { throw new MinimesosException("Resource string is null"); } String portRangeString = mesosResourceString.replaceAll(".*ports\\(.+\\):\\[(.*)\\].*", "$1"); ArrayList<String> portRanges = new ArrayList<>(Arrays.asList(portRangeString.split(","))); ArrayList<Integer> returnList = new ArrayList<>(); for (String portRange : portRanges) { if (!portRange.matches("\\d+-\\d+")) { throw new MinimesosException("Resource string '" + mesosResourceString + "' is incorrect. We only support a single port range."); } String[] ports = portRange.split("-"); int startPort = Integer.valueOf(ports[0]); int endPort = Integer.valueOf(ports[1]); if (startPort > endPort) { throw new MinimesosException("Incorrect port range. Start port " + startPort + " is greater than end port " + endPort); } for (int i = startPort; i <= endPort; i++) { returnList.add(i); } } return returnList; } private  ResourceUtil(); static ArrayList<Integer> parsePorts(String mesosResourceString);  }