alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (t2214.scala)

This example Scala source code file (t2214.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, debt, debt, enumeration, equity, equity, future, ignore, object, object, test, unit, value, value

The Scala t2214.scala source code


object InvestmentType extends Enumeration {
  val Debt = Value("DEBT")
  val Future = Value("FUTURE")
  val Equity = Value("EQUITY")
}

object Test {
  def main(args: Array[String]) = {
    val buf = new java.io.ByteArrayOutputStream
    val oos = new java.io.ObjectOutputStream(buf)
    InvestmentType.values.foreach {i => oos.writeObject(i)}
    oos.flush
    oos.close
    val ois = new java.io.ObjectInputStream(
                new java.io.ByteArrayInputStream(buf.toByteArray))
    var obj: Object = null
    foreach(ois) { obj =>
      obj match {
        case InvestmentType.Debt => println("got " + obj)
        case InvestmentType.Equity => println("got " + obj)
        case InvestmentType.Future => println("got " + obj)
        case _ => println("unknown: " + obj + " of: " + obj.getClass)
      }
    }
  }

  def foreach(os: java.io.ObjectInputStream)(f: Object => Unit) {
    try {
      val obj = os.readObject
      if (obj != null) {
        f(obj)
        foreach(os)(f)
      }
    } catch {
      case e: java.io.EOFException => //IGNORE
    }
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala t2214.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.