java.lang.Object
com.aoapps.net.IPortRange
- All Implemented Interfaces:
Serializable
,Comparable<IPortRange>
Something that can give a port range.
A single port must be represented by Port
while a port range must use PortRange
.
Port
and PortRange
are compatible with
equals(java.lang.Object)
, hashCode()
,
and compareTo(com.aoapps.net.IPortRange)
.
Java 1.8: Make this an interface with default methods.
- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal IPortRange
coalesce
(IPortRange other) Combines this port range with the given port range if possible.final int
compareTo
(IPortRange other) Ordered by from, to, protocol.abstract boolean
ports
andport ranges
will never equal each other because port range is forced to have a range larger than one port.abstract int
getFrom()
Gets the first port number in the range.abstract Port
Gets the first port number in the range as aPort
.final Protocol
abstract int
getTo()
Gets the last port number in the range.abstract Port
Gets the last port number in the range as aPort
.abstract int
hashCode()
final boolean
overlaps
(IPortRange other) Checks if this port range is of the same protocol and overlaps the given port range.abstract IPortRange
splitAbove
(int above) abstract IPortRange
splitBelow
(int below) abstract String
toString()
static ValidationResult
static IPortRange
-
Field Details
-
MIN_PORT
public static final int MIN_PORT- See Also:
-
MAX_PORT
public static final int MAX_PORT- See Also:
-
-
Method Details
-
validate
- See Also:
-
valueOf
- Throws:
ValidationException
- See Also:
-
equals
ports
andport ranges
will never equal each other because port range is forced to have a range larger than one port. -
hashCode
public abstract int hashCode() -
compareTo
Ordered by from, to, protocol. The fact that is ordered by "from" is used to break loops, this ordering must not be changed without adjusting other code.- Specified by:
compareTo
in interfaceComparable<IPortRange>
-
toString
-
getProtocol
-
getFrom
public abstract int getFrom()Gets the first port number in the range. -
getFromPort
Gets the first port number in the range as aPort
. -
getTo
public abstract int getTo()Gets the last port number in the range. -
getToPort
Gets the last port number in the range as aPort
. -
overlaps
Checks if this port range is of the same protocol and overlaps the given port range. -
splitBelow
- Returns:
- The part of this port range below, and not including, the given port or
null
if none.
-
splitAbove
- Returns:
- The part of this port range above, and not including, the given port or
null
if none.
-
coalesce
Combines this port range with the given port range if possible.- If different protocols are non-overlapping and non-adjacent, returns
null
. - If the combined range equals
this
, returnsthis
. - If the combined range equals
other
, returnsother
. - Otherwise, returns a new port range covering the full range.
- Returns:
- When the protocols match and port ranges overlap or are adjacent,
returns a port range spanning both.
null
when they cannot be combined.
- If different protocols are non-overlapping and non-adjacent, returns
-