Skip to content

Instantly share code, notes, and snippets.

Avatar

Murat Yener yenerm

  • Google
  • San Francisco
View GitHub Profile
View Person.kt
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
var address: String by Delegates.vetoable("") {
property, oldValue, newValue ->
newValue.length > 14
}
View Person$$special$$inlined$vetoable$1.java
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public final class Person$$special$$inlined$vetoable$1 extends ObservableProperty {
protected boolean beforeChange(@NotNull KProperty property, Object oldValue, Object newValue) {
Intrinsics.checkParameterIsNotNull(property, "property");
String newValue = (String)newValue;
String var10001 = (String)oldValue;
int var7 = false;
View NotNullVar.kt
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
private class NotNullVar<T : Any>() : ReadWriteProperty<Any?, T> {
private var value: T? = null
public override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.")
}
View Person.kt
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, var lastname: String) {
var name: String = name
set(value) {
name = value.toLowerCase().capitalize()
updateCount++
}
var updateCount = 0
View Person.kt
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
var name: String by FormatDelegate()
var lastname: String by FormatDelegate()
var updateCount = 0
}
View FormatDelegate.kt
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class FormatDelegate : ReadWriteProperty<Any?, String> {
private var formattedString: String = ""
override fun getValue(
thisRef: Any?,
property: KProperty<*>
): String {
View Person.kt
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
var name: String = name
set(value) {
name = value.toLowerCase().capitalize()
updateCount++
}
var lastname: String = lastname
View FormatDelegate.kt
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
override fun setValue(
thisRef: Any?,
property: KProperty<*>,
value: String
) {
if (thisRef is Person) {
thisRef.updateCount++
View ListWithTrash.kt
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class ListWithTrash <T>(
private val innerList: MutableList<T> = ArrayList<T>()
) : MutableCollection<T> by innerList {
var deletedItem : T? = null
override fun remove(element: T): Boolean {
deletedItem = element
return innerList.remove(element)
View ListWithTrash.$java
public final class ListWithTrash implements Collection, KMutableCollection {
@Nullable
private Object deletedItem;
private final List innerList;
@Nullable
public final Object getDeletedItem() {
return this.deletedItem;
}