2009년 5월 9일 토요일
2009년 4월 26일 일요일
Implementing Scala Iterable Interface
ArrayStack Overview#
It's simple scala program that implements Scala Iterable interface and test it.Source#
ArrayStackcase class ArrayStack[T](size: Int) extends Iterable[T] {
// stack
val stack : Array[T] = new Array[T](size);
// number of items in stack
var idx : Int = 0;
//---------------------------------------- Stack Methods
def push(item: T) = { stack(idx) = item ; idx += 1; }
def pop() : T = { idx -= 1; stack(idx); }
//---------------------------------------- Iterable Interface
//* check if stack is empty
override def isEmpty : Boolean = {idx <= 0; }
//* return Iterator
def elements : Iterator[T] = new Iterator[T] {
var i = idx - 1;
override def hasNext:Boolean = { i >= 0; }
override def next : T = { i -= 1; return stack(i+1); }
}
//* Apply a function f to all elements of this iterable object.
override def foreach(f : T => Unit){
var currentIndex = idx - 1;
while(currentIndex >= 0){
f(stack(currentIndex).asInstanceOf[T]);
currentIndex -= 1;
}
}
}
ArrayStackTester
object ArrayStackOfString extends Application {
//--------------------------------------------- Main Method
// create array stack
val astack = new ArrayStack[String](100);
Console.printf("> ArrayStack of Size %d created.\n\n", astack.size);
// test stack
def doStack {
Console.readLine() match {
case null =>
case "" => Console.println("> Bye !!");
case "-" if astack.isEmpty => Console.println("@@ Stack is Empty "); doStack;
case "-" => Console.printf("> Poped : %s\n", astack.pop()); doStack;
case item:String => {
astack.push(item);
Console.printf("> Pushed : %s \n", item);
doStack;
}
}
}
doStack;
// printout stack
Console.printf("> Stack dump\n");
for(item <- astack) {
Console.println(item);
}
}
Result#
> ArrayStack of Size 100 created.
Array
> Pushed : Array
Stack
> Pushed : Stack
Of
> Pushed : Of
String
> Pushed : String
-
> Poped : String
-
> Poped : Of
> Bye !!
> Stack dump
Stack
Array
2009년 4월 9일 목요일
Create Scala Project Using Eclipse Maven PlugIn
In this article, I’d like to explain a way to create simple Scala Project using Eclipse Maven Plug-In. If you're already using Eclipse and Eclipse Maven Plug-In, create a new Scala project is very straightforward, too
Step 0. Requirements
l Maven 2.0.8+
l Eclipse 3.4.x
l Eclipse Maven PlugIn
(update site[1]: http://m2eclipse.sonatype.org/update/)
l Eclipse Scala PlugIn
(update site[1]: http://www.scala-lang.org/scala-eclipse-plugin)
l Scala Runtime
[#1] Eclipse IDE Software Update : from menu, select "Help → Software Updates ... → Available Software" and copy update site
Step 1. Add Scala Repository to Maven Indexes
At First, add Scala Repository to Repository Index
( from Menu: Window -> ShowView -> Other -> Maven -> Maven Indexes)
Step 2: Create Maven App
Now you can see scala-tools.archetypes in Maven Project Wizard.
(from Menu: New -> Project -> Maven -> Maven Project)
Step 3: Check it and Run it
2009년 4월 6일 월요일
Which RIA Platform? - RIA Platform MindMap
2009년 4월 4일 토요일
Social Architecture MindMap
I created a mindmap based on that contents.
Enjoy it!
2009년 3월 27일 금요일
My New Blog Open
To do what?
1. Post my original articles in English.
2. Exchange ideas over the world.
3. Google Blooger looks so cool.
Let me test .......................... Long .............................. Long .......................... and Long, more Long Line