Skip to content

Commit

Permalink
Partially apply M13 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dzharkov committed Sep 16, 2015
1 parent b6c81c1 commit 1f4f821
Show file tree
Hide file tree
Showing 50 changed files with 92 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/ii_conventions/MyDateUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ fun MyDate.nextDay() = addTimeIntervals(DAY, 1)
fun MyDate.addTimeIntervals(timeInterval: TimeInterval, number: Int): MyDate {
val c = Calendar.getInstance()
c.set(year + if (timeInterval == YEAR) number else 0, month, dayOfMonth)
var timeInMillis = c.getTimeInMillis()
var timeInMillis = c.timeInMillis
val millisecondsInADay = 24 * 60 * 60 * 1000L
timeInMillis += number * when (timeInterval) {
DAY -> millisecondsInADay
WEEK -> 7 * millisecondsInADay
YEAR -> 0L
}
val result = Calendar.getInstance()
result.setTimeInMillis(timeInMillis)
result.timeInMillis = timeInMillis
return MyDate(result.get(Calendar.YEAR), result.get(Calendar.MONTH), result.get(Calendar.DATE))
}
4 changes: 2 additions & 2 deletions src/iii_properties/_20_DelegatesExamples.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlin.properties.ReadWriteProperty

class A(initializer: () -> Int) {

val lazy: Int by Delegates.lazy(initializer)
val lazy: Int by lazy(LazyThreadSafetyMode.NONE, initializer)
}

class B() {
Expand Down Expand Up @@ -34,6 +34,6 @@ fun <T> todoTask20(): ReadWriteProperty<Commodity, T> = TODO(
references = {
val data = hashMapOf<String, Any?>("description" to "snowboard", "price" to 349, "isAvailable" to true)
Commodity(data)
Delegates.mapVar<Any>(data)
data
}
)
4 changes: 2 additions & 2 deletions src/iii_properties/_21_DelegatesHowItWorks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class EffectiveDate<R> : ReadWriteProperty<R, MyDate> {
fun MyDate.toMillis(): Long {
val c = Calendar.getInstance()
c.set(year, month, dayOfMonth)
return c.getTimeInMillis()
return c.timeInMillis
}

fun Long.toDate(): MyDate {
val c = Calendar.getInstance()
c.setTimeInMillis(this)
c.timeInMillis = this
return MyDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE))
}
4 changes: 2 additions & 2 deletions src/iv_builders/htmlDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import iv_builders.renderProductTable
fun main(args: Array<String>) {
with (JFrame("Product popularity")) {
setSize(600, 600)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
add(JScrollPane(JLabel(renderProductTable(), CENTER)))
setVisible(true)
isVisible = true
}
}

2 changes: 1 addition & 1 deletion src/syntax/casts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package syntax.casts

