scala.annotation.switch Scala Examples

The following examples show how to use scala.annotation.switch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: PetOwner.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
import scala.annotation.switch

case class PetOwner(var pet: Pet) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(new Pet)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        pet
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.pet = {
        value
      }.asInstanceOf[Pet]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = PetOwner.SCHEMA$
}

object PetOwner {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"PetOwner\",\"fields\":[{\"name\":\"pet\",\"type\":{\"type\":\"record\",\"name\":\"Pet\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}]}")
} 
Example 2
Source File: ArrayAsScalaVector.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl.array

import scala.annotation.switch

final case class ArrayIdl(var data: Vector[Int]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(Vector.empty)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        scala.collection.JavaConverters.bufferAsJavaListConverter({
          data map { x =>
            x
          }
        }.toBuffer).asJava
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (array: java.util.List[_]) => {
            Vector((scala.collection.JavaConverters.asScalaIteratorConverter(array.iterator).asScala.toSeq map { x =>
              x
            }: _*))
          }
        }
      }.asInstanceOf[Vector[Int]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ArrayIdl.SCHEMA$
}

object ArrayIdl {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}")
} 
Example 3
Source File: ArrayAsScalaList.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl.array

import scala.annotation.switch

final case class ArrayIdl(var data: List[Int]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(List.empty)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        scala.collection.JavaConverters.bufferAsJavaListConverter({
          data map { x =>
            x
          }
        }.toBuffer).asJava
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (array: java.util.List[_]) => {
            List((scala.collection.JavaConverters.asScalaIteratorConverter(array.iterator).asScala.toSeq map { x =>
              x
            }: _*))
          }
        }
      }.asInstanceOf[List[Int]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ArrayIdl.SCHEMA$
}

object ArrayIdl {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}")
} 
Example 4
Source File: ArrayAsScalaSeq.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl.array

import scala.annotation.switch

final case class ArrayIdl(var data: Seq[Int]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(Seq.empty)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        scala.collection.JavaConverters.bufferAsJavaListConverter({
          data map { x =>
            x
          }
        }.toBuffer).asJava
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (array: java.util.List[_]) => {
            Seq((scala.collection.JavaConverters.asScalaIteratorConverter(array.iterator).asScala.toSeq map { x =>
              x
            }: _*))
          }
        }
      }.asInstanceOf[Seq[Int]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ArrayIdl.SCHEMA$
}

object ArrayIdl {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}")
} 
Example 5
Source File: NoSpaces1.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.example

import scala.annotation.switch


final case class NoSpaces1(var single_line_comment_property: String, var multi_line_property: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", "")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        single_line_comment_property
      }.asInstanceOf[AnyRef]
      case 1 => {
        multi_line_property
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.single_line_comment_property = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.multi_line_property = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces1.SCHEMA$
}

object NoSpaces1 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces1\",\"namespace\":\"com.example\",\"doc\":\"The comment applies to the `NoSpaces1` record, but is not indented to the\\nlevel of the record specification.\",\"fields\":[{\"name\":\"single_line_comment_property\",\"type\":\"string\",\"doc\":\"This is a single line comment that is indented for readability,\\n    and is not affected by indentation.\"},{\"name\":\"multi_line_property\",\"type\":\"string\",\"doc\":\"This multi-line comment on `mult_line_property` that would be affected by indentation.\\n\\nThis is another paragraph\\n\\n\\n    This is an indented block and should be shown as\\n    such.\\n\\nHere is a code block that apparently does not work for avrodoc. E.g. no [GFM](https://help.github.com/articles/github-flavored-markdown) support.\\n\\n```ruby\\n# this is a Ruby code block\\ndef method(arg1, arg2=nil)\\n  puts \\\"hello world!\\\"\\nend\\n```\"}]}")
} 
Example 6
Source File: Example4.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.example

import scala.annotation.switch


sealed trait Example4 extends org.apache.avro.specific.SpecificRecordBase with Product with Serializable

final case class NoSpaces4(var comment_property1: String) extends org.apache.avro.specific.SpecificRecordBase with Example4 {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        comment_property1
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.comment_property1 = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces4.SCHEMA$
}

final object NoSpaces4 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces4\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"comment_property1\",\"type\":\"string\"}]}")
}

final case class NoSpaces5(var comment_property2: String) extends org.apache.avro.specific.SpecificRecordBase with Example4 {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        comment_property2
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.comment_property2 = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces5.SCHEMA$
}

final object NoSpaces5 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces5\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"comment_property2\",\"type\":\"string\"}]}")
} 
Example 7
Source File: NoSpaces3.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.example

import scala.annotation.switch


final case class NoSpaces3(var comment_property: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        comment_property
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.comment_property = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces3.SCHEMA$
}

object NoSpaces3 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces3\",\"namespace\":\"com.example\",\"doc\":\"The comment applies to the `NoSpaces3` record, but is not indented to the\\nlevel of the record specification.\",\"fields\":[{\"name\":\"comment_property\",\"type\":\"string\"}]}")
} 
Example 8
Source File: NoSpaces2.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.example

import scala.annotation.switch


final case class NoSpaces2(var comment_property: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        comment_property
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.comment_property = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces2.SCHEMA$
}

object NoSpaces2 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces2\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"comment_property\",\"type\":\"string\",\"doc\":\"This is a single line comment on a field, in a record that has no comment.\"}]}")
} 
Example 9
Source File: Example5.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.example

import scala.annotation.switch




final case class NoSpaces6(var comment_property1: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        comment_property1
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.comment_property1 = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces6.SCHEMA$
}

object NoSpaces6 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces6\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"comment_property1\",\"type\":\"string\"}]}")
}

final case class NoSpaces7(var comment_property2: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        comment_property2
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.comment_property2 = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NoSpaces7.SCHEMA$
}

object NoSpaces7 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NoSpaces7\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"comment_property2\",\"type\":\"string\"}]}")
} 
Example 10
Source File: Card.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package deck

import scala.annotation.switch

case class Card(var suit: Suit = Suit.SPADES, var number: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(Suit.SPADES, 0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        suit
      }.asInstanceOf[AnyRef]
      case 1 => {
        number
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.suit = {
        value
      }.asInstanceOf[Suit]
      case 1 => this.number = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Card.SCHEMA$
}

object Card {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Card\",\"namespace\":\"deck\",\"fields\":[{\"name\":\"suit\",\"type\":{\"type\":\"enum\",\"name\":\"Suit\",\"symbols\":[\"SPADES\",\"DIAMONDS\",\"CLUBS\",\"HEARTS\"]},\"default\":\"SPADES\"},{\"name\":\"number\",\"type\":\"int\"}]}")
} 
Example 11
Source File: ArrayAsScalaArray.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl.array

import scala.annotation.switch

final case class ArrayIdl(var data: Array[Int]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(Array.empty)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        scala.collection.JavaConverters.bufferAsJavaListConverter({
          data map { x =>
            x
          }
        }.toBuffer).asJava
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (array: java.util.List[_]) => {
            Array((scala.collection.JavaConverters.asScalaIteratorConverter(array.iterator).asScala.toSeq map { x =>
              x
            }: _*))(scala.reflect.ClassTag(classOf[Int])).asInstanceOf[Array[Int]]
          }
        }
      }.asInstanceOf[Array[Int]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ArrayIdl.SCHEMA$
}

object ArrayIdl {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}")
} 
Example 12
Source File: Pet.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test.one.a

import scala.annotation.switch


case class Pet(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Pet.SCHEMA$
}

object Pet {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Pet\",\"namespace\":\"test.one.a\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 13
Source File: Person.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test.one.a
  
  import scala.annotation.switch
  
  
  case class Person(var pet: Pet) extends org.apache.avro.specific.SpecificRecordBase {
    def this() = this(new Pet)
    def get(field$: Int): AnyRef = {
      (field$: @switch) match {
        case 0 => {
          pet
        }.asInstanceOf[AnyRef]
        case _ => new org.apache.avro.AvroRuntimeException("Bad index")
      }
    }
    def put(field$: Int, value: Any): Unit = {
      (field$: @switch) match {
        case 0 => this.pet = {
          value
        }.asInstanceOf[Pet]
        case _ => new org.apache.avro.AvroRuntimeException("Bad index")
      }
      ()
    }
    def getSchema: org.apache.avro.Schema = Person.SCHEMA$
  }
  
  object Person {
    val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"test.one.a\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"pet\",\"type\":{\"type\":\"record\",\"name\":\"Pet\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]},\"doc\":\"Auto-Generated Field\"}]}")
  } 
Example 14
Source File: Pet.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test

import scala.annotation.switch


case class Pet(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Pet.SCHEMA$
}

object Pet {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Pet\",\"namespace\":\"test\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 15
Source File: Person.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test.testsub

import scala.annotation.switch


case class Person(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Person.SCHEMA$
}

object Person {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"test.testsub\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 16
Source File: Vehicle.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test

import scala.annotation.switch


case class Vehicle(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Vehicle.SCHEMA$
}

object Vehicle {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Vehicle\",\"namespace\":\"test\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 17
Source File: Experiment.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test

import scala.annotation.switch


final case class Experiment(var name: String, var age: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", 0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case 1 => {
        age
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.age = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Experiment.SCHEMA$
}

object Experiment {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Experiment\",\"namespace\":\"test\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"},{\"name\":\"age\",\"type\":\"int\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 18
Source File: Vehicle.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test.major

import scala.annotation.switch


case class Vehicle(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Vehicle.SCHEMA$
}

object Vehicle {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Vehicle\",\"namespace\":\"test.major\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 19
Source File: Person.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test
  
