package tools;

/** Test ports.
 * @author	Louis Royer
 * @author	Flavien Haas
 * @author	JS Auge
 * @version	1.0
 */
public abstract class PortRange {

	protected int portMax;
	protected int portMin;
	protected int defaultPort;
	protected String type;

	/** Port range constructor
	 * @param portMin	minimum port
	 * @param portMax	maximum port
	 * @param defaultPort	default port
	 * @param type	type of range
	 */
	public PortRange(int portMin, int portMax, int defaultPort, String type) {
		this.portMax = portMax;
		this.portMin = portMin;
		this.defaultPort = defaultPort;
		this.type = type;
	}

	/** test if port given correspond a range : registered ports, can be used without superuser privileges
	 * @return	true if port was valid
	 */
	public boolean isPortInRange(int port) {
		return ((port >= portMin) && (port <= portMax));
	}

	/** To String
	 * @return	String representation
	 */
	 public String toString() {
		 return "default " + type + "port: " + defaultPort + "(range: " + portMin + " -> " + portMax + ")";
	 }

	/** Default port getter
	 * @return	default port
	 */
	 public int getDefaultPort() {
		 return defaultPort;
	 }
}
