A DomainName
represents a name in the domain name system.
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 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 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.
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 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 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.
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,
Pattern Matching
Pattern matching is supported as the following example demonstrates,
Domain names with invalid labels will also be matched because this class is unconstrained,
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 aString
orSeq[String]
is required.A conversion to an option of the constrained version of this class is also available.