com.h3c.util.ip

## Class TcpUdpPort

- java.lang.Object
- - com.h3c.util.cache.CacheableDataType
  - - com.h3c.util.ip.TcpUdpPort

- All Implemented Interfaces:
    Serializable, Comparable<TcpUdpPort>

      public final class TcpUdpPort
      extends CacheableDataType
      implements Comparable<TcpUdpPort>

  Represents a tcp/udp port.

  All constructors for this class are private. Creating instances of `WellKnownPort` is done via the static methods on the class.

  Instances of this class are immutable, making them inherently threadsafe.

  This class overrides `equals(java.lang.Object)` and `hashCode()` so that instances play nicely with the Collection classes.

  This class implements the `Comparable` interface to ensure that a sorted list of ports is presented in an intuitive order.

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static TcpUdpPort` | `UNDETERMINED_TCP` A value representing an undetermined TCP port.
    `static TcpUdpPort` | `UNDETERMINED_UDP` A value representing an undetermined UDP port.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(TcpUdpPort o)` Implements the Comparable interface, to return ports in a natural order.
    `boolean` | `equals(Object o)`
    `String` | `getName()` Returns the descriptive name of the port.
    `int` | `getNumber()` Returns the port number.
    `IpProtocol` | `getProtocol()` Returns the IP Protocol.
    `String` | `getProtocolName()` Returns the short name of the protocol in lowercase.
    `String` | `getShortName()` Returns the short name of the port.
    `int` | `hashCode()`
    `boolean` | `isUndetermined()` Returns true if this instance of port number represents an "undetermined" port.
    `static TcpUdpPort` | `tcpPort(int portNumber)` Delegates to `valueOf(int,IpProtocol)`, specifying the protocol to be TCP.
    `String` | `toString()` Returns a string consisting of the port number followed by a slash character followed by the protocol.
    `static TcpUdpPort` | `udpPort(int portNumber)` Delegates to `valueOf(int,IpProtocol)`, specifying the protocol to be UDP.
    `static TcpUdpPort` | `valueOf(int portNumber, IpProtocol protocol)` Returns an object that represents the value of the tcp/udp port identified by the specified port number and protocol.
    `static TcpUdpPort` | `valueOf(String value)` Returns an object that represents the value of the tcp/udp port identified by the specified string.

    - ### Methods inherited from class com.h3c.util.cache.CacheableDataType

      `getRefQ, keyFromBytes`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### UNDETERMINED_TCP

          public static final TcpUdpPort UNDETERMINED_TCP

      A value representing an undetermined TCP port.

    - #### UNDETERMINED_UDP

          public static final TcpUdpPort UNDETERMINED_UDP

      A value representing an undetermined UDP port.

  - ### Method Detail

    - #### toString

          public String toString()

      Returns a string consisting of the port number followed by a slash character followed by the protocol. E.g. "17/tcp"
      Overrides:
        `toString` in class `Object`
      Returns:
        the port number and protocol as a string

    - #### getName

          public String getName()

      Returns the descriptive name of the port. E.g. "qotd : Quote of the Day"
      Returns:
        the descriptive name

    - #### getShortName

          public String getShortName()

      Returns the short name of the port. E.g. "qotd"
      Returns:
        the short name

    - #### getNumber

          public int getNumber()

      Returns the port number.
      Returns:
        the port number

    - #### getProtocol

          public IpProtocol getProtocol()

      Returns the IP Protocol.
      Returns:
        the protocol

    - #### getProtocolName

          public String getProtocolName()

      Returns the short name of the protocol in lowercase. For example, "tcp" or "udp".
      Returns:
        the short name of the protocol

    - #### isUndetermined

          public boolean isUndetermined()

      Returns true if this instance of port number represents an "undetermined" port.
      Returns:
        true if an "undetermined" port

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### compareTo

          public int compareTo(TcpUdpPort o)

      Implements the Comparable interface, to return ports in a natural order. Sorted by number first, then by protocol.
      Specified by:
        `compareTo` in interface `Comparable<TcpUdpPort>`
      Parameters:
        `o` - the other port to compare to
      Returns:
        an integer value indicating relative ordering
      See Also:
        `Comparable.compareTo(T)`

    - #### valueOf

          public static TcpUdpPort valueOf(String value)

      Returns an object that represents the value of the tcp/udp port identified by the specified string. The format of the string should be `"nnnn/ppp"` where 'nnnn' is the port number, and 'ppp' is the protocol: either `"tcp"` or `"udp"`. For example:

             TcpUdpPort p = TcpUdpPort.valueOf("7/tcp");

      Parameters:
        `value` - the port specification
      Returns:
        an object representing the specified port / protocol combination
      Throws:
        `NullPointerException` - if value is null
        `IllegalArgumentException` - if the string is incorrectly formatted

    - #### valueOf

          public static TcpUdpPort valueOf(int portNumber,
                           IpProtocol protocol)

      Returns an object that represents the value of the tcp/udp port identified by the specified port number and protocol. For example:

             TcpUdpPort p = TcpUdpPort.valueOf(7, IpProtocol.TCP)

      Parameters:
        `portNumber` - the port number
        `protocol` - the protocol (either `IpProtocol.TCP` or `IpProtocol.UDP`)
      Returns:
        an object representing the specified port / protocol combination
      Throws:
        `NullPointerException` - if protocol is null
        `IllegalArgumentException` - if protocol is not TCP or UDP, or if the port number is < 0 or > 65535

    - #### tcpPort

          public static TcpUdpPort tcpPort(int portNumber)

      Delegates to `valueOf(int,IpProtocol)`, specifying the protocol to be TCP.
      Parameters:
        `portNumber` - the port number
      Returns:
        an object representing the TCP port with the specified number
      Throws:
        `IllegalArgumentException` - if the port number is < 0 or > 65535

    - #### udpPort

          public static TcpUdpPort udpPort(int portNumber)

      Delegates to `valueOf(int,IpProtocol)`, specifying the protocol to be UDP.
      Parameters:
        `portNumber` - the port number
      Returns:
        an object representing the UDP port with the specified number
      Throws:
        `IllegalArgumentException` - if the port number is < 0 or > 65535

Copyright © 2014. All Rights Reserved.