Skip to content

Commit

Permalink
Change layout of the types package
Browse files Browse the repository at this point in the history
Closes #416
  • Loading branch information
fthomas committed Feb 1, 2018
1 parent cdfbdd4 commit 311a74d
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 27 deletions.
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ lazy val moduleJvmSettings = Def.settings(
ProblemFilters.exclude[DirectMissingMethodProblem](
"eu.timepit.refined.NumericValidate.moduloValidateNat"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"eu.timepit.refined.NumericValidate.moduloValidateWit")
"eu.timepit.refined.NumericValidate.moduloValidateWit"),
ProblemFilters.exclude[DirectMissingMethodProblem]("eu.timepit.refined.types.*"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("eu.timepit.refined.types.*"),
ProblemFilters.exclude[MissingClassProblem]("eu.timepit.refined.types.*"),
ProblemFilters.exclude[MissingTypesProblem]("eu.timepit.refined.types.*"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("eu.timepit.refined.types.*")
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import eu.timepit.refined.api.{Refined, RefinedTypeOps}
import eu.timepit.refined.char.{LowerCase, UpperCase}

/** Module for `Char` refined types. */
object char extends CharTypes

trait CharTypes {
object char {

/** A `Char` that is a lower case character. */
type LowerCaseChar = Char Refined LowerCase
Expand All @@ -18,3 +16,11 @@ trait CharTypes {

object UpperCaseChar extends RefinedTypeOps[UpperCaseChar, Char]
}

trait CharTypes {
final type LowerCaseChar = char.LowerCaseChar
final val LowerCaseChar = char.LowerCaseChar

final type UpperCaseChar = char.UpperCaseChar
final val UpperCaseChar = char.UpperCaseChar
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import eu.timepit.refined.numeric.Interval
import eu.timepit.refined.string.{IPv4, MatchesRegex, StartsWith}

/** Module for refined types that are related to the Internet protocol suite. */
object net extends NetTypes

trait NetTypes {
object net {

/** An `Int` in the range from 0 to 65535 representing a port number. */
type PortNumber = Int Refined Interval.Closed[W.`0`.T, W.`65535`.T]
Expand Down Expand Up @@ -69,24 +67,78 @@ trait NetTypes {
type Rfc2544Benchmark = String Refined Rfc2544BenchmarkSpec

/** A `String` representing a valid IPv4 in a private network according to RFC1918, RFC5737, RFC3927 or RFC2544 */
type PrivateNetwork = String Refined (Rfc1918PrivateSpec Or
Rfc5737TestnetSpec Or
Rfc3927LocalLinkSpec Or
Rfc2544BenchmarkSpec)
type PrivateNetwork =
String Refined (Rfc1918PrivateSpec Or Rfc5737TestnetSpec Or Rfc3927LocalLinkSpec Or Rfc2544BenchmarkSpec)

object PrivateNetworks {
type Rfc1918ClassAPrivateSpec = IPv4 And StartsWith[W.`"10."`.T]

type Rfc1918ClassAPrivateSpec =
IPv4 And StartsWith[W.`"10."`.T]

type Rfc1918ClassBPrivateSpec =
IPv4 And MatchesRegex[W.`"^172\\\\.(15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31).+"`.T]
type Rfc1918ClassCPrivateSpec = IPv4 And StartsWith[W.`"192.168."`.T]

type Rfc1918ClassCPrivateSpec =
IPv4 And StartsWith[W.`"192.168."`.T]

type Rfc1918PrivateSpec =
Rfc1918ClassAPrivateSpec Or Rfc1918ClassBPrivateSpec Or Rfc1918ClassCPrivateSpec
type Rfc5737Testnet1Spec = IPv4 And StartsWith[W.`"192.0.2."`.T]
type Rfc5737Testnet2Spec = IPv4 And StartsWith[W.`"198.51.100."`.T]
type Rfc5737Testnet3Spec = IPv4 And StartsWith[W.`"203.0.113."`.T]
type Rfc5737TestnetSpec = Rfc5737Testnet1Spec Or Rfc5737Testnet2Spec Or Rfc5737Testnet3Spec
type Rfc3927LocalLinkSpec = IPv4 And StartsWith[W.`"169.254."`.T]

type Rfc5737Testnet1Spec =
IPv4 And StartsWith[W.`"192.0.2."`.T]

type Rfc5737Testnet2Spec =
IPv4 And StartsWith[W.`"198.51.100."`.T]

type Rfc5737Testnet3Spec =
IPv4 And StartsWith[W.`"203.0.113."`.T]

type Rfc5737TestnetSpec =
Rfc5737Testnet1Spec Or Rfc5737Testnet2Spec Or Rfc5737Testnet3Spec

type Rfc3927LocalLinkSpec =
IPv4 And StartsWith[W.`"169.254."`.T]

type Rfc2544BenchmarkSpec =
IPv4 And Or[StartsWith[W.`"198.18."`.T], StartsWith[W.`"198.19."`.T]]
}
}

trait NetTypes {
final type PortNumber = net.PortNumber
final val PortNumber = net.PortNumber

final type SystemPortNumber = net.SystemPortNumber
final val SystemPortNumber = net.SystemPortNumber

final type UserPortNumber = net.UserPortNumber
final val UserPortNumber = net.UserPortNumber

final type DynamicPortNumber = net.DynamicPortNumber
final val DynamicPortNumber = net.DynamicPortNumber

final type NonSystemPortNumber = net.NonSystemPortNumber
final val NonSystemPortNumber = net.NonSystemPortNumber

final type Rfc1918ClassAPrivate = net.Rfc1918ClassAPrivate

final type Rfc1918ClassBPrivate = net.Rfc1918ClassBPrivate

final type Rfc1918ClassCPrivate = net.Rfc1918ClassCPrivate

final type Rfc1918Private = net.Rfc1918Private

final type Rfc5737Testnet1 = net.Rfc5737Testnet1

final type Rfc5737Testnet2 = net.Rfc5737Testnet2

final type Rfc5737Testnet3 = net.Rfc5737Testnet3

final type Rfc5737Testnet = net.Rfc5737Testnet

final type Rfc3927LocalLink = net.Rfc3927LocalLink

final type Rfc2544Benchmark = net.Rfc2544Benchmark

final type PrivateNetwork = net.PrivateNetwork
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import eu.timepit.refined.api.{Refined, RefinedTypeOps}
import eu.timepit.refined.numeric.{Negative, NonNegative, NonPositive, Positive}

/** Module for numeric refined types. */
object numeric extends NumericTypes

trait NumericTypes {
object numeric {

/** An `Int` in the range from 1 to `Int.MaxValue`. */
type PosInt = Int Refined Positive
Expand Down Expand Up @@ -88,3 +86,53 @@ trait NumericTypes {

object NonPosDouble extends RefinedTypeOps.Numeric[NonPosDouble, Double]
}

trait NumericTypes {
final type PosInt = numeric.PosInt
final val PosInt = numeric.PosInt

final type NonNegInt = numeric.NonNegInt
final val NonNegInt = numeric.NonNegInt

final type NegInt = numeric.NegInt
final val NegInt = numeric.NegInt

final type NonPosInt = numeric.NonPosInt
final val NonPosInt = numeric.NonPosInt

final type PosLong = numeric.PosLong
final val PosLong = numeric.PosLong

final type NonNegLong = numeric.NonNegLong
final val NonNegLong = numeric.NonNegLong

final type NegLong = numeric.NegLong
final val NegLong = numeric.NegLong

final type NonPosLong = numeric.NonPosLong
final val NonPosLong = numeric.NonPosLong

final type PosFloat = numeric.PosFloat
final val PosFloat = numeric.PosFloat

final type NonNegFloat = numeric.NonNegFloat
final val NonNegFloat = numeric.NonNegFloat

final type NegFloat = numeric.NegFloat
final val NegFloat = numeric.NegFloat

final type NonPosFloat = numeric.NonPosFloat
final val NonPosFloat = numeric.NonPosFloat

final type PosDouble = numeric.PosDouble
final val PosDouble = numeric.PosDouble

final type NonNegDouble = numeric.NonNegDouble
final val NonNegDouble = numeric.NonNegDouble

final type NegDouble = numeric.NegDouble
final val NegDouble = numeric.NegDouble

final type NonPosDouble = numeric.NonPosDouble
final val NonPosDouble = numeric.NonPosDouble
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.string.MatchesRegex

/** Module for `String` refined types. */
object string extends StringTypes

trait StringTypes {
object string {

/** A `String` that is not empty. */
type NonEmptyString = String Refined NonEmpty
Expand All @@ -20,3 +18,11 @@ trait StringTypes {

object TrimmedString extends RefinedTypeOps[TrimmedString, String]
}

trait StringTypes {
final type NonEmptyString = string.NonEmptyString
final val NonEmptyString = string.NonEmptyString

final type TrimmedString = string.TrimmedString
final val TrimmedString = string.TrimmedString
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import eu.timepit.refined.api.{Refined, RefinedTypeOps}
import eu.timepit.refined.numeric.Interval

/** Module for date and time related refined types. */
object time extends TimeTypes

trait TimeTypes {
object time {

/** An `Int` in the range from 1 to 12 representing the month-of-year. */
type Month = Int Refined Interval.Closed[W.`1`.T, W.`12`.T]
Expand Down Expand Up @@ -42,3 +40,23 @@ trait TimeTypes {

object Millis extends RefinedTypeOps[Millis, Int]
}

trait TimeTypes {
final type Month = time.Month
final val Month = time.Month

final type Day = time.Day
final val Day = time.Day

final type Hour = time.Hour
final val Hour = time.Hour

final type Minute = time.Minute
final val Minute = time.Minute

final type Second = time.Second
final val Second = time.Second

final type Millis = time.Millis
final val Millis = time.Millis
}

0 comments on commit 311a74d

Please sign in to comment.