fun foo(a: Any?) {
if (a is String) {
val s = a as String
val s = a
}

if (a !is Int) return
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/classesObjectsInterfaces.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ fun useClassObject() {

fun localClass() {
// class or object can be declared locally in a function
@data class Local(val i: Int, val s: String) {}
data class Local(val i: Int, val s: String) {}
}
2 changes: 1 addition & 1 deletion src/syntax/operatorOverloading.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface B {
fun rangeTo(a: A): B
}

@suppress("UNUSED_CHANGED_VALUE", "UNUSED_VALUE")
@Suppress("UNUSED_CHANGED_VALUE", "UNUSED_VALUE")
fun binaryAndUnaryOperations(a: A, b: B) {
+b
-b
Expand Down
2 changes: 1 addition & 1 deletion src/util/kotlinUtil.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package util

suppress("UNUSED_PARAMETER")
@Suppress("UNUSED_PARAMETER")
fun TODO(task: String, vararg references: Any?) = throw NotImplementedException("TODO: $task")

class NotImplementedException(message: String): Exception(message)
2 changes: 1 addition & 1 deletion src/v_collections/F_Sort_.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v_collections

fun example5() {
val result = listOf("a", "bbb", "cc").sortBy { it.length() }
val result = listOf("a", "bbb", "cc").sortedBy { it.length() }

result == listOf("a", "cc", "bbb")
}
Expand Down
2 changes: 1 addition & 1 deletion test/i_introduction/_0_Hello_World/_00_Start.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import junit.framework.Assert
import org.junit.Test as test

class _00_Start {
test fun testOk() {
@test fun testOk() {
Assert.assertEquals("OK", task0())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.awt.event.MouseEvent
import java.awt.Component

class _10_Object_Expressions {
test fun testStringComparator() {
@test fun testStringComparator() {
val mouseEvent = MouseEvent(object : Component() {}, 0, 0L, 0, 0, 0, 1, false)
val result = task10 { mouseListener ->
mouseListener.mouseClicked(mouseEvent)
Expand Down
2 changes: 1 addition & 1 deletion test/i_introduction/_1_Functions/_01_Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.Test as test
import org.junit.Assert

class _01_Functions() {
test fun collection() {
@test fun collection() {
Assert.assertEquals("{1, 2, 3, 42, 555}", task1(listOf(1, 2, 3, 42, 555)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import org.junit.Assert

class _02_Default_And_Named_Params() {

test fun testDefaultAndNamedParams() {
@test fun testDefaultAndNamedParams() {
Assert.assertEquals("a42b1C42D2", task2_1())
}

test fun testJoinToString() {
@test fun testJoinToString() {
Assert.assertEquals("{1, 2, 3, 42, 555}", task2_2(listOf(1, 2, 3, 42, 555)))
}

Expand Down
4 changes: 2 additions & 2 deletions test/i_introduction/_3_Lambdas/_03_Lambdas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import org.junit.Test as test
import org.junit.Assert

class _03_Lambdas() {
test fun contains() {
@test fun contains() {
Assert.assertTrue(task3(listOf(1, 2, 3, 126, 555)))
}

test fun notContains() {
@test fun notContains() {
Assert.assertFalse(task3(listOf(44)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import org.junit.Assert
import java.util.regex.Pattern

class _04_String_Templates() {
test fun match() {
@test fun match() {
Assert.assertTrue(Pattern.compile(task4()).matcher("Douglas Adams (11 MAR 1952)").find())
}

test fun match1() {
@test fun match1() {
Assert.assertTrue(Pattern.compile(task4()).matcher("Stephen Fry (24 AUG 1957)").find())
}

test fun doNotMatch() {
@test fun doNotMatch() {
Assert.assertFalse(Pattern.compile(task4()).matcher("Stephen Fry (24 RRR 1957)").find())
}
}
10 changes: 5 additions & 5 deletions test/i_introduction/_5_Nullable_Types/_05_Nullable_Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ class _05_Nullable_Types {
shouldBeInvoked, invoked)
}

test fun everythingIsOk() {
@test fun everythingIsOk() {
testSendMessageToClient(Client(PersonalInfo("[email protected]")),
"Hi Bob! We have an awesome proposition for you...",
"[email protected]",
true)
}

test fun noMessage() {
@test fun noMessage() {
testSendMessageToClient(Client(PersonalInfo("[email protected]")), null)
}

test fun noEmail() {
@test fun noEmail() {
testSendMessageToClient(Client(PersonalInfo(null)), "Hi Bob! We have an awesome proposition for you...")
}

test fun noPersonalInfo() {
@test fun noPersonalInfo() {
testSendMessageToClient(Client(null), "Hi Bob! We have an awesome proposition for you...")
}

test fun noClient() {
@test fun noClient() {
testSendMessageToClient(null, "Hi Bob! We have an awesome proposition for you...")
}
}
6 changes: 3 additions & 3 deletions test/i_introduction/_6_Smart_Casts/_06_Smart_Casts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import org.junit.Test as test
import org.junit.Assert

class _06_Smart_Casts {
test fun testNum() {
@test fun testNum() {
Assert.assertEquals("'print' on Num should work:", "2", print(Num(2)))
}

test fun testSum() {
@test fun testSum() {
Assert.assertEquals("'print' on Sum should work:", "2 + 1", print(Sum(Num(2), Num(1))))
}

test fun testRecursion() {
@test fun testRecursion() {
Assert.assertEquals("'print' should work recursively:", "1 + 2 + 3", print(Sum(Sum(Num(1), Num(2)), Num(3))))
}
}
2 changes: 1 addition & 1 deletion test/i_introduction/_7_Data_Classes/_07_Data_Classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.Assert


public class _07_Data_Classes {
test fun testDelight() {
@test fun testDelight() {
Assert.assertTrue(task7())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import org.junit.Test as test
import org.junit.Assert

class _08_Extension_Functions() {
test fun testIntExtension() {
@test fun testIntExtension() {
Assert.assertEquals("Rational number creation error: ", RationalNumber(4, 1), 4.r())
}

test fun testPairExtension() {
@test fun testPairExtension() {
Assert.assertEquals("Rational number creation error: ", RationalNumber(2, 3), Pair(2, 3).r())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import org.junit.Test as test
import org.junit.Assert

class _09_Extensions_On_Collections {
test fun testCollectionOfOneElement() {
@test fun testCollectionOfOneElement() {
doTest(listOf("a"), listOf("a"))
}

test fun testEmptyCollection() {
@test fun testEmptyCollection() {
doTest(null, listOf())
}

test fun testSimpleCollection() {
@test fun testSimpleCollection() {
doTest(listOf("a", "c"), listOf("a", "bb", "c"))
}

test fun testCollectionWithEmptyStrings() {
@test fun testCollectionWithEmptyStrings() {
doTest(listOf("", "", "", ""), listOf("", "", "", "", "a", "bb", "ccc", "dddd"))
}

test fun testCollectionWithTwoGroupsOfMaximalSize() {
@test fun testCollectionWithTwoGroupsOfMaximalSize() {
doTest(listOf("a", "c"), listOf("a", "bb", "c", "dd"))
}

Expand Down
6 changes: 3 additions & 3 deletions test/ii_conventions/_11_Comparison.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import org.junit.Test as test
import ii_conventions.test.s

class _11_Comparison {
test fun testDateComparison() {
@test fun testDateComparison() {
Assert.assertTrue(task11(MyDate(2014, 1, 1), MyDate(2014, 1, 2)))
}

test fun testBefore() {
@test fun testBefore() {
val first = MyDate(2014, 5, 10)
val second = MyDate(2014, 7, 11)
Assert.assertTrue("The date ${first.s} should be before ${second.s}", first < second)
}

test fun testAfter() {
@test fun testAfter() {
val first = MyDate(2014, 10, 20)
val second = MyDate(2014, 7, 11)
Assert.assertTrue("The date ${first.s} should be after ${second.s}", first > second)
Expand Down
4 changes: 2 additions & 2 deletions test/ii_conventions/_12_For_Loop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.Test as test
import java.util.ArrayList

class _12_For_Loop {
test fun testIterateOverDateRange() {
@test fun testIterateOverDateRange() {
val actualDateRange = ArrayList<MyDate>()
iterateOverDateRange(MyDate(2014, 5, 1), MyDate(2014, 5, 5), {
date: MyDate -> actualDateRange.add(date)
Expand All @@ -16,7 +16,7 @@ class _12_For_Loop {
expectedDateRange, actualDateRange)
}

test fun testIterateOverEmptyRange() {
@test fun testIterateOverEmptyRange() {
var invoked = false
iterateOverDateRange(MyDate(2014, 1, 1), MyDate(2013, 1, 1), { invoked = true })
Assert.assertFalse("Handler was invoked on an empty range", invoked)
Expand Down
2 changes: 1 addition & 1 deletion test/ii_conventions/_13_Range_To.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.Test as test
import java.util.ArrayList

class _13_Range_To {
test fun testIterateOverDateRange() {
@test fun testIterateOverDateRange() {
val actualDateRange = ArrayList<MyDate>()
iterateOverDateRange2(MyDate(2014, 5, 1), MyDate(2014, 5, 2), {
date: MyDate -> actualDateRange.add(date)
Expand Down
6 changes: 3 additions & 3 deletions test/ii_conventions/_14_In_Range.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class _14_In_Range {
Assert.assertEquals(message, shouldBeInRange, checkInRange(date, first, last))
}

test fun testInRange() {
@test fun testInRange() {
doTest(MyDate(2014, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = true)
}

test fun testBefore() {
@test fun testBefore() {
doTest(MyDate(2013, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = false)
}

test fun testAfter() {
@test fun testAfter() {
doTest(MyDate(2015, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = false)
}
}
8 changes: 4 additions & 4 deletions test/ii_conventions/_15_Operators_Overloading.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import org.junit.Test as test
import ii_conventions.TimeInterval.*

class _15_Operators_Overloading {
test fun testAddTimeIntervals() {
@test fun testAddTimeIntervals() {
Assert.assertEquals(MyDate(2014, 5, 22), MyDate(1983, 5, 22).addTimeIntervals(YEAR, 31))
Assert.assertEquals(MyDate(1983, 5, 29), MyDate(1983, 5, 22).addTimeIntervals(DAY, 7))
Assert.assertEquals(MyDate(1983, 5, 29), MyDate(1983, 5, 22).addTimeIntervals(WEEK, 1))
}

test fun testAddOneTimeInterval() {
@test fun testAddOneTimeInterval() {
Assert.assertEquals(MyDate(2015, 5, 8), task15_1(MyDate(2014, 5, 1)))
}

test fun testOneMonth() {
@test fun testOneMonth() {
Assert.assertEquals(MyDate(2016, 0, 27), task15_2(MyDate(2014, 0, 1)))
}

test fun testMonthChange() {
@test fun testMonthChange() {
Assert.assertEquals(MyDate(2016, 1, 20), task15_2(MyDate(2014, 0, 25)))
}
}
2 changes: 1 addition & 1 deletion test/ii_conventions/_16_Multi_Assignment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import junit.framework.Assert
import org.junit.Test as test

class _16_Multi_Assignment {
test fun testTask16() {
@test fun testTask16() {
Assert.assertTrue(task16())
}
}
Loading

0 comments on commit 1f4f821

Please sign in to comment.