class NetUtils {

	public static Iterator<Integer> getPortRangeFromString(String rangeDefinition) throws NumberFormatException {
		final String[] ranges = rangeDefinition.trim().split(",");
		List<Iterator<Integer>> iterators = new ArrayList<>(ranges.length);
		for(String rawRange: ranges) {
			Iterator<Integer> rangeIterator = null;
			String range = rawRange.trim();
			int dashIdx = range.indexOf('-');
			if (dashIdx == -1) {
				// only one port in range:
				rangeIterator = Iterators.singletonIterator(Integer.valueOf(range));
			} else {
				// evaluate range
				final int start = Integer.valueOf(range.substring(0, dashIdx));
				final int end = Integer.valueOf(range.substring(dashIdx+1, range.length()));
				rangeIterator = new Iterator<Integer>() {
					int i = start;
					@Override
					public boolean hasNext() {
						return i <= end;
					}

					@Override
					public Integer next() {
						return i++;
					}

					@Override
					public void remove() {
						throw new UnsupportedOperationException("Remove not supported");
					}
				};
			}
			iterators.add(rangeIterator);
		}
		return Iterators.concat(iterators.iterator());
	}

}