  import scala.annotation.switch
  
  
  case class Person(var pet: Pet) extends org.apache.avro.specific.SpecificRecordBase {
    def this() = this(new Pet)
    def get(field$: Int): AnyRef = {
      (field$: @switch) match {
        case 0 => {
          pet
        }.asInstanceOf[AnyRef]
        case _ => new org.apache.avro.AvroRuntimeException("Bad index")
      }
    }
    def put(field$: Int, value: Any): Unit = {
      (field$: @switch) match {
        case 0 => this.pet = {
          value
        }.asInstanceOf[Pet]
        case _ => new org.apache.avro.AvroRuntimeException("Bad index")
      }
      ()
    }
    def getSchema: org.apache.avro.Schema = Person.SCHEMA$
  }
  
  object Person {
    val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"test\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"pet\",\"type\":{\"type\":\"record\",\"name\":\"Pet\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]},\"doc\":\"Auto-Generated Field\"}]}")
  } 
Example 20
Source File: Leader.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test

import scala.annotation.switch


case class Leader(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Leader.SCHEMA$
}

object Leader {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Leader\",\"namespace\":\"test\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 21
Source File: JacksonTokenIterator.scala    From tethys   with Apache License 2.0 5 votes vote down vote up
package tethys.jackson

import com.fasterxml.jackson.core.{JsonParser, JsonTokenId}
import tethys.commons.Token
import tethys.commons.Token._
import tethys.readers.tokens.{BaseTokenIterator, TokenIterator}

import scala.annotation.switch

final class JacksonTokenIterator(jsonParser: JsonParser) extends BaseTokenIterator {
  private[this] var token: Token = fromId(jsonParser.currentTokenId())
  override def currentToken(): Token = token

  override def nextToken(): Token = {
    val t = jsonParser.nextToken()
    token = {
      if(t == null) Token.Empty
      else fromId(t.id())
    }
    token
  }

  override def fieldName(): String = jsonParser.getCurrentName

  override def string(): String = jsonParser.getValueAsString()

  override def number(): Number = jsonParser.getNumberValue

  override def short(): Short = jsonParser.getShortValue

  override def int(): Int = jsonParser.getIntValue

  override def long(): Long = jsonParser.getLongValue

  override def float(): Float = jsonParser.getFloatValue

  override def double(): Double = jsonParser.getDoubleValue

  override def boolean(): Boolean = jsonParser.getBooleanValue

  private def fromId(tokenId: Int): Token = (tokenId: @switch) match {
    case JsonTokenId.ID_START_OBJECT => ObjectStartToken
    case JsonTokenId.ID_END_OBJECT => ObjectEndToken
    case JsonTokenId.ID_START_ARRAY => ArrayStartToken
    case JsonTokenId.ID_END_ARRAY => ArrayEndToken
    case JsonTokenId.ID_FIELD_NAME => FieldNameToken
    case JsonTokenId.ID_STRING => StringValueToken
    case JsonTokenId.ID_NUMBER_INT => NumberValueToken
    case JsonTokenId.ID_NUMBER_FLOAT => NumberValueToken
    case JsonTokenId.ID_TRUE => BooleanValueToken
    case JsonTokenId.ID_FALSE => BooleanValueToken
    case JsonTokenId.ID_NULL => NullValueToken
    case _ => Token.Empty
  }
}

object JacksonTokenIterator {
  def fromFreshParser(parser: JsonParser): TokenIterator = {
    parser.nextToken()// move parser to first token
    new JacksonTokenIterator(parser)
  }
} 
Example 22
Source File: PatternMatching.scala    From Scala-High-Performance-Programming   with MIT License 5 votes vote down vote up
package highperfscala.patternmatch

import scala.annotation.switch
import scalaz.{@@, Tag}

object PatternMatching {

  sealed trait Event
  case object E1 extends Event
  case object E2 extends Event
  case object E3 extends Event

  sealed trait Foo

  case class IntBar(i: Int, b: Bar)
  def intBar: IntBar = IntBar(1, Bar(2))

  def tuple2Boxed(): (Int, Bar) = (1, Bar(2))

  def tuple2: (Int, Double) = (1, 2.0)

  def tuple3(): (Int, Double, Int) = (1, 2.0, 3)

  case class Triple(x: Int, y: Double, z: Int)

  def triple(): Triple = Triple(1, 2.0, 3)


  def arrayExample(): Array[Bar] = {
    Array(Bar(1), Bar(2), Bar(3))
    //      .map(b => b.copy(b.value + 1))
  }

  def arrayIntExample(): Array[Int] = {
    Array(1, 2, 3).map(i => i * 2)
    //      .map(b => b.copy(b.value + 1))
  }

  def tagFoo(i: Int): Int @@ Foo = {
    Tag.apply(i)
  }

  def useFoo(i: Int @@ Foo): Option[String] = {
    Some((5 + Tag.unwrap(i)).toString)
  }

  case class Bar(value: Int) extends AnyVal
  Bar.unapply(Bar(1))

  sealed trait Side
  case object Buy extends Side
  case object Sell extends Side
  def handleOrder(s: Side): Boolean = s match {
    case Buy => true
    case Sell => false
  }

  sealed trait Order
  case class BuyOrder(price: Double) extends Order
  case class SellOrder(price: Double) extends Order
  def handleOrder(o: Order): Boolean = o match {
    case BuyOrder(price) if price > 2.0 => true
    case BuyOrder(_) => false
    case SellOrder(_) => false
  }

  def handleGuard(e: Bar): Option[String] = e match {
    case ee if ee.value > 5 => None
    case Bar(4) => Some("4")
  }

  val z = 4
  def handleInt(e: Int): Option[String] = e match {
    case 2 => Some("res")
    case 3 => None
    case `z` => None
  }

  case class ShareCount(value: Int) extends AnyVal
  def handleAnyVal(e: ShareCount): Option[String] = e match {
    case ShareCount(2) => Some("res")
    case ShareCount(3) => None
    case ShareCount(4) => None
  }

  def processShareCount(sc: ShareCount): Boolean = (sc: @switch) match {
    case ShareCount(1) => true
    case _ => false
  }

} 
Example 23
Source File: JsPrinter.scala    From scalaz-deriving   with GNU Lesser General Public License v3.0 5 votes vote down vote up
// Copyright: 2017 - 2020 Sam Halliday
// License: http://www.gnu.org/licenses/lgpl-3.0.en.html

package jsonformat

import scala.annotation.switch
import scalaz._, Scalaz._
import internal.TCord

object PrettyPrinter {
  def apply(j: JsValue): String = print(j, 0).shows

  private def print(j: JsValue, level: Int): TCord =
    j match {
      case JsArray(as)  =>
        "[" :: as.map(print(_, level)).intercalate(", ") ++ "]"
      case JsObject(fs) =>
        "{" :: (fs.map(print(_, level + 1)).intercalate(",") ++ pad(
          level
        )) ++ "}"
      case _            => CompactPrinter.print(j)
    }

  private def print(entry: (String, JsValue), level: Int): TCord =
    (pad(level) ++ CompactPrinter.escaped(entry._1) ++ ": ") ++ print(
      entry._2,
      level
    )

  private[this] val pad: Int => TCord       = Memo.arrayMemo[TCord](16).apply(pad0(_))
  private[this] def pad0(level: Int): TCord =
    "\n" + (" " * 2 * level)

}

object CompactPrinter {
  def apply(j: JsValue, cb: String): String =
    (cb :: ("(" :: print(j) ++ ")")).shows

  def apply(j: JsValue): String = print(j).shows

  private[jsonformat] def print(j: JsValue): TCord =
    j match {
      case JsNull       => "null"
      case JsBoolean(v) => if (v) "true" else "false"
      case JsDouble(n)  => n.toString
      case JsInteger(n) => n.toString
      case JsString(s)  => escaped(s)
      case JsArray(as)  => "[" :: as.map(print).intercalate(",") ++ "]"
      case JsObject(fs) => "{" :: fs.map(print).intercalate(",") ++ "}"
    }

  private def print(entry: (String, JsValue)): TCord =
    escaped(entry._1) :: ":" :: print(entry._2)

  private[jsonformat] def escaped(s: String): String = {
    // scalafix:off
    val sb = new java.lang.StringBuilder
    var i  = 0
    sb.append("\"")
    while (i < s.length) {
      sb.append(escape(s(i)))
      i += 1
    }
    sb.append("\"")
    sb.toString
    // scalafix:on
  }

