com.scalacraft.domain.v2.net

unconstrained

package unconstrained

Visibility
  1. Public
  2. All

Type Members

  1. case class DomainName(labels: String*) extends Product with Serializable

    A DomainName represents a name in the domain name system.

    A DomainName represents a name in the domain name system.

    This class does not constrain the value of the domain name in anyway.

    Unlike the example in Programming in Scala/2e the elements of the domain name are stored in the same order as used, i.e. as www.scalacraft.com, not reversed.

    This implementation is case sensitive which is at variance with the Wikipedia specification. If a convincing use case for case insensitivity arises this could be reconsidered. Expressed in code we have,

    DomainName("WWW") != DomainName("www")
    Pattern Matching

    Pattern matching is supported as the following example demonstrates,

    "example.com" match {
    case DomainName(label1, label2) => label1 :: label2 :: Nil  // List("example", "com")
    case _ => None
    }

    Domain names with invalid labels will also be matched because this class is unconstrained,

    "a.b-" match {
    case DomainName(label1, label2) => label1 :: label2 :: Nil  // List("a", "b-")
    case _ => None
    }

    For now there is no way to match an arbitrary number of domain name labels.

    Implicit Conversions

    Implicit conversions exist which allow an instance of DomainName to be used when either a String or Seq[String] is required.

    def countElements(seq: Seq[String]) = seq.length
    
    val dn = DomainName("www", "example", "com")
    val elemNo = countElements(dn) // 3

    A conversion to an option of the constrained version of this class is also available.

  2. case class IP4Address(byte1: Int, byte2: Int, byte3: Int, byte4: Int) extends Product with Serializable

    An IP4Address represents an IP4 address.

    An IP4Address represents an IP4 address.

    This class does not constrain the value of the address components.

    Pattern Matching

    Pattern matching is supported as the following example demonstrates,

    "192.162.0.9" match {
    case IP4Address(b1, b2, _, _) => Some(b1, b2) // Some(192, 162)
    case _ => None
    }
    Implicit Conversions

    Implicit conversions exist which allow an instance of IP4Address when a String is required.

    val ipa = IP4Address(b1, b2, b3, b4)
    val inet = java.v2.InetAddress.getByName(ipa)

    A conversion to an option of the constrained version of this class is also available.

  3. case class Port(portNumber: Int) extends Product with Serializable

    A Port represents an IP port.

    A Port represents an IP port.

    This class does not constrain the value of the port in anyway.

    Pattern Matching

    Pattern matching is supported as the following examples demonstrate,

    7 match {
      case Port(p) => p // 7
      case _ => None
    }

    The match target can be a string,

    val s: String = ...
      s match {
        case Port(p) => p
        case _ => None
      }
    Implicit Conversions

    Implicit conversions exists which allow an instance of Port to be used when an Int or String is required.

    val port = Port(6006)
    val isa = new InetSocketAddress(p)

    A conversion to an option of the constrained version of this class is also available.

Value Members

  1. object DomainName extends Serializable

  2. object IP4Address extends Serializable

  3. object Port extends Serializable

Ungrouped