Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 0.59 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Type Definition
  2. trait IntQueue {
  3.   def get(): Int
  4.   def put(x: Int)
  5.   def size(): Int
  6. }
  7.  
  8. //ArrayBuffer implementation
  9. class IntQueueImpl extends IntQueue {
  10.   private[this] val buf = new collection.mutable.ArrayBuffer[Int]
  11.   def get = buf remove 0
  12.   def put(x: Int) { buf += x }
  13.   def size = buf.length
  14. }
  15.  
  16. trait Doubling extends IntQueue {
  17.   abstract override def put(x: Int) { super.put(2 * x) }
  18. }
  19.  
  20. trait Incrementing extends IntQueue {
  21.   abstract override def put(x: Int) { super.put(x + 1) }
  22. }
  23.  
  24. trait Filtering extends IntQueue {
  25.   abstract override def put(x: Int) { if (x > 0) super.put(x) }
  26. }