Skip to content

Commit 96f5d9c

Browse files
author
Dr. Brandon Wiley
committed
Finished porting symbols to new interface
1 parent e676e5a commit 96f5d9c

File tree

8 files changed

+195
-178
lines changed

8 files changed

+195
-178
lines changed
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package org.operatorfoundation.codex.Symbols
1+
package org.operatorfoundation.codex.symbols
22

3-
class CallLetter {
4-
val length: Int
5-
get() = 26
3+
class CallLetter : Symbol {
4+
override fun size(): Int {
5+
return 26
6+
}
67

78
override fun toString(): String {
89
return "CallLetter"
910
}
1011

11-
fun decode(n: ByteArray): Int {
12-
return when (n) {
12+
override fun decode(encodedValue: ByteArray): Int {
13+
return when (encodedValue.toString()) {
1314
"A" -> 0
1415
"B" -> 1
1516
"C" -> 2
@@ -36,39 +37,39 @@ class CallLetter {
3637
"X" -> 23
3738
"Y" -> 24
3839
"Z" -> 25
39-
else -> throw IllegalArgumentException("CallLetter, bad value: $n")
40+
else -> throw IllegalArgumentException("CallLetter, bad value: $encodedValue")
4041
}
4142
}
4243

43-
fun encode(n: Int): ByteArray {
44-
return when (n) {
45-
0 -> "A"
46-
1 -> "B"
47-
2 -> "C"
48-
3 -> "D"
49-
4 -> "E"
50-
5 -> "F"
51-
6 -> "G"
52-
7 -> "H"
53-
8 -> "I"
54-
9 -> "J"
55-
10 -> "K"
56-
11 -> "L"
57-
12 -> "M"
58-
13 -> "N"
59-
14 -> "O"
60-
15 -> "P"
61-
16 -> "Q"
62-
17 -> "R"
63-
18 -> "S"
64-
19 -> "T"
65-
20 -> "U"
66-
21 -> "V"
67-
22 -> "W"
68-
23 -> "X"
69-
24 -> "Y"
70-
25 -> "Z"
71-
else -> throw IllegalArgumentException("Unknown value $n for CallLetter")
44+
override fun encode(numericValue: Int): ByteArray {
45+
return when (numericValue) {
46+
0 -> "A".toByteArray()
47+
1 -> "B".toByteArray()
48+
2 -> "C".toByteArray()
49+
3 -> "D".toByteArray()
50+
4 -> "E".toByteArray()
51+
5 -> "F".toByteArray()
52+
6 -> "G".toByteArray()
53+
7 -> "H".toByteArray()
54+
8 -> "I".toByteArray()
55+
9 -> "J".toByteArray()
56+
10 -> "K".toByteArray()
57+
11 -> "L".toByteArray()
58+
12 -> "M".toByteArray()
59+
13 -> "N".toByteArray()
60+
14 -> "O".toByteArray()
61+
15 -> "P".toByteArray()
62+
16 -> "Q".toByteArray()
63+
17 -> "R".toByteArray()
64+
18 -> "S".toByteArray()
65+
19 -> "T".toByteArray()
66+
20 -> "U".toByteArray()
67+
21 -> "V".toByteArray()
68+
22 -> "W".toByteArray()
69+
23 -> "X".toByteArray()
70+
24 -> "Y".toByteArray()
71+
25 -> "Z".toByteArray()
72+
else -> throw IllegalArgumentException("Unknown value $numericValue for CallLetter")
7273
}
7374
}
7475
}

Codex/src/main/java/org/operatorfoundation/codex/symbols/CallLetterNumber.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class CallLetterNumber : Symbol {
99
return "CallLetterNumber"
1010
}
1111

12-
override fun decode(n: ByteArray): Int {
13-
return when (n.toString()) {
12+
override fun decode(encodedValue: ByteArray): Int {
13+
return when (encodedValue.toString()) {
1414
"A" -> 0
1515
"B" -> 1
1616
"C" -> 2
@@ -47,12 +47,12 @@ class CallLetterNumber : Symbol {
4747
"7" -> 33
4848
"8" -> 34
4949
"9" -> 35
50-
else -> throw IllegalArgumentException("CallLetterNumber, bad value: $n")
50+
else -> throw IllegalArgumentException("CallLetterNumber, bad value: $encodedValue")
5151
}
5252
}
5353

54-
override fun encode(n: Int): ByteArray {
55-
return when (n) {
54+
override fun encode(numericValue: Int): ByteArray {
55+
return when (numericValue) {
5656
0 -> "A".toByteArray()
5757
1 -> "B".toByteArray()
5858
2 -> "C".toByteArray()
@@ -89,7 +89,7 @@ class CallLetterNumber : Symbol {
8989
33 -> "7".toByteArray()
9090
34 -> "8".toByteArray()
9191
35 -> "9".toByteArray()
92-
else -> throw IllegalArgumentException("Unknown value $n for CallLetterNumber")
92+
else -> throw IllegalArgumentException("Unknown value $numericValue for CallLetterNumber")
9393
}
9494
}
9595
}
Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
package org.operatorfoundation.codex.Symbols
1+
package org.operatorfoundation.codex.symbols
22

3-
class CallLetterSpace {
4-
val length: Int
5-
get() = 27
3+
class CallLetterSpace : Symbol {
4+
override fun size(): Int
5+
{
6+
return 27
7+
}
68

79
override fun toString(): String {
810
return "CallLetterSpace"
911
}
1012

11-
fun decode(n: ByteArray): Int {
12-
return when (n) {
13+
override fun decode(encodedValue: ByteArray): Int {
14+
return when (encodedValue.toString()) {
1315
"A" -> 0
1416
"B" -> 1
1517
"C" -> 2
@@ -37,40 +39,40 @@ class CallLetterSpace {
3739
"Y" -> 24
3840
"Z" -> 25
3941
" " -> 26
40-
else -> throw IllegalArgumentException("CallLetterSpace, bad value: $n")
42+
else -> throw IllegalArgumentException("CallLetterSpace, bad value: $encodedValue")
4143
}
4244
}
4345

44-
fun encode(n: Int): ByteArray {
45-
return when (n) {
46-
0 -> "A"
47-
1 -> "B"
48-
2 -> "C"
49-
3 -> "D"
50-
4 -> "E"
51-
5 -> "F"
52-
6 -> "G"
53-
7 -> "H"
54-
8 -> "I"
55-
9 -> "J"
56-
10 -> "K"
57-
11 -> "L"
58-
12 -> "M"
59-
13 -> "N"
60-
14 -> "O"
61-
15 -> "P"
62-
16 -> "Q"
63-
17 -> "R"
64-
18 -> "S"
65-
19 -> "T"
66-
20 -> "U"
67-
21 -> "V"
68-
22 -> "W"
69-
23 -> "X"
70-
24 -> "Y"
71-
25 -> "Z"
72-
26 -> " "
73-
else -> throw IllegalArgumentException("Unknown value $n for CallLetterSpace")
46+
override fun encode(numericValue: Int): ByteArray {
47+
return when (numericValue) {
48+
0 -> "A".toByteArray()
49+
1 -> "B".toByteArray()
50+
2 -> "C".toByteArray()
51+
3 -> "D".toByteArray()
52+
4 -> "E".toByteArray()
53+
5 -> "F".toByteArray()
54+
6 -> "G".toByteArray()
55+
7 -> "H".toByteArray()
56+
8 -> "I".toByteArray()
57+
9 -> "J".toByteArray()
58+
10 -> "K".toByteArray()
59+
11 -> "L".toByteArray()
60+
12 -> "M".toByteArray()
61+
13 -> "N".toByteArray()
62+
14 -> "O".toByteArray()
63+
15 -> "P".toByteArray()
64+
16 -> "Q".toByteArray()
65+
17 -> "R".toByteArray()
66+
18 -> "S".toByteArray()
67+
19 -> "T".toByteArray()
68+
20 -> "U".toByteArray()
69+
21 -> "V".toByteArray()
70+
22 -> "W".toByteArray()
71+
23 -> "X".toByteArray()
72+
24 -> "Y".toByteArray()
73+
25 -> "Z".toByteArray()
74+
26 -> " ".toByteArray()
75+
else -> throw IllegalArgumentException("Unknown value $numericValue for CallLetterSpace")
7476
}
7577
}
7678
}
Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package org.operatorfoundation.codex.Symbols
1+
package org.operatorfoundation.codex.symbols
22

3-
class GridLetter {
4-
val length: Int
5-
get() = 18
3+
class GridLetter : Symbol {
4+
override fun size(): Int {
5+
return 18
6+
}
67

78
override fun toString(): String {
89
return "GridLetter"
910
}
1011

11-
fun decode(n: ByteArray): Int {
12-
return when (n) {
12+
override fun decode(encodedValue: ByteArray): Int {
13+
return when (encodedValue.toString()) {
1314
"A" -> 0
1415
"B" -> 1
1516
"C" -> 2
@@ -21,31 +22,31 @@ class GridLetter {
2122
"I" -> 8
2223
"J" -> 9
2324
"K" -> 10
24-
else -> throw IllegalArgumentException("GridLetter, bad value $n")
25+
else -> throw IllegalArgumentException("GridLetter, bad value $encodedValue")
2526
}
2627
}
2728

28-
fun encode(n: Int): ByteArray {
29-
return when (n) {
30-
0 -> "A"
31-
1 -> "B"
32-
2 -> "C"
33-
3 -> "D"
34-
4 -> "E"
35-
5 -> "F"
36-
6 -> "G"
37-
7 -> "H"
38-
8 -> "I"
39-
9 -> "J"
40-
10 -> "K"
41-
11 -> "L"
42-
12 -> "M"
43-
13 -> "N"
44-
14 -> "O"
45-
15 -> "P"
46-
16 -> "Q"
47-
17 -> "R"
48-
else -> throw IllegalArgumentException("Unknown value $n for GridLetter")
29+
override fun encode(numericValue: Int): ByteArray {
30+
return when (numericValue) {
31+
0 -> "A".toByteArray()
32+
1 -> "B".toByteArray()
33+
2 -> "C".toByteArray()
34+
3 -> "D".toByteArray()
35+
4 -> "E".toByteArray()
36+
5 -> "F".toByteArray()
37+
6 -> "G".toByteArray()
38+
7 -> "H".toByteArray()
39+
8 -> "I".toByteArray()
40+
9 -> "J".toByteArray()
41+
10 -> "K".toByteArray()
42+
11 -> "L".toByteArray()
43+
12 -> "M".toByteArray()
44+
13 -> "N".toByteArray()
45+
14 -> "O".toByteArray()
46+
15 -> "P".toByteArray()
47+
16 -> "Q".toByteArray()
48+
17 -> "R".toByteArray()
49+
else -> throw IllegalArgumentException("Unknown value $numericValue for GridLetter")
4950
}
5051
}
5152
}
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package org.operatorfoundation.codex.Symbols
1+
package org.operatorfoundation.codex.symbols
22

3-
class Number {
4-
val length: Int
5-
get() = 10
3+
class Number : Symbol {
4+
override fun size(): Int {
5+
return 10
6+
}
67

78
override fun toString(): String {
89
return "Number"
910
}
1011

11-
fun decode(n: ByteArray): Int {
12-
return when (n) {
12+
override fun decode(encodedValue: ByteArray): Int {
13+
return when (encodedValue.toString()) {
1314
"0" -> 0
1415
"1" -> 1
1516
"2" -> 2
@@ -20,23 +21,23 @@ class Number {
2021
"7" -> 7
2122
"8" -> 8
2223
"9" -> 9
23-
else -> throw IllegalArgumentException("Number, bad value: $n")
24+
else -> throw IllegalArgumentException("Number, bad value: $encodedValue")
2425
}
2526
}
2627

27-
fun encode(n: Int): ByteArray {
28-
return when (n) {
29-
0 -> "0"
30-
1 -> "1"
31-
2 -> "2"
32-
3 -> "3"
33-
4 -> "4"
34-
5 -> "5"
35-
6 -> "6"
36-
7 -> "7"
37-
8 -> "8"
38-
9 -> "9"
39-
else -> throw IllegalArgumentException("Unknown value $n for Number")
28+
override fun encode(numericValue: Int): ByteArray {
29+
return when (numericValue) {
30+
0 -> "0".toByteArray()
31+
1 -> "1".toByteArray()
32+
2 -> "2".toByteArray()
33+
3 -> "3".toByteArray()
34+
4 -> "4".toByteArray()
35+
5 -> "5".toByteArray()
36+
6 -> "6".toByteArray()
37+
7 -> "7".toByteArray()
38+
8 -> "8".toByteArray()
39+
9 -> "9".toByteArray()
40+
else -> throw IllegalArgumentException("Unknown value $numericValue for Number")
4041
}
4142
}
4243
}

0 commit comments

Comments
 (0)