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).
TODO: Java 1.8: Make this an interface with default methods.
- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfinal IPortRangecoalesce(IPortRange other) Combines this port range with the given port range if possible.final intcompareTo(IPortRange other) Ordered by from, to, protocol.abstract booleanportsandport rangeswill never equal each other because port range is forced to have a range larger than one port.abstract intgetFrom()Gets the first port number in the range.abstract PortGets the first port number in the range as aPort.final Protocolabstract intgetTo()Gets the last port number in the range.abstract PortGets the last port number in the range as aPort.abstract inthashCode()final booleanoverlaps(IPortRange other) Checks if this port range is of the same protocol and overlaps the given port range.abstract IPortRangesplitAbove(int above) abstract IPortRangesplitBelow(int below) abstract StringtoString()static ValidationResultstatic 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
portsandport rangeswill 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:
compareToin 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
nullif none.
-
splitAbove
- Returns:
- The part of this port range above, and not including, the given port or
nullif 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.
nullwhen they cannot be combined.
- If different protocols are non-overlapping and non-adjacent, returns
-
