object PosInt
The companion object for PosInt
that offers factory methods that
produce PosInt
s, implicit widening conversions from PosInt
to other numeric types, and maximum and minimum constant values for PosInt
.
- Source
- PosInt.scala
- Alphabetic
- By Inheritance
- PosInt
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
val
MaxValue: PosInt
The largest value representable as a positive
Int
, which isPosInt(2147483647)
. -
final
val
MinValue: PosInt
The smallest value representable as a positive
Int
, which isPosInt(1)
. -
implicit macro
def
apply(value: Int): PosInt
A factory method, implemented via a macro, that produces a
PosInt
if passed a validInt
literal, otherwise a compile time error.A factory method, implemented via a macro, that produces a
PosInt
if passed a validInt
literal, otherwise a compile time error.The macro that implements this method will inspect the specified
Int
expression at compile time. If the expression is a positiveInt
literal, i.e., with a value greater than 0, it will return aPosInt
representing that value. Otherwise, the passedInt
expression is either a literal that is 0 or negative, or is not a literal, so this method will give a compiler error.This factory method differs from the
from
factory method in that this method is implemented via a macro that inspectsInt
literals at compile time, whereasfrom
inspectsInt
values at run time.- value
the
Int
literal expression to inspect at compile time, and if positive, to return wrapped in aPosInt
at run time.- returns
the specified, valid
Int
literal value wrapped in aPosInt
. (If the specified expression is not a validInt
literal, the invocation of this method will not compile.)
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
ensuringValid(value: Int): PosInt
A factory/assertion method that produces a
PosInt
given a validInt
value, or throwsAssertionError
, if given an invalidInt
value.A factory/assertion method that produces a
PosInt
given a validInt
value, or throwsAssertionError
, if given an invalidInt
value.Note: you should use this method only when you are convinced that it will always succeed, i.e., never throw an exception. It is good practice to add a comment near the invocation of this method indicating why you think it will always succeed to document your reasoning. If you are not sure an
ensuringValid
call will always succeed, you should use one of the other factory or validation methods provided on this object instead:isValid
,tryingValid
,passOrElse
,goodOrElse
, orrightOrElse
.This method will inspect the passed
Int
value and if it is a positiveInt
, it will return aPosInt
representing that value. Otherwise, the passedInt
value is not positive, so this method will throwAssertionError
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereas this method inspectsInt
values at run time. It differs from a vanillaassert
orensuring
call in that you get something you didn't already have if the assertion succeeds: a type that promises anInt
is positive.- value
the
Int
to inspect, and if positive, return wrapped in aPosInt
.- returns
the specified
Int
value wrapped in aPosInt
, if it is positive, else throwsAssertionError
.
- Exceptions thrown
AssertionError
if the passed value is not positive
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
from(value: Int): Option[PosInt]
A factory method that produces an
Option[PosInt]
given anInt
value.A factory method that produces an
Option[PosInt]
given anInt
value.This method will inspect the passed
Int
value and if it is a positiveInt
, i.e., a positive integer value, it will return aPosInt
representing that value, wrapped in aSome
. Otherwise, the passedInt
value is not positive integer value, so this method will returnNone
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereasfrom
inspectsInt
values at run time.- value
the
Int
to inspect, and if positive, return wrapped in aSome[PosInt]
.- returns
the specified
Int
value wrapped in aSome[PosInt]
, if it is positive, elseNone
.
-
def
fromOrElse(value: Int, default: ⇒ PosInt): PosInt
A factory method that produces a
PosInt
given aInt
value and a defaultPosInt
.A factory method that produces a
PosInt
given aInt
value and a defaultPosInt
.This method will inspect the passed
Int
value and if it is a positiveInt
, i.e., a value greater than 0.0, it will return aPosInt
representing that value. Otherwise, the passedInt
value is 0 or negative, so this method will return the passeddefault
value.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereasfrom
inspectsInt
values at run time.- value
the
Int
to inspect, and if positive, return.- default
the
PosInt
to return if the passedInt
value is not positive.- returns
the specified
Int
value wrapped in aPosInt
, if it is positive, else thedefault
PosInt
value.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
goodOrElse[B](value: Int)(f: (Int) ⇒ B): Or[PosInt, B]
A factory/validation method that produces a
PosInt
, wrapped in aGood
, given a validInt
value, or if the givenInt
is invalid, an error value of typeB
produced by passing the given invalidInt
value to the given functionf
, wrapped in aBad
.A factory/validation method that produces a
PosInt
, wrapped in aGood
, given a validInt
value, or if the givenInt
is invalid, an error value of typeB
produced by passing the given invalidInt
value to the given functionf
, wrapped in aBad
.This method will inspect the passed
Int
value and if it is a positiveInt
, it will return aPosInt
representing that value, wrapped in aGood
. Otherwise, the passedInt
value is not positive, so this method will return a result of typeB
obtained by passing the invalidInt
value to the given functionf
, wrapped in aBad
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereas this method inspectsInt
values at run time.- value
the
Int
to inspect, and if positive, return wrapped in aGood(PosInt)
.- returns
the specified
Int
value wrapped in aGood(PosInt)
, if it is positive, else aBad(f(value))
.
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isValid(value: Int): Boolean
A predicate method that returns true if a given
Int
value is positive.A predicate method that returns true if a given
Int
value is positive.- value
the
Int
to inspect, and if positive, return true.- returns
true if the specified
Int
is positive, else false.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
implicit
val
ordering: Ordering[PosInt]
Implicit Ordering instance.
-
def
passOrElse[E](value: Int)(f: (Int) ⇒ E): Validation[E]
A validation method that produces a
Pass
given a validInt
value, or an error value of typeE
produced by passing the given invalidInt
value to the given functionf
, wrapped in aFail
.A validation method that produces a
Pass
given a validInt
value, or an error value of typeE
produced by passing the given invalidInt
value to the given functionf
, wrapped in aFail
.This method will inspect the passed
Int
value and if it is a positiveInt
, it will return aPass
. Otherwise, the passedInt
value is positive, so this method will return a result of typeE
obtained by passing the invalidInt
value to the given functionf
, wrapped in aFail
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereas this method inspectsInt
values at run time.- value
the
Int
to validate that it is positive.- returns
a
Pass
if the specifiedInt
value is positive, else aFail
containing an error value produced by passing the specifiedInt
to the given functionf
.
-
def
rightOrElse[L](value: Int)(f: (Int) ⇒ L): Either[L, PosInt]
A factory/validation method that produces a
PosInt
, wrapped in aRight
, given a validInt
value, or if the givenInt
is invalid, an error value of typeL
produced by passing the given invalidInt
value to the given functionf
, wrapped in aLeft
.A factory/validation method that produces a
PosInt
, wrapped in aRight
, given a validInt
value, or if the givenInt
is invalid, an error value of typeL
produced by passing the given invalidInt
value to the given functionf
, wrapped in aLeft
.This method will inspect the passed
Int
value and if it is a positiveInt
, it will return aPosInt
representing that value, wrapped in aRight
. Otherwise, the passedInt
value is not positive, so this method will return a result of typeL
obtained by passing the invalidInt
value to the given functionf
, wrapped in aLeft
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereas this method inspectsInt
values at run time.- value
the
Int
to inspect, and if positive, return wrapped in aRight(PosInt)
.- returns
the specified
Int
value wrapped in aRight(PosInt)
, if it is positive, else aLeft(f(value))
.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
tryingValid(value: Int): Try[PosInt]
A factory/validation method that produces a
PosInt
, wrapped in aSuccess
, given a validInt
value, or if the givenInt
is invalid, anAssertionError
, wrapped in aFailure
.A factory/validation method that produces a
PosInt
, wrapped in aSuccess
, given a validInt
value, or if the givenInt
is invalid, anAssertionError
, wrapped in aFailure
.This method will inspect the passed
Int
value and if it is a positiveInt
, it will return aPosInt
representing that value, wrapped in aSuccess
. Otherwise, the passedInt
value is not positive, so this method will return anAssertionError
, wrapped in aFailure
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsInt
literals at compile time, whereas this method inspectsInt
values at run time.- value
the
Int
to inspect, and if positive, return wrapped in aSuccess(PosInt)
.- returns
the specified
Int
value wrapped in aSuccess(PosInt)
, if it is positive, else aFailure(AssertionError)
.
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
implicit
def
widenToDouble(pos: PosInt): Double
Implicit widening conversion from
PosInt
toDouble
.Implicit widening conversion from
PosInt
toDouble
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toDouble
.
-
implicit
def
widenToFloat(pos: PosInt): Float
Implicit widening conversion from
PosInt
toFloat
.Implicit widening conversion from
PosInt
toFloat
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toFloat
.
-
implicit
def
widenToInt(pos: PosInt): Int
Implicit widening conversion from
PosInt
toInt
.Implicit widening conversion from
PosInt
toInt
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
.
-
implicit
def
widenToLong(pos: PosInt): Long
Implicit widening conversion from
PosInt
toLong
.Implicit widening conversion from
PosInt
toLong
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toLong
.
-
implicit
def
widenToNonZeroDouble(pos: PosInt): NonZeroDouble
Implicit widening conversion from
PosInt
toNonZeroDouble
.Implicit widening conversion from
PosInt
toNonZeroDouble
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toDouble
and wrapped in aNonZeroDouble
.
-
implicit
def
widenToNonZeroFloat(pos: PosInt): NonZeroFloat
Implicit widening conversion from
PosInt
toNonZeroFloat
.Implicit widening conversion from
PosInt
toNonZeroFloat
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toFloat
and wrapped in aNonZeroFloat
.
-
implicit
def
widenToNonZeroInt(pos: PosInt): NonZeroInt
Implicit widening conversion from
PosInt
toNonZeroInt
.Implicit widening conversion from
PosInt
toNonZeroInt
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toInt
and wrapped in aNonZeroInt
.
-
implicit
def
widenToNonZeroLong(pos: PosInt): NonZeroLong
Implicit widening conversion from
PosInt
toNonZeroLong
.Implicit widening conversion from
PosInt
toNonZeroLong
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toLong
and wrapped in aNonZeroLong
.
-
implicit
def
widenToPosDouble(pos: PosInt): PosDouble
Implicit widening conversion from
PosInt
toPosDouble
.Implicit widening conversion from
PosInt
toPosDouble
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toDouble
and wrapped in aPosDouble
.
-
implicit
def
widenToPosFloat(pos: PosInt): PosFloat
Implicit widening conversion from
PosInt
toPosFloat
.Implicit widening conversion from
PosInt
toPosFloat
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toFloat
and wrapped in aPosFloat
.
-
implicit
def
widenToPosLong(pos: PosInt): PosLong
Implicit widening conversion from
PosInt
toPosLong
.Implicit widening conversion from
PosInt
toPosLong
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toLong
and wrapped in aPosLong
.
-
implicit
def
widenToPosZDouble(pos: PosInt): PosZDouble
Implicit widening conversion from
PosInt
toPosZDouble
.Implicit widening conversion from
PosInt
toPosZDouble
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toDouble
and wrapped in aPosZDouble
.
-
implicit
def
widenToPosZFloat(pos: PosInt): PosZFloat
Implicit widening conversion from
PosInt
toPosZFloat
.Implicit widening conversion from
PosInt
toPosZFloat
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toFloat
and wrapped in aPosZFloat
.
-
implicit
def
widenToPosZInt(pos: PosInt): PosZInt
Implicit widening conversion from
PosInt
toPosZInt
.Implicit widening conversion from
PosInt
toPosZInt
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toInt
and wrapped in aPosZInt
.
-
implicit
def
widenToPosZLong(pos: PosInt): PosZLong
Implicit widening conversion from
PosInt
toPosZLong
.Implicit widening conversion from
PosInt
toPosZLong
.- pos
the
PosInt
to widen- returns
the
Int
value underlying the specifiedPosInt
, widened toLong
and wrapped in aPosZLong
.
Deprecated Value Members
-
val
posIntOrd: Ordering[PosInt]
The formerly implicit
posIntOrd
field has been deprecated and will be removed in a future version of ScalaTest. Please use theordering
field instead.The formerly implicit
posIntOrd
field has been deprecated and will be removed in a future version of ScalaTest. Please use theordering
field instead.- Annotations
- @deprecated
- Deprecated
The formerly implicit posIntOrd field has been deprecated and will be removed in a future version of ScalaTest. Please use the ordering field instead.