@Test public void testFromStringWithSpacesToString() { PortRange r = PortRanges.fromString(" 80 , 8080 , 8000 , 8080 - 8099 "); Assert.assertEquals(r.toString(), "80,8080,8000,8080-8099"); }
public static PortRange fromString(String s) { List<PortRange> l = new ArrayList<PortRange>(); for (String si: s.split(",")) { si = si.trim(); int start, end; if (si.endsWith("+")) { String si2 = si.substring(0, si.length()-1).trim(); start = Integer.parseInt(si2); end = MAX_PORT; } else if (si.indexOf('-')>0) { int v = si.indexOf('-'); start = Integer.parseInt(si.substring(0, v).trim()); end = Integer.parseInt(si.substring(v+1).trim()); } else if (si.length()==0) { continue; } else { l.add(new SinglePort(Integer.parseInt(si))); continue; } l.add(new LinearPortRange(start, end)); } if (l.size() == 1) { return l.get(0); } else { return new AggregatePortRange(l); } }
PortRanges { public static PortRange fromString(String s) { List<PortRange> l = new ArrayList<PortRange>(); for (String si: s.split(",")) { si = si.trim(); int start, end; if (si.endsWith("+")) { String si2 = si.substring(0, si.length()-1).trim(); start = Integer.parseInt(si2); end = MAX_PORT; } else if (si.indexOf('-')>0) { int v = si.indexOf('-'); start = Integer.parseInt(si.substring(0, v).trim()); end = Integer.parseInt(si.substring(v+1).trim()); } else if (si.length()==0) { continue; } else { l.add(new SinglePort(Integer.parseInt(si))); continue; } l.add(new LinearPortRange(start, end)); } if (l.size() == 1) { return l.get(0); } else { return new AggregatePortRange(l); } } }
PortRanges { public static PortRange fromString(String s) { List<PortRange> l = new ArrayList<PortRange>(); for (String si: s.split(",")) { si = si.trim(); int start, end; if (si.endsWith("+")) { String si2 = si.substring(0, si.length()-1).trim(); start = Integer.parseInt(si2); end = MAX_PORT; } else if (si.indexOf('-')>0) { int v = si.indexOf('-'); start = Integer.parseInt(si.substring(0, v).trim()); end = Integer.parseInt(si.substring(v+1).trim()); } else if (si.length()==0) { continue; } else { l.add(new SinglePort(Integer.parseInt(si))); continue; } l.add(new LinearPortRange(start, end)); } if (l.size() == 1) { return l.get(0); } else { return new AggregatePortRange(l); } }  }
PortRanges { public static PortRange fromString(String s) { List<PortRange> l = new ArrayList<PortRange>(); for (String si: s.split(",")) { si = si.trim(); int start, end; if (si.endsWith("+")) { String si2 = si.substring(0, si.length()-1).trim(); start = Integer.parseInt(si2); end = MAX_PORT; } else if (si.indexOf('-')>0) { int v = si.indexOf('-'); start = Integer.parseInt(si.substring(0, v).trim()); end = Integer.parseInt(si.substring(v+1).trim()); } else if (si.length()==0) { continue; } else { l.add(new SinglePort(Integer.parseInt(si))); continue; } l.add(new LinearPortRange(start, end)); } if (l.size() == 1) { return l.get(0); } else { return new AggregatePortRange(l); } }  static PortRange fromInteger(int x); static PortRange fromIterable(Iterable<?> c); static PortRange fromString(String s); @SuppressWarnings("rawtypes") static void init(); }
PortRanges { public static PortRange fromString(String s) { List<PortRange> l = new ArrayList<PortRange>(); for (String si: s.split(",")) { si = si.trim(); int start, end; if (si.endsWith("+")) { String si2 = si.substring(0, si.length()-1).trim(); start = Integer.parseInt(si2); end = MAX_PORT; } else if (si.indexOf('-')>0) { int v = si.indexOf('-'); start = Integer.parseInt(si.substring(0, v).trim()); end = Integer.parseInt(si.substring(v+1).trim()); } else if (si.length()==0) { continue; } else { l.add(new SinglePort(Integer.parseInt(si))); continue; } l.add(new LinearPortRange(start, end)); } if (l.size() == 1) { return l.get(0); } else { return new AggregatePortRange(l); } }  static PortRange fromInteger(int x); static PortRange fromIterable(Iterable<?> c); static PortRange fromString(String s); @SuppressWarnings("rawtypes") static void init(); static final int MAX_PORT; static final PortRange ANY_HIGH_PORT; }