From 46208ad14ff084560773c26f3a0a9862f8d0d290 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 15 Jun 2011 17:26:33 +0200 Subject: [PATCH] get rid of 'new' --- examples/src/Bottles.jetl | 2 +- examples/src/TwentyFourGame.jetl | 22 +++++++++++----------- examples/src/collections/ColossalCave.jetl | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/src/Bottles.jetl b/examples/src/Bottles.jetl index a0293624b5b..ceab79be506 100644 --- a/examples/src/Bottles.jetl +++ b/examples/src/Bottles.jetl @@ -16,7 +16,7 @@ fun main(args: Array) { } fun bottlesOfBeer(count: Int): String { - val result = new StringBuilder() + val result = StringBuilder() result.append(count) result.append(if (count > 1) " bottles of beer" else " bottle of beer") return result.toString() ?: "" diff --git a/examples/src/TwentyFourGame.jetl b/examples/src/TwentyFourGame.jetl index ad0634c2652..d3db7d523e1 100644 --- a/examples/src/TwentyFourGame.jetl +++ b/examples/src/TwentyFourGame.jetl @@ -24,17 +24,17 @@ class Evaluator(val expr: StringBuilder, val numbers: ArrayList) { in '0'..'9' => { val n = c - '0' val index = numbers.indexOf(n) - if (index < 0) throw new Exception("You used incorrect number: " + n) + if (index < 0) throw Exception("You used incorrect number: " + n) numbers.remove(index) // gotcha: conflict between remove(Object) and remove(int) return n } '(' => { val result = evaluate() - if (expr.takeFirst() != ')') throw new Exception(") expected") + if (expr.takeFirst() != ')') throw Exception(") expected") return result } - '\0' => throw new Exception("Syntax error: Character expected") - else => throw new Exception("Syntax error: Unrecognized character " + c) + '\0' => throw Exception("Syntax error: Character expected") + else => throw Exception("Syntax error: Unrecognized character " + c) } } @@ -58,16 +58,16 @@ class Evaluator(val expr: StringBuilder, val numbers: ArrayList) { fun evaluateAll(): Int { val result = evaluate() - if (expr.length() > 0) throw new Exception("unexpected text: " + expr) + if (expr.length() > 0) throw Exception("unexpected text: " + expr) return result } } fun main(args: Array) { System.out?.println("24 game") - val numbers = new ArrayList(4) - val rnd = new Random(); - val prompt = new StringBuilder() + val numbers = ArrayList(4) + val rnd = Random(); + val prompt = StringBuilder() for(val i in 0..3) { val n = rnd.nextInt(9) + 1 numbers.add(n) @@ -76,10 +76,10 @@ fun main(args: Array) { } System.out?.println("Your numbers: " + prompt) System.out?.println("Enter your expression:") - val reader = new BufferedReader(new InputStreamReader(System.`in`)) - val expr = new StringBuilder(reader.readLine()) + val reader = BufferedReader(InputStreamReader(System.`in`)) + val expr = StringBuilder(reader.readLine()) try { - val result = new Evaluator(expr, numbers).evaluateAll() + val result = Evaluator(expr, numbers).evaluateAll() if (result != 24) System.out?.println("Sorry, that's " + result) else diff --git a/examples/src/collections/ColossalCave.jetl b/examples/src/collections/ColossalCave.jetl index 3a9e79c5d54..e2f2e0ffa9a 100644 --- a/examples/src/collections/ColossalCave.jetl +++ b/examples/src/collections/ColossalCave.jetl @@ -11,7 +11,7 @@ class World() { public val world: World get() = this@World } - public val items = new ArrayList + public val items = ArrayList() class Item(val name: String, var room: Room) { { @@ -29,11 +29,11 @@ class World() { } } - public val atEndOfRoad = new AtEndOfRoad() - public val atHillInRoad = new AtHillInRoad() - public val insideBuilding = new InsideBuilding() + public val atEndOfRoad = AtEndOfRoad() + public val atHillInRoad = AtHillInRoad() + public val insideBuilding = InsideBuilding() - public val brassLantern = new BrassLantern() + public val brassLantern = BrassLantern() class AtEndOfRoad(): Room("At End of Road") { public val west: Room? get() = atHillInRoad @@ -92,17 +92,17 @@ class EastCommand(): MoveCommand { } fun parse(cmd: String): Command? { - if (cmd == "quit") return new QuitCommand() - if (cmd == "west") return new WestCommand() - if (cmd == "east") return new EastCommand() + if (cmd == "quit") return QuitCommand() + if (cmd == "west") return WestCommand() + if (cmd == "east") return EastCommand() return null } fun main(args: Array) { - val w = new World() - val p = new Player(w.startRoom()) + val w = World() + val p = Player(w.startRoom()) System.out?.println(p.room.name) - val reader = new BufferedReader(new InputStreamReader(System.`in`)) + val reader = BufferedReader(InputStreamReader(System.`in`)) while(true) { System.out?.print("> ") val cmd = reader.readLine() as String