Interface Port

All Superinterfaces:
Normalisable<Port>, org.wiremock.stringparser.ParsedString

public interface Port extends Normalisable<Port>, org.wiremock.stringparser.ParsedString
Represents a valid network port.

An implementation must be immutable (and hence threadsafe)

Implementations must enforce that 1 <= port <= 65,535

Implementations should be equal to any other Port implementation with the same text representation. Implementations are NOT equal if they have different string representations, even if they represent the same port number. For example, Port.parse("00080").equals(Port.of(80)) == false because their string representations differ ("00080" vs "80"), even though both represent port 80. This preserves the original format as it appeared in the URL.

An implementation's toString should return the String used when it was created. For ports created via parse(), this preserves the original format including any leading zeros. For ports created via of(), this returns the canonical form without leading zeros.

An implementation's hashCode() is based on the string representation, ensuring consistency with equals.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    boolean
     
    Returns a Port with the canonical (normalised) string representation of this port number, without any leading zeros.
    static Port
    of(int port)
     
    static Port
    parse(String port)
     

    Methods inherited from interface org.wiremock.stringparser.ParsedString

    toString
  • Method Details

    • getIntValue

      int getIntValue()
    • isNormalForm

      boolean isNormalForm()
      Specified by:
      isNormalForm in interface Normalisable<Port>
    • normalise

      Port normalise()
      Returns a Port with the canonical (normalised) string representation of this port number, without any leading zeros.

      For example, Port.parse("00080").normalise() returns a Port whose toString() is "80".

      If this Port is already in canonical form, returns a Port equal to this one.

      Specified by:
      normalise in interface Normalisable<Port>
      Returns:
      a Port with the canonical string representation
    • parse

      static Port parse(String port) throws IllegalPort
      Throws:
      IllegalPort
    • of

      static Port of(int port) throws IllegalPort
      Throws:
      IllegalPort