package org.kne.cloud.network.scanner;

import java.math.BigInteger;
import java.util.Objects;

public class PortRange {
	private int begin;
	public PortRange(int begin, int end) {
		super();
		checkRange(begin,end);
		this.begin = begin;
		this.end = end;
	}
	public PortRange(int port) {
		this(port,port);
	}
	private void checkRange(int begin2, int end2) {
		if(end2<begin2)
			throw new IllegalArgumentException("begin is bigger than end!");
		
	}
	private int end;
	public int getBegin() {
		return begin;
	}
	public int getEnd() {
		return end;
	}
	@Override
	public String toString() {
		return begin + "~" + end ;
	}
	@Override
	public int hashCode() {
		return Objects.hash(begin, end);
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PortRange other = (PortRange) obj;
		return begin == other.begin && end == other.end;
	}
	public BigInteger getElementCount() {
		return BigInteger.valueOf(end).subtract(BigInteger.valueOf(begin)).add(BigInteger.valueOf(1));
	}
	
}
