Skip to content

Instantly share code, notes, and snippets.

@faermanj
Created March 15, 2012 12:37
Show Gist options
  • Save faermanj/2043988 to your computer and use it in GitHub Desktop.
Save faermanj/2043988 to your computer and use it in GitHub Desktop.
Avaliando Scala 2
object Colecoes extends Application {
val lista = List.range(-5, 5)
CollectionUtils.forAllDo(
CollectionUtils.collect(
CollectionUtils.select(lista,
new Predicate() {
def evaluate(obj: Object): Boolean =
return obj.asInstanceOf[Int] > 0;
}), new Transformer() {
def transform(obj: Object): Object = {
return (2 * obj.asInstanceOf[Int])
.asInstanceOf[Object];
}
}),
new Closure() {
def execute(obj: Object) {
println(obj);
}
})
}
@WebServlet(Array("/mostraParams"))
class MostraParametrosServlet extends HttpServlet {
override def doGet(req: HttpServletRequest,
resp: HttpServletResponse) {
val out = resp.getWriter();
req.getParameterMap()
.map {case (chave, valor) => chave +" = "+ valor.mkString(",")}
.foreach(out.println(_))
}
}
object ColecoesParalelas{
def main(args: Array[String]) {
(1 to 5).foreach(println);
(1 to 5).par.foreach(println);
}
}
object PiAtores {
def main(args: Array[String]) {
new Coordenador(2).start
}
}
lista.filter(_ > 0).map(_ * 2).foreach(println(_));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment