Skip to content

Commit

Permalink
Scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Oct 13, 2020
1 parent a06a967 commit 75898a0
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 66 deletions.
6 changes: 2 additions & 4 deletions jvm/src/main/scala/com/comcast/ip4s/HostnamePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import cats.effect.Sync

private[ip4s] trait HostnamePlatform { self: Hostname =>

/**
* Resolves this hostname to an ip address using the platform DNS resolver.
/** Resolves this hostname to an ip address using the platform DNS resolver.
*
* If the hostname cannot be resolved, a `None` is returned.
*
Expand All @@ -41,8 +40,7 @@ private[ip4s] trait HostnamePlatform { self: Hostname =>
}
}

/**
* Resolves this hostname to all ip addresses known to the platform DNS resolver.
/** Resolves this hostname to all ip addresses known to the platform DNS resolver.
*
* If the hostname cannot be resolved, a `None` is returned.
*
Expand Down
21 changes: 7 additions & 14 deletions shared/src/main/scala/com/comcast/ip4s/Cidr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import scala.util.hashing.MurmurHash3

import cats.{Order, Show}

/**
* Classless Inter-Domain Routing address, which represents an IP address and its routing prefix.
/** Classless Inter-Domain Routing address, which represents an IP address and its routing prefix.
*
* @param address IP address for which this CIDR refers to
* @param prefixBits number of leading 1s in the routing mask
Expand All @@ -31,8 +30,7 @@ final class Cidr[+A <: IpAddress] private (val address: A, val prefixBits: Int)
def copy[AA >: A <: IpAddress](address: AA = this.address, prefixBits: Int = this.prefixBits): Cidr[AA] =
Cidr[AA](address, prefixBits)

/**
* Returns the routing mask.
/** Returns the routing mask.
*
* @example {{{
* scala> Cidr(ipv4"10.11.12.13", 8).mask
Expand All @@ -43,8 +41,7 @@ final class Cidr[+A <: IpAddress] private (val address: A, val prefixBits: Int)
*/
def mask: A = address.transform(_ => Ipv4Address.mask(prefixBits), _ => Ipv6Address.mask(prefixBits))

/**
* Returns the routing prefix.
/** Returns the routing prefix.
*
* Note: the routing prefix also serves as the first address in the range described by this CIDR.
*
Expand All @@ -60,8 +57,7 @@ final class Cidr[+A <: IpAddress] private (val address: A, val prefixBits: Int)
def prefix: A =
address.transform(_.masked(Ipv4Address.mask(prefixBits)), _.masked(Ipv6Address.mask(prefixBits)))

/**
* Returns the last address in the range described by this CIDR.
/** Returns the last address in the range described by this CIDR.
*
* @example {{{
* scala> Cidr(ipv4"10.11.12.13", 8).last
Expand All @@ -75,15 +71,13 @@ final class Cidr[+A <: IpAddress] private (val address: A, val prefixBits: Int)
def last: A =
address.transform(_.maskedLast(Ipv4Address.mask(prefixBits)), _.maskedLast(Ipv6Address.mask(prefixBits)))

/**
* Returns the number of addresses in the range described by this CIDR.
/** Returns the number of addresses in the range described by this CIDR.
*/
def totalIps: BigInt = {
BigInt(1) << (address.fold(_ => 32, _ => 128) - prefixBits)
}

/**
* Returns a predicate which tests if the supplied address is in the range described by this CIDR.
/** Returns a predicate which tests if the supplied address is in the range described by this CIDR.
*
* @example {{{
* scala> Cidr(ipv4"10.11.12.13", 8).contains(ipv4"10.100.100.100")
Expand Down Expand Up @@ -122,8 +116,7 @@ final class Cidr[+A <: IpAddress] private (val address: A, val prefixBits: Int)

object Cidr {

/**
* Constructs a CIDR from the supplied IP address and prefix bit count.
/** Constructs a CIDR from the supplied IP address and prefix bit count.
* Note if `prefixBits` is less than 0, the built `Cidr` will have `prefixBits` set to 0. Similarly,
* if `prefixBits` is greater than the bit length of the address, it will be set to the bit length of the address.
*/
Expand Down
6 changes: 2 additions & 4 deletions shared/src/main/scala/com/comcast/ip4s/Hostname.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import scala.util.hashing.MurmurHash3

import cats.{Order, Show}

/**
* RFC1123 compliant hostname.
/** RFC1123 compliant hostname.
*
* A hostname contains one or more labels, where each label consists of letters A-Z, a-z, digits 0-9, or a dash.
* A label may not start or end in a dash and may not exceed 63 characters in length. Labels are separated by
Expand All @@ -46,8 +45,7 @@ final class Hostname private (val labels: List[Hostname.Label], override val toS

object Hostname {

/**
* Label component of a hostname.
/** Label component of a hostname.
*
* A label consists of letters A-Z, a-z, digits 0-9, or a dash. A label may not start or end in a
* dash and may not exceed 63 characters in length.
Expand Down
3 changes: 1 addition & 2 deletions shared/src/main/scala/com/comcast/ip4s/IDN.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import scala.util.hashing.MurmurHash3

import cats.{Order, Show}

/**
* Internationalized domain name, as specified by RFC3490 and RFC5891.
/** Internationalized domain name, as specified by RFC3490 and RFC5891.
*
* This type models internationalized hostnames. An IDN provides unicode labels, a unicode string form,
* and an ASCII hostname form.
Expand Down
45 changes: 15 additions & 30 deletions shared/src/main/scala/com/comcast/ip4s/IpAddress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ object IpVersion {
case object V6 extends IpVersion
}

/**
* Immutable and safe representation of an IP address, either V4 or V6.
/** Immutable and safe representation of an IP address, either V4 or V6.
*
* === Construction ===
*
Expand Down Expand Up @@ -88,8 +87,7 @@ sealed abstract class IpAddress extends IpAddressPlatform with Ordered[IpAddress
/** Gets the IP address before this address, with underflow from minimum value to the maximum value. */
def previous: IpAddress

/**
* Converts this address to a string form that is compatible for use in a URI per RFC3986
/** Converts this address to a string form that is compatible for use in a URI per RFC3986
* (namely, IPv6 addresses are rendered in condensed form and surrounded by brackets).
*/
def toUriString: String
Expand Down Expand Up @@ -180,8 +178,7 @@ final class Ipv4Address private (protected val bytes: Array[Byte]) extends IpAdd
override def isSourceSpecificMulticast: Boolean =
this >= Ipv4Address.SourceSpecificMulticastRangeStart && this <= Ipv4Address.SourceSpecificMulticastRangeEnd

/**
* Converts this V4 address to a compat V6 address, where the first 12 bytes are all zero
/** Converts this V4 address to a compat V6 address, where the first 12 bytes are all zero
* and the last 4 bytes contain the bytes of this V4 address.
*/
def toCompatV6: Ipv6Address = {
Expand All @@ -193,8 +190,7 @@ final class Ipv4Address private (protected val bytes: Array[Byte]) extends IpAdd
Ipv6Address.fromBytes(compat).get
}

/**
* Converts this V4 address to a mapped V6 address, where the first 10 bytes are all zero,
/** Converts this V4 address to a mapped V6 address, where the first 10 bytes are all zero,
* the next two bytes are `ff`, and the last 4 bytes contain the bytes of this V4 address.
*/
def toMappedV6: Ipv6Address = {
Expand All @@ -208,8 +204,7 @@ final class Ipv4Address private (protected val bytes: Array[Byte]) extends IpAdd
Ipv6Address.fromBytes(mapped).get
}

/**
* Applies the supplied mask to this address.
/** Applies the supplied mask to this address.
*
* @example {{{
* scala> ipv4"192.168.29.1".masked(ipv4"255.255.0.0")
Expand All @@ -219,8 +214,7 @@ final class Ipv4Address private (protected val bytes: Array[Byte]) extends IpAdd
def masked(mask: Ipv4Address): Ipv4Address =
Ipv4Address.fromLong(toLong & mask.toLong)

/**
* Computes the last address in the network identified by applying the supplied mask to this address.
/** Computes the last address in the network identified by applying the supplied mask to this address.
*
* @example {{{
* scala> ipv4"192.168.29.1".maskedLast(ipv4"255.255.0.0")
Expand Down Expand Up @@ -269,8 +263,7 @@ object Ipv4Address {
} else None
}

/**
* Constructs an IPv4 address from a 4-element byte array.
/** Constructs an IPv4 address from a 4-element byte array.
* Returns `Some` when array is exactly 4-bytes and `None` otherwise.
*/
def fromBytes(bytes: Array[Byte]): Option[Ipv4Address] =
Expand All @@ -280,8 +273,7 @@ object Ipv4Address {
private def unsafeFromBytes(bytes: Array[Byte]): Ipv4Address =
new Ipv4Address(bytes)

/**
* Constructs an address from the specified 4 bytes.
/** Constructs an address from the specified 4 bytes.
*
* Each byte is represented as an `Int` to avoid having to manually call `.toByte` on each value --
* the `toByte` call is done inside this function.
Expand All @@ -306,8 +298,7 @@ object Ipv4Address {
unsafeFromBytes(bytes)
}

/**
* Computes a mask by setting the first / left-most `n` bits high.
/** Computes a mask by setting the first / left-most `n` bits high.
*
* @example {{{
* scala> Ipv4Address.mask(16)
Expand Down Expand Up @@ -385,8 +376,7 @@ final class Ipv6Address private (protected val bytes: Array[Byte]) extends IpAdd
str.toString
}

/**
* Converts this address to a string of form `x:x:x:x:x:x:a.b.c.d` where
/** Converts this address to a string of form `x:x:x:x:x:x:a.b.c.d` where
* each `x` represents 16-bits and `a.b.c.d` is IPv4 dotted decimal notation.
* Consecutive 0 `x` fields are condensed with `::`.
*
Expand Down Expand Up @@ -442,8 +432,7 @@ final class Ipv6Address private (protected val bytes: Array[Byte]) extends IpAdd
override def isSourceSpecificMulticast: Boolean =
this >= Ipv6Address.SourceSpecificMulticastRangeStart && this <= Ipv6Address.SourceSpecificMulticastRangeEnd

/**
* Applies the supplied mask to this address.
/** Applies the supplied mask to this address.
*
* @example {{{
* scala> ipv6"ff3b::1".masked(ipv6"fff0::")
Expand All @@ -453,8 +442,7 @@ final class Ipv6Address private (protected val bytes: Array[Byte]) extends IpAdd
def masked(mask: Ipv6Address): Ipv6Address =
Ipv6Address.fromBigInt(toBigInt & mask.toBigInt)

/**
* Computes the last address in the network identified by applying the supplied mask to this address.
/** Computes the last address in the network identified by applying the supplied mask to this address.
*
* @example {{{
* scala> ipv6"ff3b::1".maskedLast(ipv6"fff0::")
Expand Down Expand Up @@ -571,8 +559,7 @@ object Ipv6Address {
case _ => None
}

/**
* Constructs an IPv6 address from a 16-element byte array.
/** Constructs an IPv6 address from a 16-element byte array.
* Returns `Some` when array is exactly 16-bytes and `None` otherwise.
*/
def fromBytes(bytes: Array[Byte]): Option[Ipv6Address] =
Expand All @@ -582,8 +569,7 @@ object Ipv6Address {
private def unsafeFromBytes(bytes: Array[Byte]): Ipv6Address =
new Ipv6Address(bytes)

/**
* Constructs an address from the specified 16 bytes.
/** Constructs an address from the specified 16 bytes.
*
* Each byte is represented as an `Int` to avoid having to manually call `.toByte` on each value -- the `toByte` call is done inside this function.
*/
Expand Down Expand Up @@ -636,8 +622,7 @@ object Ipv6Address {
unsafeFromBytes(bytes)
}

/**
* Computes a mask by setting the first / left-most `n` bits high.
/** Computes a mask by setting the first / left-most `n` bits high.
*
* @example {{{
* scala> Ipv6Address.mask(32)
Expand Down
6 changes: 2 additions & 4 deletions shared/src/main/scala/com/comcast/ip4s/Multicast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package com.comcast.ip4s

import cats.{Order, Show}

/**
* Witness that the wrapped address of type `A` is a multicast address.
/** Witness that the wrapped address of type `A` is a multicast address.
*
* An instance of `Multicast` is typically created by either calling `Multicast.apply` or by using
* the `asMulticast` method on `IpAddress`.
Expand All @@ -46,8 +45,7 @@ object Multicast {
Show.fromToString[J[A]]
}

/**
* Witnesses that the wrapped address of type `A` is a source specific multicast address.
/** Witnesses that the wrapped address of type `A` is a source specific multicast address.
*
* An instance of `SourceSpecificMulticast` is typically created by either calling `Multicast.apply`
* or by using the `asSourceSpecificMulticast` method on `IpAddress`.
Expand Down
6 changes: 2 additions & 4 deletions shared/src/main/scala/com/comcast/ip4s/MulticastJoin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package com.comcast.ip4s

import cats.{Order, Show}

/**
* Represents a join of a multicast group.
/** Represents a join of a multicast group.
*
* This is represented as an ADT consisting of two constructors, [[AnySourceMulticastJoin]] and
* [[SourceSpecificMulticastJoin]]. These constructors are provided as top level types to allow
Expand All @@ -41,8 +40,7 @@ sealed abstract class MulticastJoin[+A <: IpAddress] extends Product with Serial
/** Narrows to a `SourceSpecificMulticastJoin`. */
def asSsm: Option[SourceSpecificMulticastJoin[A]] = fold(_ => None, Some(_))

/**
* Returns the source address and group address. If this join is an any-source join, `None` is
/** Returns the source address and group address. If this join is an any-source join, `None` is
* returned for the source. Otherwise, this join is a source specific join and `Some(src)` is
* returned for the source.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package com.comcast.ip4s

import cats.{Order, Show}

/**
* A multicast join of the specified type and a port number. Used to describe UDP join of a multicast group.
/** A multicast join of the specified type and a port number. Used to describe UDP join of a multicast group.
*/
final case class MulticastSocketAddress[J[+x <: IpAddress] <: MulticastJoin[x], +A <: IpAddress](
join: J[A],
Expand Down
3 changes: 1 addition & 2 deletions shared/src/main/scala/com/comcast/ip4s/SocketAddress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package com.comcast.ip4s

import cats.{Order, Show}

/**
* An IP address of the specified type and a port number. Used to describe the source or destination of a socket.
/** An IP address of the specified type and a port number. Used to describe the source or destination of a socket.
*/
final case class SocketAddress[+A <: IpAddress](ip: A, port: Port) extends SocketAddressPlatform[A] {
override def toString: String =
Expand Down

0 comments on commit 75898a0

Please sign in to comment.