Created
August 1, 2013 04:31
-
-
Save Aidanie/6128422 to your computer and use it in GitHub Desktop.
Simple Circular Buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple Scala Circular Buffer. | |
* | |
* @author Aidan Church ([email protected]) | |
* @url http://www.achurch.me | |
* | |
*/ | |
class circularBuffer(size:Int){ | |
val maxSize = size; | |
val buffer = new ArrayBuffer[String] | |
def +=(item : String){ | |
if(buffer.size == size) | |
buffer.trimStart(1) | |
buffer.append(item) | |
} | |
def remove(n:Int) = {buffer.trimStart(n)} | |
def print(){ | |
for(string <- buffer){ | |
println(string) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment