Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make almost all the case classes extend AnyVal #178

Merged
merged 3 commits into from
Aug 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.twitter.bijection

case class EnglishInt(get: String)
case class EnglishInt(get: String) extends AnyVal

object EnglishInt {
implicit val bijectionToInt: Bijection[Int, EnglishInt] = new AbstractBijection[Int, EnglishInt] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package com.twitter.bijection

object NumberSystems {
case class BinaryString(get: String)
case class HexString(get: String)
case class OctalString(get: String)
case class BinaryString(get: String) extends AnyVal
case class HexString(get: String) extends AnyVal
case class OctalString(get: String) extends AnyVal
case class ArbitBaseString(get: String, base: Int)

implicit val binary: Bijection[Int, BinaryString] = new AbstractBijection[Int, BinaryString] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import com.twitter.bijection.Inversion.attempt
import scala.util.Try

trait StringInjections extends NumericInjections {
import StringCodec.URLEncodedString

implicit val utf8: Injection[String, Array[Byte]] = withEncoding("UTF-8")

def withEncoding(encoding: String): Injection[String, Array[Byte]] =
Expand All @@ -48,13 +50,13 @@ trait StringInjections extends NumericInjections {
override def invert(s: String) = attempt(s)(UUID.fromString(_))
}

case class URLEncodedString(encodedString: String)

implicit val string2UrlEncodedString: Injection[String, URLEncodedString] = new AbstractInjection[String, URLEncodedString] {
override def apply(a: String): URLEncodedString = URLEncodedString(URLEncoder.encode(a, "UTF-8"))

override def invert(b: URLEncodedString): Try[String] = attempt(b)(s => URLDecoder.decode(s.encodedString, "UTF-8"))
}
}

object StringCodec extends StringInjections
object StringCodec extends StringInjections {
case class URLEncodedString(encodedString: String) extends AnyVal
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ import com.google.common.io.BaseEncoding
*/
object GuavaBinaryBijections {

trait BaseEncoding {
val str: String
trait BaseEncoding extends Any {
def str: String
}

case class Base16String(str: String) extends BaseEncoding
case class Base16String(str: String) extends AnyVal with BaseEncoding

case class Base32String(str: String) extends BaseEncoding
case class Base32String(str: String) extends AnyVal with BaseEncoding

case class Base32HEXString(str: String) extends BaseEncoding
case class Base32HEXString(str: String) extends AnyVal with BaseEncoding

case class Base64String(str: String) extends BaseEncoding
case class Base64String(str: String) extends AnyVal with BaseEncoding

case class Base64URLString(str: String) extends BaseEncoding
case class Base64URLString(str: String) extends AnyVal with BaseEncoding

implicit def unwrap(encodedString: BaseEncoding): String = Option(encodedString) match {
case Some(x) => x.str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import org.codehaus.jackson.JsonNode

/**
* Value class representing unparsed Json text
* TODO in scala 2.10 this should be a value class
*/
case class UnparsedJson(str: String)
case class UnparsedJson(str: String) extends AnyVal

object UnparsedJson {

Expand Down