Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Working on React native and Android as the Team Lead of Carwale

BAL SIKANDAR balsikandar

💭
Working on React native and Android as the Team Lead of Carwale
View GitHub Profile
View PolymorphismToAvoidIf.kt
fun main() {
val carDealer = CarDealer()
println(carDealer.getSpeed(VehicleTypes.BUS))
}
class CarDealer {
val map = HashMap<VehicleTypes, Vehicle>()
init {
map.put(VehicleTypes.CAR, Car())
View IfElseChainSolution3.kt
if (pickupSelected && dropSelected) return gotoNextPage()
var msg: String? = "Please select pickup location"
if (selectedTab === "PICKUP_POINT" && pickupSelected) {
goToDrop()
msg = null
}
msg = msg ?: "Please select drop location"
if (selectedTab === "DROP_POINT" && dropSelected) {
View ifElseChainSolution2.kt
if (pickupSelected && dropSelected) return gotoNextPage()
if (selectedTab === "PICKUP_POINT") {
if (pickupSelected) {
goToDrop();
} else {
toast("Please select pickup location")
}
}
View IfElseChainSolution4.kt
fun main() {
if (pickupSelected && dropSelected) return gotoNextPage()
if (selectedTab === "PICKUP_POINT") {
verifyPickup(pickupSelected)
}
if (selectedTab === "DROP_POINT") {
verifyDropOff(dropSelected)
}
View ifElseChainSolution1.kt
if (pickupSelected && dropSelected) {
return gotoNextPage();
}
if (selectedTab === "PICKUP_POINT") {
if (pickupSelected) {
goToDrop();
} else {
toast("Please select pickup location")
}
View IfElseChain.kt
if (pickupSelected && dropSelected) {
gotoNextPage();
} else if (selectedTab === "PICKUP_POINT") {
if (pickupSelected) {
goToDrop();
} else {
toast("Please select pickup location")
}
} else {
if (dropSelected) {
View IfAndElseChain.kt
getCurrencyNameOf("UK")
fun getCurrencyNameOf(country: String): String {
return if (country == "India") {
"Rupee"
} else if (country == "USA") {
"Dollars"
} else if (country == "UK") {
"Euro"
} else if (country == "Japan") {
View AvoidIfExample.kt
class Currency {
val map = HashMap<String, String>();
init {
map.put("India", "Rupee")
map.put("UK", "Euro")
map.put("Japan", "Yen")
map.put("USA", "Dollar")
map.put("China", "Yuan")
}
View EnableAutoStart.kt
try {
val intent = Intent()
val manufacturer = Build.MANUFACTURER
if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName(
"com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"
)
} else if ("oppo".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName(
@balsikandar
balsikandar / StudentBuilder.kt
Created Jan 19, 2020
Student Builder pattern example
View StudentBuilder.kt
class Student(
val name: String?,
val standard: Int,
val rollNumber: Int
) {
private constructor(builder: Builder) : this(builder.name, builder.standard, builder.rollNumber)
class Builder {
var name: String? = null