  // https://www.ietf.org/rfc/rfc4627.txt
  private def escape(c: Char): String =
    (c: @switch) match {
      case '\\' => "\\\\"
      case '"'  => "\\\""
      case '\b' => "\\b"
      case '\f' => "\\f"
      case '\n' => "\\n"
      case '\r' => "\\r"
      case '\t' => "\\t"
      case c    =>
        if (Character.isISOControl(c)) "\\u%04x".format(c.toInt) else c.toString
    }

} 
Example 24
Source File: InterceptionLoop.scala    From swave   with Mozilla Public License 2.0 5 votes vote down vote up
package swave.core.impl

import scala.annotation.switch
import swave.core.impl.stages.StageImpl
import swave.core.impl.util.ResizableRingBuffer

private[impl] final class InterceptionLoop(initialBufferSize: Int) {

  private[this] val signalBuffer: ResizableRingBuffer[AnyRef] =
    new ResizableRingBuffer(initialBufferSize, initialBufferSize << 4)

  def enqueueSubscribe(target: StageImpl, from: Outport): Unit =
    if (from eq null) store(target, Statics._0) else store(target, Statics._1, from)
  def enqueueRequest(target: StageImpl, n: Int, from: Outport): Unit =
    if (from eq null) store(target, if (n <= 32) Statics.NEG_INTS(n - 1) else new Integer(-n))
    else store(target, if (n <= 32) Statics.INTS_PLUS_100(n - 1) else new Integer(n + 100), from)
  def enqueueCancel(target: StageImpl, from: Outport): Unit =
    if (from eq null) store(target, Statics._2) else store(target, Statics._3, from)
  def enqueueOnSubscribe(target: StageImpl, from: Inport): Unit =
    if (from eq null) store(target, Statics._4) else store(target, Statics._5, from)
  def enqueueOnNext(target: StageImpl, elem: AnyRef, from: Inport): Unit =
    if (from eq null) store(target, Statics._6, elem) else store(target, Statics._7, elem, from)
  def enqueueOnComplete(target: StageImpl, from: Inport): Unit =
    if (from eq null) store(target, Statics._8) else store(target, Statics._9, from)
  def enqueueOnError(target: StageImpl, e: Throwable, from: Inport): Unit =
    if (from eq null) store(target, Statics._10, e) else store(target, Statics._11, e, from)
  def enqueueXEvent(target: StageImpl, ev: AnyRef): Unit =
    store(target, Statics._12, ev)

  private def store(a: AnyRef, b: AnyRef): Unit =
    if (!signalBuffer.write(a, b)) throwBufOverflow()
  private def store(a: AnyRef, b: AnyRef, c: AnyRef): Unit =
    if (!signalBuffer.write(a, b, c)) throwBufOverflow()
  private def store(a: AnyRef, b: AnyRef, c: AnyRef, d: AnyRef): Unit =
    if (!signalBuffer.write(a, b, c, d)) throwBufOverflow()

  private def throwBufOverflow() = throw new IllegalStateException("Interception signal buffer overflow")

  def hasInterception: Boolean = signalBuffer.nonEmpty

  def handleInterception(): Unit = {
    def read()       = signalBuffer.unsafeRead()
    def readNoZero() = signalBuffer.unsafeRead_NoZero()
    def readInt()    = readNoZero().asInstanceOf[java.lang.Integer].intValue()
    def readStage()  = readNoZero().asInstanceOf[StageImpl]
    val target       = readStage()
    (readInt(): @switch) match {
      case 0  ⇒ target._subscribe(null)
      case 1  ⇒ target._subscribe(readStage())
      case 2  ⇒ target._cancel(null)
      case 3  ⇒ target._cancel(readStage())
      case 4  ⇒ target._onSubscribe(null)
      case 5  ⇒ target._onSubscribe(readStage())
      case 6  ⇒ target._onNext(read(), null)
      case 7  ⇒ target._onNext(read(), readStage())
      case 8  ⇒ target._onComplete(null)
      case 9  ⇒ target._onComplete(readStage())
      case 10 ⇒ target._onError(read().asInstanceOf[Throwable], null)
      case 11 ⇒ target._onError(read().asInstanceOf[Throwable], readStage())
      case 12 ⇒ target._xEvent(read())
      case x =>
        if (x < 0) target._request(-x, null)
        else target._request(x - 100, readStage())
    }
  }
} 
Example 25
Source File: ComponentRepresentation.scala    From scalismo   with Apache License 2.0 5 votes vote down vote up
package scalismo.common

import scalismo.geometry.{_2D, _3D, EuclideanVector}

import scala.annotation.switch


  def intoArray(color: A, array: Array[Double]): Array[Double] = {
    require(array.length >= size, "target Array is too small")
    var i = 0
    while (i < size) {
      array(i) = component(color, i)
      i += 1
    }
    array
  }
}

object ComponentRepresentation {

  def apply[A](implicit vec: ComponentRepresentation[A]): ComponentRepresentation[A] = vec

  implicit object VectorComponents2D extends ComponentRepresentation[EuclideanVector[_2D]] {
    override def fromArray(arr: Array[Double]): EuclideanVector[_2D] = EuclideanVector(arr(0), arr(1))
    override def toArray(value: EuclideanVector[_2D]): Array[Double] = Array(value.x, value.y)
    override val size: Int = 2
    override def intoArray(vec: EuclideanVector[_2D], array: Array[Double]): Array[Double] = {
      require(array.length >= size)
      array(0) = vec.x
      array(1) = vec.y
      array
    }
    override def component(color: EuclideanVector[_2D], index: Int): Double = (index: @switch) match {
      case 0 => color.x
      case 1 => color.y
      case _ => throw new Exception(s"index ($index) out of bounds, Vector[_2D] can only handle 0 and 1")
    }

    override def fromComponents(comp: (Int) => Double): EuclideanVector[_2D] = EuclideanVector(comp(0), comp(1))
  }

  implicit object VectorComponents3D extends ComponentRepresentation[EuclideanVector[_3D]] {
    override def fromArray(arr: Array[Double]): EuclideanVector[_3D] = EuclideanVector(arr(0), arr(1), arr(2))
    override def toArray(value: EuclideanVector[_3D]): Array[Double] = Array(value.x, value.y, value.z)
    override val size: Int = 3
    override def intoArray(vec: EuclideanVector[_3D], array: Array[Double]): Array[Double] = {
      require(array.length >= size)
      array(0) = vec.x
      array(1) = vec.y
      array(2) = vec.z
      array
    }
    override def component(color: EuclideanVector[_3D], index: Int): Double = (index: @switch) match {
      case 0 => color.x
      case 1 => color.y
      case 2 => color.z
      case _ => throw new Exception(s"index ($index) out of bounds, Vector[_3D] can only handle 0, 1 and 2")
    }
    override def fromComponents(comp: (Int) => Double): EuclideanVector[_3D] =
      EuclideanVector(comp(0), comp(1), comp(2))
  }
} 
Example 26
Source File: AuthenticationRequest.scala    From skunk   with MIT License 5 votes vote down vote up
// Copyright (c) 2018-2020 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package skunk.net.message

import scala.annotation.switch
import scodec.Decoder
import scodec.codecs.int32


trait AuthenticationRequest extends BackendMessage

object AuthenticationRequest {
  final val Tag = 'R'
  val decoder: Decoder[AuthenticationRequest] =
    int32.flatMap { a =>
      (a: @switch) match {
        case AuthenticationOk.Tagʹ                => AuthenticationOk.decoderʹ
        case AuthenticationKerberosV5.Tagʹ        => AuthenticationKerberosV5.decoderʹ
        case AuthenticationCleartextPassword.Tagʹ => AuthenticationCleartextPassword.decoderʹ
        case AuthenticationMD5Password.Tagʹ       => AuthenticationMD5Password.decoderʹ
        case AuthenticationSCMCredential.Tagʹ     => AuthenticationSCMCredential.decoderʹ
        case AuthenticationGSS.Tagʹ               => AuthenticationGSS.decoderʹ
        case AuthenticationSSPI.Tagʹ              => AuthenticationSSPI.decoderʹ
        case AuthenticationGSSContinue.Tagʹ       => AuthenticationGSSContinue.decoderʹ
        case AuthenticationSASL.Tagʹ              => AuthenticationSASL.decoderʹ
        case AuthenticationSASLContinue.Tagʹ      => AuthenticationSASLContinue.decoderʹ
        case AuthenticationSASLFinal.Tagʹ         => AuthenticationSASLFinal.decoderʹ
      }
    }
} 
Example 27
Source File: BackendMessage.scala    From skunk   with MIT License 5 votes vote down vote up
// Copyright (c) 2018-2020 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package skunk.net.message

import scala.annotation.switch
import scodec.Decoder


