Skip to content

Instantly share code, notes, and snippets.

View jonnycaley's full-sized avatar
💻
Working

Jonny Caley jonnycaley

💻
Working
View GitHub Profile
fun getMineCells(): List<IntArray> {
val mineCells = mutableListOf<IntArray>()
gameBoardCells.forEach { cell ->
if (cell[0] == 4)
mineCells.add(cell)
}
return mineCells
}
fun getMineCells(): List<Cell> {
val mineCells = mutableListOf<Cell>()
gameBoardCells.forEach { cell ->
if (cell.isMine())
mineCells.add(cell)
}
return mineCells
}
fun calculateCost(vehicle: Vehicle): Money {
return when (vehicle) {
is CAR -> {
CalculateCarCost(vehicle)
}
is MOTORBIKE -> {
CalculateMotorbikeCost(vehicle)
}
is VAN -> {
CalculateVanCost(vehicle)
fun getAveragePrice(vehicle: Vehicle): Int {
return when (vehicle) {
is CAR -> {
20000
}
is MOTORBIKE -> {
10000
}
is VAN -> {
25000
interface Vehicle {
fun getAveragePrice(): Int
fun calculateCost(): Money
fun calculateDailyMaintanence(): Money
}
class VehicleFactory() {
fun makeVehicle(type: VehicleType): Vehicle {
when (type) {
is CAR -> {
package com.dropbox.affectedmoduledetector
import java.io.File
class AffectedModuleConfiguration {
/**
* Folder to place the log in
*/
var logFolder: String? = null
@jonnycaley
jonnycaley / BuildTimeLoggerPlugin.kt
Last active June 18, 2022 14:00
Register BuildDurationService
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildDurationService = registerBuildDurationService(gradle)
}
private fun registerBuildDurationService(gradle: Gradle): Provider<BuildDurationService> {
val registry = gradle.serviceRegistry()[BuildEventListenerRegistryInternal::class.java]
val buildDurationService = gradle.sharedServices.registerIfAbsent("build-duration-service", BuildDurationService::class.java) { }
@jonnycaley
jonnycaley / BuildDurationService.kt
Last active June 21, 2022 08:10
BuildDurationService - Capturing build time
abstract class BuildDurationService : BuildService<BuildServiceParameters.None>, BuildOperationListener, AutoCloseable {
var buildDuration: Long? = null
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}
override fun finished(buildOperationDescriptor: BuildOperationDescriptor, operationFinishEvent: OperationFinishEvent) {
if (buildOperationDescriptor.details is RunRootBuildWorkBuildOperationType.Details) {
@jonnycaley
jonnycaley / BuildDurationService.kt
Last active June 21, 2022 08:10
BuildDurationService - build and configuration time
abstract class BuildDurationService : BuildService<BuildServiceParameters.None>, BuildOperationListener, AutoCloseable {
var buildDuration: Long? = null
var configurationDuration: Long? = null
var configurationPhaseFailed = true
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}
@jonnycaley
jonnycaley / BuildTaskService.kt
Last active June 21, 2022 08:17
BuildTaskService - capturing task execution information
abstract class BuildTaskService : BuildService<BuildServiceParameters.None>, OperationCompletionListener {
var fromCacheTasksCount = 0
var upToDateTasksCount = 0
var executedTasksCount = 0
var buildPhaseFailureMessage: String? = null
val buildPhaseFailed: Boolean
get() = buildPhaseFailureMessage != null