com.h3c.util.ip

## Class TcpUdpPortPair

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

- All Implemented Interfaces:
    Serializable, Comparable<TcpUdpPortPair>

      public final class TcpUdpPortPair
      extends CacheableDataType
      implements Comparable<TcpUdpPortPair>

  Represents a pair of ports defined by a source `IpAddress` and `TcpUdpPort` and a destination `IpAddress` and `TcpUdpPort`.

  All constructors for this class are private. Creating instances of `TcpUdpPortPair` is done via the static `valueOf(com.h3c.util.ip.IpAddress, com.h3c.util.ip.TcpUdpPort, com.h3c.util.ip.IpAddress, com.h3c.util.ip.TcpUdpPort)` methods on the class.

  Instances of this class are immutable, making them inherently thread-safe.

  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 pairs is presented in an intuitive order.

  See Also:
    Serialized Form

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(TcpUdpPortPair o)` This implementation of the `Comparable` interface sorts by source IP/port first, then destination IP/port.
    `boolean` | `equals(Object o)`
    `IpAddress` | `getDestinationIp()` Returns the IP address of the destination.
    `TcpUdpPort` | `getDestinationPort()` Returns the port of the destination.
    `IpAddress` | `getSourceIp()` Returns the IP address of the source.
    `TcpUdpPort` | `getSourcePort()` Returns the port of the source.
    `int` | `hashCode()`
    `String` | `toShortString()` Returns the string representation of this port pair, without including the well-known names of the ports.
    `String` | `toString()` Returns the string representation of this port pair, including the well-known names of the ports.
    `static TcpUdpPortPair` | `valueOf(IpAddress sourceIp, TcpUdpPort sourcePort, IpAddress destIp, TcpUdpPort destPort)` Returns a `TcpUdpPortPair` object that represents the source and destination ports specified by the given IP addresses and TCP/UDP ports.

    - ### 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`

- - ### Method Detail

    - #### getSourceIp

          public IpAddress getSourceIp()

      Returns the IP address of the source.
      Returns:
        the source IP address

    - #### getSourcePort

          public TcpUdpPort getSourcePort()

      Returns the port of the source.
      Returns:
        the source port

    - #### getDestinationIp

          public IpAddress getDestinationIp()

      Returns the IP address of the destination.
      Returns:
        the destination IP address

    - #### getDestinationPort

          public TcpUdpPort getDestinationPort()

      Returns the port of the destination.
      Returns:
        the destination port

    - #### toString

          public String toString()

      Returns the string representation of this port pair, including the well-known names of the ports.
      Overrides:
        `toString` in class `Object`
      Returns:
        the string representation
      See Also:
        `toShortString()`

    - #### toShortString

          public String toShortString()

      Returns the string representation of this port pair, without including the well-known names of the ports.
      Returns:
        the short string representation
      See Also:
        `toString()`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### compareTo

          public int compareTo(TcpUdpPortPair o)

      This implementation of the `Comparable` interface sorts by source IP/port first, then destination IP/port.
      Specified by:
        `compareTo` in interface `Comparable<TcpUdpPortPair>`
      Parameters:
        `o` - the other pair
      Returns:
        a number indicating relative ordering

    - #### valueOf

          public static TcpUdpPortPair valueOf(IpAddress sourceIp,
                               TcpUdpPort sourcePort,
                               IpAddress destIp,
                               TcpUdpPort destPort)

      Returns a `TcpUdpPortPair` object that represents the source and destination ports specified by the given IP addresses and TCP/UDP ports.
      Parameters:
        `sourceIp` - the IP address of the source
        `sourcePort` - the TCP/UDP port of the source
        `destIp` - the IP address of the destination
        `destPort` - the TCP/UDP port of the destination
      Returns:
        the source / destination port pair
      Throws:
        `NullPointerException` - if any of the parameters are null
        `IllegalArgumentException` - if the port protocols don't match

Copyright © 2014. All Rights Reserved.