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<Cell> {
val mineCells = mutableListOf<Cell>()
gameBoardCells.forEach { cell ->
if (cell.isMine())
mineCells.add(cell)
}
return mineCells
}
fun getMineCells(): List<IntArray> {
val mineCells = mutableListOf<IntArray>()
gameBoardCells.forEach { cell ->
if (cell[0] == 4)
mineCells.add(cell)
}
return mineCells
}
fun getAveragePrice(vehicle: Vehicle): Int {
return when (vehicle) {
is CAR -> {
20000
}
is MOTORBIKE -> {
10000
}
is VAN -> {
25000
fun calculateCost(vehicle: Vehicle): Money {
return when (vehicle) {
is CAR -> {
CalculateCarCost(vehicle)
}
is MOTORBIKE -> {
CalculateMotorbikeCost(vehicle)
}
is VAN -> {
CalculateVanCost(vehicle)
package com.dropbox.affectedmoduledetector
import java.io.File
class AffectedModuleConfiguration {
/**
* Folder to place the log in
*/
var logFolder: String? = null
interface Vehicle {
fun getAveragePrice(): Int
fun calculateCost(): Money
fun calculateDailyMaintanence(): Money
}
class VehicleFactory() {
fun makeVehicle(type: VehicleType): Vehicle {
when (type) {
is CAR -> {
@jonnycaley
jonnycaley / BuildTimeLoggerPlugin.kt
Created June 18, 2022 13:57
BuildTimeLoggerPlugin - register build task service
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildTaskService = registerBuildTaskService(gradle)
}
private fun registerBuildTaskService(gradle: Gradle): Provider<BuildTaskService> {
val registry = gradle.serviceRegistry()[BuildEventListenerRegistryInternal::class.java]
val buildTaskService = gradle.sharedServices.registerIfAbsent("build-task-service", BuildTaskService::class.java) { }
@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 / BuildTimeLoggerPlugin.kt
Created June 18, 2022 15:44
BuildTimeLoggerPlugin - register build reporter service
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildDurationService = registerBuildDurationService(gradle)
val buildTaskService = registerBuildTaskService(gradle)
registerBuildReporterService(gradle, buildDurationService, buildTaskService)
}
@jonnycaley
jonnycaley / BuildReporterService.kt
Last active June 18, 2022 16:33
BuildReporterService - report data from other services
abstract class BuildReporterService : BuildService<BuildReporterService.Params>, BuildOperationListener, AutoCloseable {
interface Params : BuildServiceParameters {
fun getBuildDurationServiceProvider(): Property<Provider<BuildDurationService>>
fun getBuildTaskServiceProvider(): Property<Provider<BuildTaskService>>
}
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}