  def decoder(tag: Byte): Decoder[BackendMessage] =
    (tag: @switch) match { // N.B. `final val Tag = <char>` req'd for case switch here
       case AuthenticationRequest.Tag => AuthenticationRequest.decoder
       case BackendKeyData.Tag        => BackendKeyData.decoder
       case BindComplete.Tag          => BindComplete.decoder
       case CloseComplete.Tag         => CloseComplete.decoder
       case CommandComplete.Tag       => CommandComplete.decoder
       case ErrorResponse.Tag         => ErrorResponse.decoder
       case NoData.Tag                => NoData.decoder
       case NotificationResponse.Tag  => NotificationResponse.decoder
       case NoticeResponse.Tag        => NoticeResponse.decoder
       case ParameterDescription.Tag  => ParameterDescription.decoder
       case ParameterStatus.Tag       => ParameterStatus.decoder
       case ParseComplete.Tag         => ParseComplete.decoder
       case PortalSuspended.Tag       => PortalSuspended.decoder
       case ReadyForQuery.Tag         => ReadyForQuery.decoder
       case RowData.Tag               => RowData.decoder
       case RowDescription.Tag        => RowDescription.decoder
       case _                         => UnknownMessage.decoder(tag)
    }

} 
Example 28
Source File: Person.scala    From kafka4s   with Apache License 2.0 5 votes vote down vote up
package com.banno.kafka

import scala.annotation.switch

case class Person(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$ : Int): AnyRef =
    (field$ : @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  def put(field$ : Int, value: Any): Unit = {
    (field$ : @switch) match {
      case 0 =>
        this.name = {
          value.toString
        }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Person.SCHEMA$
}

object Person {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse(
    "{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"com.banno.kafka\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}"
  )
} 
Example 29
Source File: Ui.scala    From mist   with Apache License 2.0 5 votes vote down vote up
import java.net.HttpURLConnection

import sbt.Keys._
import sbt._

import scala.annotation.switch


object Ui {

  lazy val uiVersion: SettingKey[String] = settingKey[String]("Ui version")
  lazy val uiUrl: SettingKey[String => String] = settingKey[String => String]("Construct url for ui downloading")
  lazy val uiCheckoutDir: SettingKey[String] = settingKey[String]("Directory for downloading ui")
  lazy val ui: TaskKey[File] = taskKey[File]("Download ui or return cached")

  lazy val settings = Seq(
    uiUrl := { (s: String) => s"https://github.com/Hydrospheredata/mist-ui/releases/download/v$s/mist-ui-$s.tar.gz" },
    uiVersion := "2.2.1",
    uiCheckoutDir := "ui_local",
    ui := {
      val local = baseDirectory.value / uiCheckoutDir.value
      if (!local.exists()) IO.createDirectory(local)

      val v = uiVersion.value
      val target = local / s"ui-$v"
      if (!target.exists()) {
        val link = uiUrl.value(v)
        val targetF = local/ s"ui-$v.tar.gz"
        Downloader.download(link, targetF)
        Tar.extractTarGz(targetF, target)
      }
      target / "dist"
    }
  )

} 
Example 30
Source File: Chars.scala    From Argus-SAF   with Apache License 2.0 5 votes vote down vote up
package org.argus.jawa.core.io

import java.lang.{Character => JCharacter}

import scala.annotation.switch
import scala.language.postfixOps


  def isVarPart(c: Char): Boolean =
    '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'

  def isIdentifierStart(c: Char): Boolean =
    (c == '`') || Character.isJavaIdentifierPart(c)

  def isIdentifierPart(c: Char, isGraveAccent: Boolean): Boolean = {
    (c != '`' || c != ' ') &&
    {if(isGraveAccent) {c == '.' || c == '/' || c == ';' || c == ':' || c == '_' || c == '(' || c == ')' || c == '<' || c == '>' || Character.isJavaIdentifierPart(c)} 
    else {c != '.' && Character.isJavaIdentifierPart(c)}}
  }

  def isSpecial(c: Char): Boolean = {
    val chtp = Character.getType(c)
    chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt
  }

  private final val otherLetters = Set[Char]('\u0024', '\u005F')  // '$' and '_'
  private final val letterGroups = {
    import JCharacter._
    Set[Byte](LOWERCASE_LETTER, UPPERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, LETTER_NUMBER)
  }
  def isJawaLetter(ch: Char): Boolean = letterGroups(JCharacter.getType(ch).toByte) || otherLetters(ch)

  def isOperatorPart(c: Char): Boolean = (c: @switch) match {
    case '+' | '-' | '/' | '\\' | '*' | '%' | '&' | '|' | '?' | '>' | '<' | '=' | '~' | ':' => true
    case a => isSpecial(a)
  }
}

object Chars extends Chars { } 
Example 31
Source File: Pet.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
import scala.annotation.switch

case class Pet(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Pet.SCHEMA$
}

object Pet {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Pet\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}")
} 
Example 32
Source File: Example03.scala    From jsoniter-scala   with MIT License 5 votes vote down vote up
package com.github.plokhotnyuk.jsoniter_scala.examples

import com.github.plokhotnyuk.jsoniter_scala.core._
import com.github.plokhotnyuk.jsoniter_scala.macros._

import scala.annotation.switch


object Example03 {
  case class RequestData(id: String, load: Int, important: Boolean)

  case class Request(url: String, data: RequestData)

  implicit val requestDataCodec: JsonValueCodec[RequestData] = new JsonValueCodec[RequestData] {
    val requestDataDirectCodec: JsonValueCodec[RequestData] = JsonCodecMaker.make
    val requestDataEncodedCodec: JsonValueCodec[RequestData] = new JsonValueCodec[RequestData] {
      override def decodeValue(in: JsonReader, default: RequestData): RequestData = {
        val json = in.readString(null)
        readFromString(json)(requestDataDirectCodec)
      }

      override def encodeValue(x: RequestData, out: JsonWriter): Unit = requestDataDirectCodec.encodeValue(x, out)

      override val nullValue: RequestData = null
    }

    override def decodeValue(in: JsonReader, default: RequestData): RequestData = (in.nextToken(): @switch) match {
      case '{' =>
        in.rollbackToken()
        requestDataDirectCodec.decodeValue(in, default)
      case '"' =>
        in.rollbackToken()
        requestDataEncodedCodec.decodeValue(in, default)
      case _ =>
        in.decodeError("""expected '{' or '"'""")
    }

    override def encodeValue(x: RequestData, out: JsonWriter): Unit = requestDataDirectCodec.encodeValue(x, out)

    override val nullValue: RequestData = null
  }

  implicit val requestCodec: JsonValueCodec[Request] = JsonCodecMaker.make

  def main(args: Array[String]): Unit = {
    val normalJson =
      """{
        |  "url": "http://google.com",
        |  "data": {
        |  	"id": "abcdefghijklmn",
        |  	"load": 10,
        |  	"important": true
        |  }
        |}""".stripMargin.getBytes("UTF-8")
    val normal = readFromArray[Request](normalJson)
    println(normal)
    println(new String(writeToArray(normal), "UTF-8"))
    println()
    val escapedJson =
      """{
        |  "url": "http://google.com",
        |  "data": "{\"id\":\"abcdefghijklmn\",\"load\":10,\"important\":true}"
        |}""".stripMargin.getBytes("UTF-8")
    val escaped = readFromArray[Request](escapedJson)
    println(escaped)
    println(new String(writeToArray(escaped), "UTF-8"))
  }
} 
Example 33
Source File: Util.scala    From PPrint   with MIT License 5 votes vote down vote up
package pprint

import scala.annotation.{switch, tailrec}

object Util{


  def concat[T](is: (() => Iterator[T])*) = new ConcatIterator(is.iterator.map(_()), () => Iterator.empty)
  
  def literalize(s: IndexedSeq[Char], unicode: Boolean = true) = {
    val sb = new StringBuilder
    sb.append('"')
    var i = 0
    val len = s.length
    while (i < len) {
      Util.escapeChar(s(i), sb)
      i += 1
    }
    sb.append('"')

    sb.result()
  }
} 
Example 34
Source File: twitter_schema.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.miguno.avro

import scala.annotation.switch


final case class twitter_schema(var username: String, var tweet: String, var timestamp: Long) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", "", 0L)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        username
      }.asInstanceOf[AnyRef]
      case 1 => {
        tweet
      }.asInstanceOf[AnyRef]
      case 2 => {
        timestamp
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.username = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.tweet = {
        value.toString
      }.asInstanceOf[String]
      case 2 => this.timestamp = {
        value
      }.asInstanceOf[Long]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = twitter_schema.SCHEMA$
}

object twitter_schema {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"twitter_schema\",\"namespace\":\"com.miguno.avro\",\"fields\":[{\"name\":\"username\",\"type\":\"string\",\"doc\":\"Name of the user account on Twitter.com\"},{\"name\":\"tweet\",\"type\":\"string\",\"doc\":\"The content of the user\'s Twitter message\"},{\"name\":\"timestamp\",\"type\":\"long\",\"doc\":\"Unix epoch time in milliseconds\"}],\"doc:\":\"A basic schema for storing Twitter messages\"}")
} 
Example 35
Source File: Mascot.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package avro.examples.baseball

import scala.annotation.switch

final case class Mascot(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Mascot.SCHEMA$
}

object Mascot {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Mascot\",\"namespace\":\"avro.examples.baseball\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}")
} 
Example 36
Source File: Wrestler.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package avro.examples.baseball

import scala.annotation.switch

final case class Wrestler(var number: Int, var first_name: String, var last_name: String, var nicknames: Seq[Mascot]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0, "", "", Seq.empty)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        number
      }.asInstanceOf[AnyRef]
      case 1 => {
        first_name
      }.asInstanceOf[AnyRef]
      case 2 => {
        last_name
      }.asInstanceOf[AnyRef]
      case 3 => {
        scala.collection.JavaConverters.bufferAsJavaListConverter({
          nicknames map { x =>
            x
          }
        }.toBuffer).asJava
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.number = {
        value
      }.asInstanceOf[Int]
      case 1 => this.first_name = {
        value.toString
      }.asInstanceOf[String]
      case 2 => this.last_name = {
        value.toString
      }.asInstanceOf[String]
      case 3 => this.nicknames = {
        value match {
          case (array: java.util.List[_]) => {
            Seq((scala.collection.JavaConverters.asScalaIteratorConverter(array.iterator).asScala.toSeq map { x =>
              x
            }: _*))
          }
        }
      }.asInstanceOf[Seq[Mascot]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Wrestler.SCHEMA$
}

object Wrestler {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Wrestler\",\"namespace\":\"avro.examples.baseball\",\"fields\":[{\"name\":\"number\",\"type\":\"int\"},{\"name\":\"first_name\",\"type\":\"string\"},{\"name\":\"last_name\",\"type\":\"string\"},{\"name\":\"nicknames\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Mascot\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}}]}")
} 
Example 37
Source File: Nickname.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package avro.examples.baseball

import scala.annotation.switch

final case class Nickname(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Nickname.SCHEMA$
}

