2009년 4월 26일 일요일

Implementing Scala Iterable Interface

ArrayStack Overview#

It's simple scala program that implements Scala Iterable interface and test it.
* See it in my wiki

Source#

ArrayStack
  case 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, Id 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

See it in my wiki

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


In Korea, more and more projects are using RIA platforms instead of legacy X-Internet solutions.
Thesedays, all of my project are based on "iBatis + Spring + Flex" architecture, too.
These Mindmap is just personal opinions. just see it and forget it.








2009년 4월 4일 토요일

Social Architecture MindMap


So inspired by the article: The Elements of Social Architecture by Christina Wodtke, March 03 2009
I created a mindmap based on that contents.

Enjoy it!