Created
March 15, 2012 12:37
-
-
Save faermanj/2043988 to your computer and use it in GitHub Desktop.
Avaliando Scala 2
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
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); | |
} | |
}) | |
} |
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
@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(_)) | |
} | |
} |
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
object ColecoesParalelas{ | |
def main(args: Array[String]) { | |
(1 to 5).foreach(println); | |
(1 to 5).par.foreach(println); | |
} | |
} |
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
object PiAtores { | |
def main(args: Array[String]) { | |
new Coordenador(2).start | |
} | |
} |
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
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