object Nickname {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Nickname\",\"namespace\":\"avro.examples.baseball\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}")
} 
Example 38
Source File: Player.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package avro.examples.baseball

import scala.annotation.switch

final case class Player(var number: Int, var first_name: String, var last_name: String, var nicknames: Seq[Nickname]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0, "", "", Seq.empty)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        number
      }.asInstanceOf[AnyRef]
      case 1 => {
        first_name
      }.asInstanceOf[AnyRef]
      case 2 => {
        last_name
      }.asInstanceOf[AnyRef]
      case 3 => {
        scala.collection.JavaConverters.bufferAsJavaListConverter({
          nicknames map { x =>
            x
          }
        }.toBuffer).asJava
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.number = {
        value
      }.asInstanceOf[Int]
      case 1 => this.first_name = {
        value.toString
      }.asInstanceOf[String]
      case 2 => this.last_name = {
        value.toString
      }.asInstanceOf[String]
      case 3 => this.nicknames = {
        value match {
          case (array: java.util.List[_]) => {
            Seq((scala.collection.JavaConverters.asScalaIteratorConverter(array.iterator).asScala.toSeq map { x =>
              x
            }: _*))
          }
        }
      }.asInstanceOf[Seq[Nickname]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Player.SCHEMA$
}

object Player {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Player\",\"namespace\":\"avro.examples.baseball\",\"fields\":[{\"name\":\"number\",\"type\":\"int\"},{\"name\":\"first_name\",\"type\":\"string\"},{\"name\":\"last_name\",\"type\":\"string\"},{\"name\":\"nicknames\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Nickname\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}}]}")
} 
Example 39
Source File: Message.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.proto

import scala.annotation.switch

final case class Message(var to: String, var from: String, var body: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", "", "")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        to
      }.asInstanceOf[AnyRef]
      case 1 => {
        from
      }.asInstanceOf[AnyRef]
      case 2 => {
        body
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.to = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.from = {
        value.toString
      }.asInstanceOf[String]
      case 2 => this.body = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Message.SCHEMA$
}

object Message {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Message\",\"namespace\":\"example.proto\",\"fields\":[{\"name\":\"to\",\"type\":\"string\"},{\"name\":\"from\",\"type\":\"string\"},{\"name\":\"body\",\"type\":\"string\"}]}")
} 
Example 40
Source File: Names.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl

import scala.annotation.switch

final case class Names(var public$: String, var `ends_with_`: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", "")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        public$
      }.asInstanceOf[AnyRef]
      case 1 => {
        `ends_with_`
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.public$ = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.`ends_with_` = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Names.SCHEMA$
}

object Names {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Names\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"public\",\"type\":\"string\"},{\"name\":\"ends_with_\",\"type\":\"string\"}]}")
} 
Example 41
Source File: Card.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.proto

import scala.annotation.switch

final case class Card(var suit: Suit, var number: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(null, 0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        suit
      }.asInstanceOf[AnyRef]
      case 1 => {
        number
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.suit = {
        value
      }.asInstanceOf[Suit]
      case 1 => this.number = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Card.SCHEMA$
}

object Card {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Card\",\"namespace\":\"example.proto\",\"fields\":[{\"name\":\"suit\",\"type\":{\"type\":\"enum\",\"name\":\"Suit\",\"symbols\":[\"SPADES\",\"HEARTS\",\"DIAMONDS\",\"CLUBS\"]}},{\"name\":\"number\",\"type\":\"int\"}]}")
} 
Example 42
Source File: Logical.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.logical.proto

import scala.annotation.switch

final case class Logical(var dec: BigDecimal, var ts: java.time.Instant, var dt: java.time.LocalDate, var uuid: java.util.UUID, var decBig: BigDecimal) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(scala.math.BigDecimal(0), java.time.Instant.now, java.time.LocalDate.now, java.util.UUID.randomUUID, scala.math.BigDecimal(0))
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        val schema = getSchema.getFields().get(field$).schema()
        val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
        val scale = decimalType.getScale()
        val scaledValue = dec.setScale(scale)
        val bigDecimal = scaledValue.bigDecimal
        Logical.decimalConversion.toBytes(bigDecimal, schema, decimalType)
      }.asInstanceOf[AnyRef]
      case 1 => {
        ts.toEpochMilli
      }.asInstanceOf[AnyRef]
      case 2 => {
        dt.toEpochDay.toInt
      }.asInstanceOf[AnyRef]
      case 3 => {
        uuid.toString
      }.asInstanceOf[AnyRef]
      case 4 => {
        val schema = getSchema.getFields().get(field$).schema()
        val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
        val scale = decimalType.getScale()
        val scaledValue = decBig.setScale(scale)
        val bigDecimal = scaledValue.bigDecimal
        Logical.decimalConversion.toBytes(bigDecimal, schema, decimalType)
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.dec = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val schema = getSchema.getFields().get(field$).schema()
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            BigDecimal(Logical.decimalConversion.fromBytes(buffer, schema, decimalType))
          }
        }
      }.asInstanceOf[BigDecimal]
      case 1 => this.ts = {
        value match {
          case (l: Long) => {
            java.time.Instant.ofEpochMilli(l)
          }
        }
      }.asInstanceOf[java.time.Instant]
      case 2 => this.dt = {
        value match {
          case (i: Integer) => {
            java.time.LocalDate.ofEpochDay(i.toInt)
          }
        }
      }.asInstanceOf[java.time.LocalDate]
      case 3 => this.uuid = {
        value match {
          case (chars: java.lang.CharSequence) => {
            java.util.UUID.fromString(chars.toString)
          }
        }
      }.asInstanceOf[java.util.UUID]
      case 4 => this.decBig = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val schema = getSchema.getFields().get(field$).schema()
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            BigDecimal(Logical.decimalConversion.fromBytes(buffer, schema, decimalType))
          }
        }
      }.asInstanceOf[BigDecimal]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Logical.SCHEMA$
}

object Logical {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Logical\",\"namespace\":\"example.logical.proto\",\"fields\":[{\"name\":\"dec\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":9,\"scale\":2},\"logicalType\":\"decimal\",\"precision\":9,\"scale\":2},{\"name\":\"ts\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"dt\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}},{\"name\":\"uuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"decBig\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":20,\"scale\":12},\"logicalType\":\"decimal\",\"precision\":20,\"scale\":12}]}")
  val decimalConversion = new org.apache.avro.Conversions.DecimalConversion
} 
Example 43
Source File: LogicalSc.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.logical

import scala.annotation.switch

final case class LogicalSc(var data: BigDecimal, var ts: java.time.Instant, var dt: java.time.LocalDate, var uuid: java.util.UUID, var dataBig: BigDecimal) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(scala.math.BigDecimal(0), java.time.Instant.now, java.time.LocalDate.now, java.util.UUID.randomUUID, scala.math.BigDecimal(0))
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        val schema = getSchema.getFields().get(field$).schema()
        val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
        val scale = decimalType.getScale()
        val scaledValue = data.setScale(scale)
        val bigDecimal = scaledValue.bigDecimal
        LogicalSc.decimalConversion.toBytes(bigDecimal, schema, decimalType)
      }.asInstanceOf[AnyRef]
      case 1 => {
        ts.toEpochMilli
      }.asInstanceOf[AnyRef]
      case 2 => {
        dt.toEpochDay.toInt
      }.asInstanceOf[AnyRef]
      case 3 => {
        uuid.toString
      }.asInstanceOf[AnyRef]
      case 4 => {
        val schema = getSchema.getFields().get(field$).schema()
        val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
        val scale = decimalType.getScale()
        val scaledValue = dataBig.setScale(scale)
        val bigDecimal = scaledValue.bigDecimal
        LogicalSc.decimalConversion.toBytes(bigDecimal, schema, decimalType)
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val schema = getSchema.getFields().get(field$).schema()
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            BigDecimal(LogicalSc.decimalConversion.fromBytes(buffer, schema, decimalType))
          }
        }
      }.asInstanceOf[BigDecimal]
      case 1 => this.ts = {
        value match {
          case (l: Long) => {
            java.time.Instant.ofEpochMilli(l)
          }
        }
      }.asInstanceOf[java.time.Instant]
      case 2 => this.dt = {
        value match {
          case (i: Integer) => {
            java.time.LocalDate.ofEpochDay(i.toInt)
          }
        }
      }.asInstanceOf[java.time.LocalDate]
      case 3 => this.uuid = {
        value match {
          case (chars: java.lang.CharSequence) => {
            java.util.UUID.fromString(chars.toString)
          }
        }
      }.asInstanceOf[java.util.UUID]
      case 4 => this.dataBig = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val schema = getSchema.getFields().get(field$).schema()
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            BigDecimal(LogicalSc.decimalConversion.fromBytes(buffer, schema, decimalType))
          }
        }
      }.asInstanceOf[BigDecimal]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = LogicalSc.SCHEMA$
}

object LogicalSc {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"LogicalSc\",\"namespace\":\"example.logical\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":9,\"scale\":2}},{\"name\":\"ts\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"dt\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}},{\"name\":\"uuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"dataBig\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":20,\"scale\":12}}]}")
  val decimalConversion = new org.apache.avro.Conversions.DecimalConversion
} 
Example 44
Source File: LogicalSql.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.logical

import scala.annotation.switch

