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
/** | |
* Handles checking when data should be considered stale, and invokes a function to refresh data. | |
* | |
*/ | |
@DataScope class StaleDataObservatory( | |
/** | |
* Duration the data is considered "fresh" | |
*/ | |
syncInterval: Long, |
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
/** | |
* A controller that loads a shopping cart (think online shopping). | |
*/ | |
public class CartControllerImpl implements CartController { | |
final CartModel model; | |
final TaxModel taxModel; | |
final CurrencyUnit currencyUnit; | |
final MoneyFormatter moneyFormatter; | |
final RxBus rxBus; |
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
fun <T, R> Observable<T>.scanMap(func2: (T?, T) -> R): Observable<R> { | |
return this.startWith(null as T?) //emit a null value first, otherwise the .buffer() below won't emit at first (needs 2 emissions to emit) | |
.buffer(2, 1) //buffer the previous and current emission | |
.filter { it.size >= 2 } | |
.map { func2.invoke(it[0], it[1]) } | |
} | |
fun <T, R> Observable<T>.scanMap(initialValue: T, func2: (T, T) -> R): Observable<R> { | |
return this.startWith(initialValue) //use initially provided value instead of null | |
.buffer(2, 1) |
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
@Test | |
fun testClear() { | |
clickNumber(1) | |
clickNumber(2) | |
clickNumber(3) | |
state.assertValue(123) | |
longPressClear() | |
state.assertValue(0) | |
} |
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
/** | |
* The user interface for dealing cards. | |
* | |
* @see DealCardsActivity | |
*/ | |
interface DealCardsUi : StateRenderer<DealCardsUi.State> { | |
val state: State | |
override fun render(state: State) |
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
import android.animation.Animator | |
import android.animation.AnimatorListenerAdapter | |
import android.content.Context | |
import android.view.View | |
import android.view.ViewGroup | |
/** | |
* Animates a view between its states. | |
* | |
* Currently only supports crossfading. |
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
class TemporalCoupling { | |
fun incorrectUsageOfBadApi() { | |
val badApi: BadApi = BadApi() | |
badApi.username = "Zak" | |
badApi.password = "temporalCouplingIsBad_123" | |
badApi.login() //throws an NullPointerException | |
} |
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
import org.junit.Test; | |
import java.util.function.Consumer; | |
/** | |
* Note: no actual assertions are done here. | |
*/ | |
public class FizzBuzzTest { | |
static void defaultPrint(BaseFizzBuzz base) { |
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
package com.example.taccardi.zak; | |
import android.support.annotation.NonNull; | |
import io.reactivex.Observable; | |
/** | |
* Use this class to lock (prevent charges to it) or unlock (allow charges) a card. | |
*/ | |
interface CardLockRepository { |
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
class UserRepository{ | |
// note: hot observables that do not replay missed events | |
fun logins(): Observable<User> | |
fun logouts(): Observable<Unit> | |
} | |
/** | |
* An abstract user with two implementations: | |
* "LoggedIn" and "Logged out" | |
*/ |