Permalink
Browse files

Renamed tuples from other code.

  • Loading branch information...
1 parent c458ed3 commit 655f9e01a212064ab5a1f63b3e6a4c7f5bcc11e0 Evgeny Gerashchenko committed Mar 18, 2013
@@ -62,9 +62,9 @@ var JFrame.title : String
get() = getTitle()!!
set(t) {setTitle(t)}
-var JFrame.size : #(Int, Int)
- get() = #(getSize()!!.getWidth().toInt(), getSize()!!.getHeight().toInt())
- set(dim) {setSize(Dimension(dim._1, dim._2))}
+var JFrame.size : Pair<Int, Int>
+ get() = Pair(getSize()!!.getWidth().toInt(), getSize()!!.getHeight().toInt())
+ set(dim) {setSize(Dimension(dim.first, dim.second))}
var JFrame.height : Int
get() = getSize()!!.getHeight().toInt()
@@ -25,11 +25,11 @@ import java.util.*
* free space (a path does not go through walls). One can move only
* straightly up, down, left or right, no diagonal moves allowed.
*/
-fun findPath(maze : Maze) : List<#(Int, Int)>? {
- val previous = HashMap<#(Int, Int), #(Int, Int)>
+fun findPath(maze : Maze) : List<Pair<Int, Int>>? {
+ val previous = HashMap<Pair<Int, Int>, Pair<Int, Int>>
- val queue = LinkedList<#(Int, Int)>
- val visited = HashSet<#(Int, Int)>
+ val queue = LinkedList<Pair<Int, Int>>
+ val visited = HashSet<Pair<Int, Int>>
queue.offer(maze.start)
visited.add(maze.start)
@@ -47,7 +47,7 @@ fun findPath(maze : Maze) : List<#(Int, Int)>? {
if (previous[maze.end] == null) return null
- val path = ArrayList<#(Int, Int)>()
+ val path = ArrayList<Pair<Int, Int>>()
var current = previous[maze.end]
while (current != maze.start) {
path.add(0, current)
@@ -59,21 +59,21 @@ fun findPath(maze : Maze) : List<#(Int, Int)>? {
/**
* Find neighbors of the (i, j) cell that are not walls
*/
-fun Maze.neighbors(i : Int, j : Int) : List<#(Int, Int)> {
- val result = ArrayList<#(Int, Int)>
+fun Maze.neighbors(i : Int, j : Int) : List<Pair<Int, Int>> {
+ val result = ArrayList<Pair<Int, Int>>
addIfFree(i - 1, j, result)
addIfFree(i, j - 1, result)
addIfFree(i + 1, j, result)
addIfFree(i, j + 1, result)
return result
}
-fun Maze.addIfFree(i : Int, j : Int, result : List<#(Int, Int)>) {
+fun Maze.addIfFree(i : Int, j : Int, result : List<Pair<Int, Int>>) {
if (i !in 0..height-1) return
if (j !in 0..width-1) return
if (walls[i][j]) return
- result.add(#(i, j))
+ result.add(Pair(i, j))
}
/**
@@ -87,9 +87,9 @@ class Maze(
// true for a wall, false for free space
val walls : Array<out Array<out Boolean>>,
// The starting point (must not be a wall)
- val start : #(Int, Int),
+ val start : Pair<Int, Int>,
// The target point (must not be a wall)
- val end : #(Int, Int)
+ val end : Pair<Int, Int>
) {
}
@@ -137,7 +137,7 @@ fun printMaze(str : String) {
val path = findPath(maze)
for (i in 0..maze.height - 1) {
for (j in 0..maze.width - 1) {
- val cell = #(i, j)
+ val cell = Pair(i, j)
print(
if (maze.walls[i][j]) "O"
else if (cell == maze.start) "I"
@@ -179,16 +179,16 @@ fun makeMaze(s : String) : Maze {
})!!
val data = Array<Array<Boolean>>(lines.size) {Array<Boolean>(w.size) {false}}
- var start : #(Int, Int)? = null
- var end : #(Int, Int)? = null
+ var start : Pair<Int, Int>? = null
+ var end : Pair<Int, Int>? = null
for (line in lines.indices) {
for (x in lines[line].indices) {
val c = lines[line]!![x]
data[line][x] = c == 'O'
when (c) {
- 'I' -> start = #(line, x)
- '$' -> end = #(line, x)
+ 'I' -> start = Pair(line, x)
+ '$' -> end = Pair(line, x)
else -> {}
}
}
@@ -348,9 +348,9 @@ public trait Traversable<T>: Iterable<T> {
* @includeFunctionBody ../../test/ListTest.kt withIndices
*/
/*
- public fun withIndices(): java.lang.Iterable<#(Int, T)> {
- return object : java.lang.Iterable<#(Int, T)> {
- public override fun iterator(): Iterator<#(Int, T)> {
+ public fun withIndices(): java.lang.Iterable<Pair(Int, T)> {
+ return object : java.lang.Iterable<Pair(Int, T)> {
+ public override fun iterator(): Iterator<Pair(Int, T)> {
return NumberedIterator<T>(iterator())
}
}
@@ -119,7 +119,7 @@ class MapJsTest {
/*
test fun createLinkedMap() {
- val map = linkedMap(#("c", 3), #("b", 2), #("a", 1))
+ val map = linkedMapOf("c" to 3, "b" to 2, "a" to 1)
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
assertEquals(3, map.get("c"))
@@ -183,15 +183,15 @@ class MapJsTest {
}
test fun createSortedMap() {
- val map = sortedMap(#("c", 3), #("b", 2), #("a", 1))
+ val map = sortedMapOf("c" to 3, "b" to 2, "a" to 1)
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
assertEquals(3, map.get("c"))
assertEquals(arrayList("a", "b", "c"), map.keySet()!!.toList())
}
test fun toSortedMap() {
- val map = hashMap<String,Int>(#("c", 3), #("b", 2), #("a", 1))
+ val map = hashMapOf<String,Int>("c" to 3, "b" to 2, "a" to 1)
val sorted = map.toSortedMap<String,Int>()
assertEquals(1, sorted.get("a"))
assertEquals(2, sorted.get("b"))
@@ -200,7 +200,7 @@ class MapJsTest {
}
test fun toSortedMapWithComparator() {
- val map = hashMap(#("c", 3), #("bc", 2), #("bd", 4), #("abc", 1))
+ val map = hashMapOf("c" to 3, "bc" to 2, "bd" to 4, "abc" to 1)
val c = comparator<String>{ a, b ->
val answer = a.length() - b.length()
if (answer == 0) a.compareTo(b) else answer

0 comments on commit 655f9e0

Please sign in to comment.