final case class LogicalSql(var data: BigDecimal, var ts: java.sql.Timestamp, var dt: java.sql.Date, var dataBig: BigDecimal) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(scala.math.BigDecimal(0), new java.sql.Timestamp(0L), new java.sql.Date(0L), scala.math.BigDecimal(0))
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        val schema = getSchema.getFields().get(field$).schema()
        val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
        val scale = decimalType.getScale()
        val scaledValue = data.setScale(scale)
        val bigDecimal = scaledValue.bigDecimal
        LogicalSql.decimalConversion.toBytes(bigDecimal, schema, decimalType)
      }.asInstanceOf[AnyRef]
      case 1 => {
        ts.getTime()
      }.asInstanceOf[AnyRef]
      case 2 => {
        dt.getTime()./(86400000)
      }.asInstanceOf[AnyRef]
      case 3 => {
        val schema = getSchema.getFields().get(field$).schema()
        val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
        val scale = decimalType.getScale()
        val scaledValue = dataBig.setScale(scale)
        val bigDecimal = scaledValue.bigDecimal
        LogicalSql.decimalConversion.toBytes(bigDecimal, schema, decimalType)
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val schema = getSchema.getFields().get(field$).schema()
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            BigDecimal(LogicalSql.decimalConversion.fromBytes(buffer, schema, decimalType))
          }
        }
      }.asInstanceOf[BigDecimal]
      case 1 => this.ts = {
        value match {
          case (l: Long) => {
            new java.sql.Timestamp(l)
          }
        }
      }.asInstanceOf[java.sql.Timestamp]
      case 2 => this.dt = {
        value match {
          case (i: Integer) => {
            new java.sql.Date(i.toLong.*(86400000L))
          }
        }
      }.asInstanceOf[java.sql.Date]
      case 3 => this.dataBig = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val schema = getSchema.getFields().get(field$).schema()
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            BigDecimal(LogicalSql.decimalConversion.fromBytes(buffer, schema, decimalType))
          }
        }
      }.asInstanceOf[BigDecimal]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = LogicalSql.SCHEMA$
}

object LogicalSql {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"LogicalSql\",\"namespace\":\"example.logical\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":9,\"scale\":2}},{\"name\":\"ts\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"dt\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}},{\"name\":\"dataBig\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":20,\"scale\":12}}]}")
  val decimalConversion = new org.apache.avro.Conversions.DecimalConversion
} 
Example 45
Source File: User.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

final case class User(var name: String, var favorite_number: Option[Int], var favorite_color: Option[String]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", None, None)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case 1 => {
        favorite_number match {
          case Some(x) => x
          case None => null
        }
      }.asInstanceOf[AnyRef]
      case 2 => {
        favorite_color match {
          case Some(x) => x
          case None => null
        }
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.favorite_number = {
        value match {
          case null => None
          case _ => Some(value)
        }
      }.asInstanceOf[Option[Int]]
      case 2 => this.favorite_color = {
        value match {
          case null => None
          case _ => Some(value.toString)
        }
      }.asInstanceOf[Option[String]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = User.SCHEMA$
}

object User {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"example\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\":[\"int\",\"null\"]},{\"name\":\"favorite_color\",\"type\":[\"string\",\"null\"]}]}")
} 
Example 46
Source File: BinaryIdl.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl

import scala.annotation.switch

final case class BinaryIdl(var data: Array[Byte]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(null)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        java.nio.ByteBuffer.wrap(data)
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val dup = buffer.duplicate()
            val array = new Array[Byte](dup.remaining)
            dup.get(array)
            array
          }
        }
      }.asInstanceOf[Array[Byte]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = BinaryIdl.SCHEMA$
}

object BinaryIdl {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"BinaryIdl\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"data\",\"type\":\"bytes\"}]}")
} 
Example 47
Source File: Card.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl

import scala.annotation.switch

final case class Card(var suit: Suit, var number: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(null, 0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        suit
      }.asInstanceOf[AnyRef]
      case 1 => {
        number
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.suit = {
        value
      }.asInstanceOf[Suit]
      case 1 => this.number = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Card.SCHEMA$
}

object Card {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Card\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"suit\",\"type\":{\"type\":\"enum\",\"name\":\"Suit\",\"symbols\":[\"SPADES\",\"DIAMONDS\",\"CLUBS\",\"HEARTS\"]}},{\"name\":\"number\",\"type\":\"int\"}]}")
} 
Example 48
Source File: Recursive.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl

import scala.annotation.switch

final case class Recursive(var name: String, var recursive: Option[Recursive]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", None)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case 1 => {
        recursive match {
          case Some(x) => x
          case None => null
        }
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.recursive = {
        value match {
          case null => None
          case _ => Some(value)
        }
      }.asInstanceOf[Option[Recursive]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Recursive.SCHEMA$
}

object Recursive {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Recursive\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"recursive\",\"type\":[\"null\",\"Recursive\"]}]}")
} 
Example 49
Source File: NestedProtocol.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.idl

import scala.annotation.switch

sealed trait NestedProtocol extends org.apache.avro.specific.SpecificRecordBase with Product with Serializable

final case class Level2(var name: String) extends org.apache.avro.specific.SpecificRecordBase with NestedProtocol {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Level2.SCHEMA$
}

final object Level2 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Level2\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}")
}

final case class Level1(var level2: Level2) extends org.apache.avro.specific.SpecificRecordBase with NestedProtocol {
  def this() = this(new Level2)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        level2
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.level2 = {
        value
      }.asInstanceOf[Level2]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Level1.SCHEMA$
}

final object Level1 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Level1\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"level2\",\"type\":{\"type\":\"record\",\"name\":\"Level2\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}]}")
}

final case class Level0(var level1: Level1) extends org.apache.avro.specific.SpecificRecordBase with NestedProtocol {
  def this() = this(new Level1)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        level1
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.level1 = {
        value
      }.asInstanceOf[Level1]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Level0.SCHEMA$
}

final object Level0 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Level0\",\"namespace\":\"example.idl\",\"fields\":[{\"name\":\"level1\",\"type\":{\"type\":\"record\",\"name\":\"Level1\",\"fields\":[{\"name\":\"level2\",\"type\":{\"type\":\"record\",\"name\":\"Level2\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}]}}]}")
} 
Example 50
Source File: BinaryPr.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.proto

import scala.annotation.switch

final case class BinaryPr(var data: Array[Byte]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(null)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        java.nio.ByteBuffer.wrap(data)
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val dup = buffer.duplicate()
            val array = new Array[Byte](dup.remaining)
            dup.get(array)
            array
          }
        }
      }.asInstanceOf[Array[Byte]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = BinaryPr.SCHEMA$
}

object BinaryPr {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"BinaryPr\",\"namespace\":\"example.proto\",\"fields\":[{\"name\":\"data\",\"type\":\"bytes\"}]}")
} 
Example 51
Source File: Level1.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

final case class Level1(var level2: Level2) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(new Level2)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        level2
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.level2 = {
        value
      }.asInstanceOf[Level2]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Level1.SCHEMA$
}

object Level1 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Level1\",\"namespace\":\"example\",\"fields\":[{\"name\":\"level2\",\"type\":{\"type\":\"record\",\"name\":\"Level2\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}]}")
} 
Example 52
Source File: BinarySc.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

final case class BinarySc(var data: Array[Byte]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(null)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        java.nio.ByteBuffer.wrap(data)
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.data = {
        value match {
          case (buffer: java.nio.ByteBuffer) => {
            val dup = buffer.duplicate()
            val array = new Array[Byte](dup.remaining)
            dup.get(array)
            array
          }
        }
      }.asInstanceOf[Array[Byte]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = BinarySc.SCHEMA$
}

object BinarySc {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"BinarySc\",\"namespace\":\"example\",\"fields\":[{\"name\":\"data\",\"type\":\"bytes\"}]}")
} 
Example 53
Source File: Level0.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

final case class Level0(var level1: Level1) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(new Level1)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        level1
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.level1 = {
        value
      }.asInstanceOf[Level1]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Level0.SCHEMA$
}

object Level0 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Level0\",\"namespace\":\"example\",\"fields\":[{\"name\":\"level1\",\"type\":{\"type\":\"record\",\"name\":\"Level1\",\"fields\":[{\"name\":\"level2\",\"type\":{\"type\":\"record\",\"name\":\"Level2\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}]}}]}")
} 
Example 54
Source File: Compass.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

final case class Compass(var direction: Direction) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(null)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        direction
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.direction = {
        value
      }.asInstanceOf[Direction]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Compass.SCHEMA$
}

object Compass {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Compass\",\"namespace\":\"example\",\"fields\":[{\"name\":\"direction\",\"type\":{\"type\":\"enum\",\"name\":\"Direction\",\"symbols\":[\"NORTH\",\"SOUTH\",\"EAST\",\"WEST\"]}}]}")
} 
Example 55
Source File: JsonPrinter.scala    From pushka   with Apache License 2.0 5 votes vote down vote up
package pushka.json

import pushka.{Ast, Printer}

import scala.annotation.switch


final class JsonPrinter extends Printer[String] {
  
  def print(jv: Ast): String = {
    val sb = new StringBuilder
    render(sb, 0, jv)
    sb.toString()
  }

  def render(sb: StringBuilder, depth: Int, jv: Ast): Unit =
    jv match {
      case Ast.Null => sb.append("null")
      case Ast.True => sb.append("true")
      case Ast.False => sb.append("false")
      case Ast.Num(n) => sb.append(n)
      case Ast.Str(s) => renderString(sb, s)
      case Ast.Arr(xs) => renderArray(sb, depth, xs)
      case Ast.Obj(vs) => renderObject(sb, depth, canonicalizeObject(vs))
    }

