Skip to content

Commit

Permalink
Use Kotlin official style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Sep 21, 2023
1 parent b952670 commit 5bc4809
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 207 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = disabled

[*.md]
trim_trailing_whitespace = false

[*.{json,yaml,yml}]
indent_style = space
indent_size = 2
86 changes: 0 additions & 86 deletions gradle/publishing.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

package org.radarbase.kotlin.coroutines

import kotlinx.coroutines.*
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.consume
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.withContext
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import kotlin.coroutines.CoroutineContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.radarbase.ktor.auth

import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.http.HttpHeaders

fun HttpRequestBuilder.bearer(token: String) {
headers[HttpHeaders.Authorization] = "Bearer $token"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package org.radarbase.ktor.auth

import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.plugins.auth.*
import io.ktor.client.plugins.auth.providers.*
import io.ktor.client.request.*
import io.ktor.client.request.forms.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.http.auth.*
import io.ktor.util.*
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthProvider
import io.ktor.client.plugins.auth.providers.BearerAuthConfig
import io.ktor.client.plugins.auth.providers.BearerAuthProvider
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.accept
import io.ktor.client.request.forms.submitForm
import io.ktor.client.request.headers
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsText
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.Parameters
import io.ktor.http.auth.AuthScheme
import io.ktor.http.auth.HttpAuthHeader
import io.ktor.http.isSuccess
import io.ktor.util.KtorDsl
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import org.slf4j.LoggerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.lessThan
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.math.BigDecimal
import java.math.BigDecimal.valueOf
import java.math.BigInteger
import java.nio.ByteBuffer
import java.util.*
import java.util.Objects

/**
* Java class to aggregate data using Kafka Streams. Double is the base type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
package org.radarbase.mock

import com.opencsv.exceptions.CsvValidationException
import io.ktor.client.call.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.auth.*
import io.ktor.client.plugins.auth.providers.*
import io.ktor.client.request.forms.*
import io.ktor.http.*
import kotlinx.coroutines.*
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.defaultRequest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.apache.avro.SchemaValidationException
import org.radarbase.config.ServerConfig
import org.radarbase.config.YamlConfigLoader
Expand All @@ -41,13 +43,17 @@ import org.radarbase.producer.rest.RestKafkaSender.Companion.restKafkaSender
import org.radarbase.producer.schema.SchemaRetriever
import org.radarbase.producer.schema.SchemaRetriever.Companion.schemaRetriever
import org.radarcns.kafka.ObservationKey
import org.radarcns.passive.empatica.*
import org.radarcns.passive.empatica.EmpaticaE4Acceleration
import org.radarcns.passive.empatica.EmpaticaE4BatteryLevel
import org.radarcns.passive.empatica.EmpaticaE4BloodVolumePulse
import org.radarcns.passive.empatica.EmpaticaE4ElectroDermalActivity
import org.radarcns.passive.empatica.EmpaticaE4InterBeatInterval
import org.radarcns.passive.empatica.EmpaticaE4Temperature
import org.slf4j.LoggerFactory
import java.io.IOException
import java.nio.file.Path
import java.nio.file.Paths
import java.time.Instant
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.system.exitProcess
import kotlin.time.Duration.Companion.seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import java.nio.charset.StandardCharsets
import java.nio.file.Path
import java.time.Duration
import java.time.Instant
import java.util.*
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.io.path.bufferedReader

/**
Expand Down Expand Up @@ -277,9 +278,9 @@ class MockCsvParser(
}
}

@OptIn(ExperimentalEncodingApi::class)
private fun parseBytes(fieldString: String?): ByteBuffer {
val result = Base64.getDecoder()
.decode(fieldString!!.toByteArray(StandardCharsets.UTF_8))
val result = Base64.decode(fieldString!!.toByteArray(StandardCharsets.UTF_8))
return ByteBuffer.wrap(result)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import java.io.IOException
import java.io.Writer
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import kotlin.io.path.bufferedWriter

class MockRecordValidatorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ package org.radarbase.util

import kotlinx.coroutines.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.hamcrest.Matchers.greaterThanOrEqualTo
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.lessThan
import org.hamcrest.Matchers.lessThanOrEqualTo
import org.junit.jupiter.api.Test

class OscilloscopeTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package org.radarbase.producer

import io.ktor.client.*
import io.ktor.client.engine.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import kotlinx.coroutines.flow.Flow
import org.apache.avro.SchemaValidationException
import org.radarbase.producer.rest.ConnectionState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package org.radarbase.producer.avro
import org.apache.avro.JsonProperties
import org.apache.avro.Schema
import org.apache.avro.SchemaValidationException
import org.apache.avro.generic.*
import org.apache.avro.generic.GenericData
import org.apache.avro.generic.GenericEnumSymbol
import org.apache.avro.generic.GenericRecord
import org.apache.avro.generic.GenericRecordBuilder
import org.apache.avro.generic.IndexedRecord
import org.radarbase.util.Base64Encoder
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.ByteBuffer
import java.util.*
import java.util.EnumSet

object AvroDataMapperFactory {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,18 @@
*/
package org.radarbase.producer.io

import io.ktor.utils.io.*
import io.ktor.utils.io.ByteWriteChannel
import io.ktor.utils.io.close
import io.ktor.utils.io.writeByte
import org.apache.avro.io.BinaryData
import java.io.IOException
import java.util.*

/**
* An [Encoder] for Avro's binary encoding that does not buffer output.
*
*
* This encoder does not buffer writes, and as a result is slower than
* [BufferedBinaryEncoder]. However, it is lighter-weight and useful when
* the buffering in BufferedBinaryEncoder is not desired and/or the Encoder is
* very short lived.
*
*
* To construct, use
* [EncoderFactory.directBinaryEncoder]
*
*
* DirectBinaryEncoder is not thread-safe
*
* @see BinaryEncoder
*
* @see EncoderFactory
*
* @see Encoder
*
* @see Decoder
*/
class DirectBinaryEncoder(
var out: ByteWriteChannel,
Expand Down Expand Up @@ -95,10 +79,10 @@ class DirectBinaryEncoder(
if (`val` and 0x7FFFFFFFL.inv() == 0L) {
var i = `val`.toInt()
while (i and 0x7F.inv() != 0) {
out.writeByte((0x80 or i and 0xFF).toByte().toInt())
out.writeByte((0x80 or i and 0xFF).toByte())
i = i ushr 7
}
out.writeByte(i.toByte().toInt())
out.writeByte(i.toByte())
return
}
val len = BinaryData.encodeLong(n, buf, 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.radarbase.producer.io

import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.cio.CIOEngineConfig
import io.ktor.client.plugins.HttpTimeout
import java.security.cert.X509Certificate
import javax.net.ssl.X509TrustManager
import kotlin.time.Duration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.radarbase.producer.io

import io.ktor.http.*
import io.ktor.http.ContentType
import java.io.IOException

class UnsupportedMediaTypeException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.radarbase.producer.rest

import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.serialization.*
import io.ktor.util.reflect.*
import io.ktor.utils.io.*
import io.ktor.utils.io.charsets.*
import io.ktor.http.ContentType
import io.ktor.http.content.OutgoingContent
import io.ktor.serialization.ContentConverter
import io.ktor.util.reflect.TypeInfo
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.charsets.Charset
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import org.radarbase.data.RecordData
Expand Down
Loading

0 comments on commit 5bc4809

Please sign in to comment.