  def canonicalizeObject(vs: Map[String, Ast]): Iterator[(String, Ast)] = {
    vs.iterator
  }

  def renderString(sb: StringBuilder, s: String): Unit = {
    escape(sb, s, unicode = false)
  }

  def renderArray(sb: StringBuilder, depth: Int, vs: Iterable[Ast]): Unit = {
    if (vs.isEmpty) sb.append("[]")
    else {
      sb.append("[")
      val iter = vs.iterator
      render(sb, depth + 1, iter.next())
      while (iter.hasNext) {
        sb.append(",")
        render(sb, depth + 1, iter.next())
      }
      sb.append("]")
    }
  }

  def renderObject(sb: StringBuilder, depth: Int, it: Iterator[(String, Ast)]): Unit = {
    if (!it.hasNext) { sb.append("{}"); () } else {
      val (k0, v0) = it.next()
      sb.append("{")
      renderString(sb, k0)
      sb.append(":")
      render(sb, depth + 1, v0)
      while (it.hasNext) {
        val (k, v) = it.next()
        sb.append(",")
        renderString(sb, k)
        sb.append(":")
        render(sb, depth + 1, v)
      }
      sb.append("}")
    }
  }

  def escape(sb: StringBuilder, s: String, unicode: Boolean): Unit = {
    sb.append('"')
    var i = 0
    val len = s.length
    while (i < len) {
      (s.charAt(i): @switch) match {
        case '"' => sb.append("\\\"")
        case '\\' => sb.append("\\\\")
        case '\b' => sb.append("\\b")
        case '\f' => sb.append("\\f")
        case '\n' => sb.append("\\n")
        case '\r' => sb.append("\\r")
        case '\t' => sb.append("\\t")
        case c =>
          if (c < ' ' || (c > '~' && unicode)) sb.append("\\u%04x" format c.toInt)
          else sb.append(c)
      }
      i += 1
    }
    sb.append('"')
  }
} 
Example 56
Source File: SerializedSuspendableExecutionContext.scala    From perf_tester   with Apache License 2.0 5 votes vote down vote up
package akka.util

import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.ExecutionContext
import scala.util.control.NonFatal
import scala.annotation.{ tailrec, switch }
import akka.dispatch.AbstractNodeQueue

private[akka] object SerializedSuspendableExecutionContext {
  final val Off = 0
  final val On = 1
  final val Suspended = 2

  def apply(throughput: Int)(implicit context: ExecutionContext): SerializedSuspendableExecutionContext =
    new SerializedSuspendableExecutionContext(throughput)(context match {
      case s: SerializedSuspendableExecutionContext ⇒ s.context
      case other ⇒ other
    })
}


  final def size(): Int = count()

  override final def toString: String = (state.get: @switch) match {
    case 0 ⇒ "Off"
    case 1 ⇒ "On"
    case 2 ⇒ "Off & Suspended"
    case 3 ⇒ "On & Suspended"
  }
} 
Example 57
Source File: Sorter.scala    From Converter   with GNU General Public License v3.0 5 votes vote down vote up
package org.scalablytyped.converter.internal
package scalajs
package transforms

import scala.annotation.switch

object Sorter extends TreeTransformation {

  override def leaveClassTree(scope: TreeScope)(s: ClassTree): ClassTree =
    s.copy(members = s.members.sorted(TreeOrdering), ctors = s.ctors.sorted(TreeOrdering))

  override def leaveModuleTree(scope: TreeScope)(s: ModuleTree): ModuleTree =
    s.copy(members = s.members.sorted(TreeOrdering))

  override def leavePackageTree(scope: TreeScope)(s: PackageTree): PackageTree =
    s.copy(members = s.members.sorted(TreeOrdering))

  object TreeOrdering extends Ordering[Tree] {
    override def compare(x: Tree, y: Tree): Int =
      (x, y) match {
        case (m1: MethodTree, m2: MethodTree) =>
          (m1.name.unescaped.compareTo(m2.name.unescaped): @switch) match {
            case 0 =>
              (m1.tparams.length.compareTo(m2.tparams.length): @switch) match {
                case 0 =>
                  (m1.params.length.compareTo(m2.params.length): @switch) match {
                    case 0 =>
                      // well, the rest was fast enough, so... :)
                      val p1: String =
                        m1.params.flatten
                          .map(p => p.name.unescaped + Printer.formatQN(p.tpe.typeName))
                          .mkString
                      val p2: String =
                        m2.params.flatten
                          .map(p => p.name.unescaped + Printer.formatQN(p.tpe.typeName))
                          .mkString
                      p1.compareTo(p2)
                    case other => other
                  }
                case other => other
              }
            case other => other
          }

        case (c1: CtorTree, c2: CtorTree) =>
          (c1.params.length.compareTo(c2.params.length): @switch) match {
            case 0 =>
              val p1: String =
                c1.params.map(p => p.name.unescaped + Printer.formatQN(p.tpe.typeName)).mkString
              val p2: String =
                c2.params.map(p => p.name.unescaped + Printer.formatQN(p.tpe.typeName)).mkString

              p1.compareTo(p2)
            case other => other
          }

        case (s1, s2) =>
          (s1.getClass.getSimpleName.compareTo(s2.getClass.getSimpleName): @switch) match {
            case 0     => s1.name.unescaped.compareTo(s2.name.unescaped)
            case other => other
          }
      }
  }
} 
Example 58
Source File: stringUtils.scala    From Converter   with GNU General Public License v3.0 5 votes vote down vote up
package org.scalablytyped.converter.internal
import java.net.URLEncoder

import scala.annotation.switch

object stringUtils {
  val Quote    = '"'
  val QuoteStr = Quote.toString

  def quote(s: String): String =
    s"$Quote${EscapeStrings.java(s)}$Quote"

  
  def escapeUnicodeEscapes(s: String): String =
    s.replaceAll("\\\\u", "\\\\\\\\u")

  def unCapitalize(str: String): String =
    if (str.length == 0) ""
    else if (str.charAt(0).isLower) str
    else {
      val chars = str.toCharArray
      chars(0) = chars(0).toLower
      new String(chars)
    }

  def joinCamelCase(strings: List[String]): String =
    strings
      .filterNot(_.isEmpty)
      .zipWithIndex
      .map {
        case (x, 0) if x.length > 2 && x(0).isUpper && x(1).isUpper => x.toLowerCase //avoid things like dOM...
        case (x, 0)                                                 => stringUtils.unCapitalize(x)
        case (x, _)                                                 => x.capitalize
      }
      .mkString

  def toCamelCase(str: String): String =
    joinCamelCase(str.split("[_-]").toList)

  // https://stackoverflow.com/a/611117
  def encodeURIComponent(s: String): String =
    URLEncoder
      .encode(s, "UTF-8")
      .replaceAll("\\+", "%20")
      .replaceAll("\\%21", "!")
      .replaceAll("\\%27", "'")
      .replaceAll("\\%28", "(")
      .replaceAll("\\%29", ")")
      .replaceAll("\\%7E", "~")

} 
Example 59
Source File: AvroTypeProviderTestNoNamespace.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
import scala.annotation.switch


final case class AvroTypeProviderTestNoNamespace(var x: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        x
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.x = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = AvroTypeProviderTestNoNamespace.SCHEMA$
}

object AvroTypeProviderTestNoNamespace {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"AvroTypeProviderTestNoNamespace\",\"doc\":\"Auto-generated schema\",\"fields\":[{\"name\":\"x\",\"type\":\"int\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 60
Source File: Reset.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
import scala.annotation.switch


case class Reset() extends org.apache.avro.specific.SpecificRecordBase {
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Reset.SCHEMA$
}

object Reset {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Reset\",\"doc\":\"Auto-Generated Schema\",\"fields\":[]}")
} 
Example 61
Source File: Raise.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
import scala.annotation.switch


case class Raise() extends org.apache.avro.specific.SpecificRecordBase {
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Raise.SCHEMA$
}

object Raise {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Raise\",\"doc\":\"Auto-Generated Schema\",\"fields\":[]}")
} 
Example 62
Source File: Person.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
import scala.annotation.switch


case class Person(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Person.SCHEMA$
}

object Person {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 63
Source File: Driver.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

import test.major.Vehicle


case class Driver(var vehicle: Vehicle) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(new Vehicle)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        vehicle
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.vehicle = {
        value
      }.asInstanceOf[Vehicle]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Driver.SCHEMA$
}

object Driver {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Driver\",\"namespace\":\"example\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"vehicle\",\"type\":{\"type\":\"record\",\"name\":\"Vehicle\",\"namespace\":\"test.major\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]},\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 64
Source File: Pet.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch


case class Pet(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Pet.SCHEMA$
}

object Pet {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Pet\",\"namespace\":\"example\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 65
Source File: Person.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch


case class Person(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Person.SCHEMA$
}

object Person {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 66
Source File: Garage.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

import test.major.Vehicle


case class Garage(var vehicle: Vehicle) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(new Vehicle)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        vehicle
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.vehicle = {
        value
      }.asInstanceOf[Vehicle]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Garage.SCHEMA$
}

object Garage {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Garage\",\"namespace\":\"example\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"vehicle\",\"type\":{\"type\":\"record\",\"name\":\"Vehicle\",\"namespace\":\"test.major\",\"doc\":\"Auto-Generated Schema\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Auto-Generated Field\"}]},\"doc\":\"Auto-Generated Field\"}]}")
} 
Example 67
Source File: Joystick.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test

import scala.annotation.switch

final case class Up(var value: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        value
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.value = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Up.SCHEMA$
}

object Up {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Up\",\"namespace\":\"test\",\"fields\":[{\"name\":\"value\",\"type\":\"int\"}]}")
}

final case class Down(var value: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        value
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.value = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Down.SCHEMA$
}

object Down {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Down\",\"namespace\":\"test\",\"fields\":[{\"name\":\"value\",\"type\":\"int\"}]}")
} 
Example 68
Source File: ComplexExternalDependency.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package test

import scala.annotation.switch

import model.UnionRecord

import model.v2.NestedRecord

final case class ComplexExternalDependency(var nestedrecord: NestedRecord) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(new NestedRecord)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        nestedrecord
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.nestedrecord = {
        value
      }.asInstanceOf[NestedRecord]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ComplexExternalDependency.SCHEMA$
}

object ComplexExternalDependency {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ComplexExternalDependency\",\"namespace\":\"test\",\"fields\":[{\"name\":\"nestedrecord\",\"type\":{\"type\":\"record\",\"name\":\"NestedRecord\",\"namespace\":\"model.v2\",\"fields\":[{\"name\":\"nestedunion\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"UnionRecord\",\"namespace\":\"model\",\"fields\":[{\"name\":\"blah\",\"type\":\"string\"}]}]}]}}]}")
} 
Example 69
Source File: SizeSpec.scala    From nyaya   with GNU Lesser General Public License v2.1 5 votes vote down vote up
package nyaya.gen

import scala.annotation.switch
import scala.collection.immutable.IndexedSeq

sealed trait SizeSpec {
  def gen : Gen[Int]
  def gen1: Gen[Int]
}

object SizeSpec {
  case object Default extends SizeSpec {
    override val gen  = Gen.chooseSize
    override val gen1 = Gen.chooseSizeMin1
    private[gen] val both = (gen, gen1)
  }

  implicit def default: SizeSpec =
    Default

  object DisableDefault {
    implicit def _disableDefaultSizeSpec1: SizeSpec = ???
    implicit def _disableDefaultSizeSpec2: SizeSpec = ???
  }

  // ===================================================================================================================

  case class Exactly(value: Int) extends SizeSpec {
    override val gen  = Gen(_ => value)
    override val gen1 = Gen(_ => value)
  }

  implicit def autoFromInt(i: Int): SizeSpec =
    Exactly(i)

  // ===================================================================================================================

  case class OneOf(possibilities: IndexedSeq[Int]) extends SizeSpec {

    override val (gen, gen1) =
      (possibilities.length: @switch) match {

        case 1 =>
          val e = Exactly(possibilities.head)
          (e.gen, e.gen1)

        case 0 =>
          Default.both

        case _ =>
          val g = Gen.chooseIndexed_!(possibilities)
          val a = g flatMap (n => Gen(_ fixGenSize n))
          val b = g flatMap (n => Gen(_ fixGenSize1 n))
          (a, b)
      }
  }

  implicit def autoFromSeq(possibilities: IndexedSeq[Int]): SizeSpec =
    OneOf(possibilities)

  // ===================================================================================================================

  implicit def autoFromOption[A](o: Option[A])(implicit ev: A => SizeSpec): SizeSpec =
    o.fold[SizeSpec](Default)(ev)
} 
Example 70
Source File: UnionRecord.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package model

import scala.annotation.switch

final case class UnionRecord(var blah: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        blah
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.blah = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = UnionRecord.SCHEMA$
}

object UnionRecord {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"UnionRecord\",\"namespace\":\"model\",\"fields\":[{\"name\":\"blah\",\"type\":\"string\"}]}")
} 
Example 71
Source File: NestedRecord.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package model.v2

import scala.annotation.switch

import model.UnionRecord

final case class NestedRecord(var nestedunion: Option[UnionRecord]) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(None)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        nestedunion match {
          case Some(x) => x
          case None => null
        }
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.nestedunion = {
        value match {
          case null => None
          case _ => Some(value)
        }
      }.asInstanceOf[Option[UnionRecord]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NestedRecord.SCHEMA$
}

object NestedRecord {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NestedRecord\",\"namespace\":\"model.v2\",\"fields\":[{\"name\":\"nestedunion\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"UnionRecord\",\"namespace\":\"model\",\"fields\":[{\"name\":\"blah\",\"type\":\"string\"}]}]}]}")
} 
Example 72
Source File: twitter_schema.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.miguno.avro

import scala.annotation.switch


final case class twitter_schema(var username: String, var tweet: String, var timestamp: Long) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", "", 0L)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        username
      }.asInstanceOf[AnyRef]
      case 1 => {
        tweet
      }.asInstanceOf[AnyRef]
      case 2 => {
        timestamp
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.username = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.tweet = {
        value.toString
      }.asInstanceOf[String]
      case 2 => this.timestamp = {
        value
      }.asInstanceOf[Long]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = twitter_schema.SCHEMA$
}

object twitter_schema {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"twitter_schema\",\"namespace\":\"com.miguno.avro\",\"fields\":[{\"name\":\"username\",\"type\":\"string\",\"doc\":\"Name of the user account on Twitter.com\"},{\"name\":\"tweet\",\"type\":\"string\",\"doc\":\"The content of the user\'s Twitter message\"},{\"name\":\"timestamp\",\"type\":\"long\",\"doc\":\"Unix epoch time in milliseconds\"}],\"doc:\":\"A basic schema for storing Twitter messages\"}")
} 
Example 73
Source File: NullableDecimal.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package com.example

import scala.annotation.switch

final case class NullableDecimal(var ciao: Option[BigDecimal] = None) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(None)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        ciao match {
          case Some(x) => {
            val schema = scala.collection.JavaConverters.asScalaBufferConverter(getSchema.getFields().get(field$).schema().getTypes).asScala.toList.find(_.getFullName == "bytes").get
            val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
            val scale = decimalType.getScale()
            val scaledValue = x.setScale(scale)
            val bigDecimal = scaledValue.bigDecimal
            NullableDecimal.decimalConversion.toBytes(bigDecimal, schema, decimalType)
          }
          case None => null
        }
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.ciao = {
        value match {
          case null => None
          case _ => Some(value match {
            case (buffer: java.nio.ByteBuffer) => {
              val schema = scala.collection.JavaConverters.asScalaBufferConverter(getSchema.getFields().get(field$).schema().getTypes).asScala.toList.find(_.getFullName == "bytes").get
              val decimalType = schema.getLogicalType().asInstanceOf[org.apache.avro.LogicalTypes.Decimal]
              BigDecimal(NullableDecimal.decimalConversion.fromBytes(buffer, schema, decimalType))
            }
          })
        }
      }.asInstanceOf[Option[BigDecimal]]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = NullableDecimal.SCHEMA$
}

object NullableDecimal {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"NullableDecimal\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"ciao\",\"type\":[\"null\",{\"type\":\"bytes\",\"scale\":5,\"precision\":64,\"logicalType\":\"decimal\"}],\"default\":null}]}")
  val decimalConversion = new org.apache.avro.Conversions.DecimalConversion
} 
Example 74
Source File: ExternalDependency.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package other.ns.string

import scala.annotation.switch

final case class ExternalDependency(var number: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        number
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.number = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ExternalDependency.SCHEMA$
}

object ExternalDependency {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ExternalDependency\",\"namespace\":\"other.ns\",\"fields\":[{\"name\":\"number\",\"type\":\"int\"}]}")
} 
Example 75
Source File: ExternalDependency.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package other.ns

import scala.annotation.switch

final case class ExternalDependency(var number: Int) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this(0)
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        number
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.number = {
        value
      }.asInstanceOf[Int]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = ExternalDependency.SCHEMA$
}

object ExternalDependency {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ExternalDependency\",\"namespace\":\"other.ns\",\"fields\":[{\"name\":\"number\",\"type\":\"int\"}]}")
} 
Example 76
Source File: Level2.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example

import scala.annotation.switch

final case class Level2(var name: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        name
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.name = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Level2.SCHEMA$
}

object Level2 {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Level2\",\"namespace\":\"example\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}")
} 
Example 77
Source File: Message.scala    From avrohugger   with Apache License 2.0 5 votes vote down vote up
package example.proto

import scala.annotation.switch

final case class Message(var to: String, var from: String, var body: String) extends org.apache.avro.specific.SpecificRecordBase {
  def this() = this("", "", "")
  def get(field$: Int): AnyRef = {
    (field$: @switch) match {
      case 0 => {
        to
      }.asInstanceOf[AnyRef]
      case 1 => {
        from
      }.asInstanceOf[AnyRef]
      case 2 => {
        body
      }.asInstanceOf[AnyRef]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
  }
  def put(field$: Int, value: Any): Unit = {
    (field$: @switch) match {
      case 0 => this.to = {
        value.toString
      }.asInstanceOf[String]
      case 1 => this.from = {
        value.toString
      }.asInstanceOf[String]
      case 2 => this.body = {
        value.toString
      }.asInstanceOf[String]
      case _ => new org.apache.avro.AvroRuntimeException("Bad index")
    }
    ()
  }
  def getSchema: org.apache.avro.Schema = Message.SCHEMA$
}

object Message {
  val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Message\",\"namespace\":\"example.proto\",\"fields\":[{\"name\":\"to\",\"type\":\"string\"},{\"name\":\"from\",\"type\":\"string\"},{\"name\":\"body\",\"type\":\"string\"}]}")
}