From 9fda160b5c704d1a71fd4944e3f0d82abd351ae6 Mon Sep 17 00:00:00 2001 From: Lukas Forst Date: Tue, 1 Nov 2022 10:59:16 +0100 Subject: [PATCH] Update dependencies and format project (#28) * update dependencies and format project * revert nemerosa versioning to version that supports jvm 8 --- .github/workflows/ci.yml | 6 +- .github/workflows/release.yml | 8 +- build.gradle.kts | 19 +-- detekt-config.yml | 114 +++++++++++------- .../kotlin/dev/forst/katlib/DateExtensions.kt | 2 - .../dev/forst/katlib/IterableExtensions.kt | 19 +-- .../dev/forst/katlib/JacksonExtensions.kt | 1 - .../kotlin/dev/forst/katlib/MapExtensions.kt | 4 - .../dev/forst/katlib/OtherExtensions.kt | 4 +- .../dev/forst/katlib/SequenceExtensions.kt | 2 - .../kotlin/dev/forst/katlib/SetExtensions.kt | 1 - .../dev/forst/katlib/ArrayExtensionsTest.kt | 26 ++-- .../dev/forst/katlib/DateExtensionsTest.kt | 2 - .../dev/forst/katlib/InstantExtensionsTest.kt | 1 - .../forst/katlib/IterableExtensionsTest.kt | 7 +- .../dev/forst/katlib/MapExtensionsTest.kt | 8 +- .../kotlin/dev/forst/katlib/SettableRandom.kt | 1 - .../dev/forst/katlib/StringExtensionsTest.kt | 9 +- 18 files changed, 120 insertions(+), 114 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ccae35e..233e78b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,13 +20,15 @@ jobs: strategy: matrix: os: [ windows-latest, ubuntu-latest ] - java: [ 8, 11, 17 ] + java: [ 8, 17 ] steps: - uses: actions/checkout@v3 + - name: Setup JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'temurin' java-version: ${{ matrix.java }} - name: Build lib diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5925b49..c482b3a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,9 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Setup JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'temurin' java-version: 8 - name: Build lib @@ -30,9 +32,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Setup JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'temurin' java-version: 8 server-id: ossrh server-username: OSSRH_USERNAME diff --git a/build.gradle.kts b/build.gradle.kts index 8b8272e..e23c030 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,9 +9,10 @@ plugins { signing id("io.github.gradle-nexus.publish-plugin") version "1.1.0" + // 3.0.0 requires JVM 11, but we want to keep this compatible with JVM 8 id("net.nemerosa.versioning") version "2.15.1" id("org.jetbrains.dokka") version "1.7.20" - id("io.gitlab.arturbosch.detekt") version "1.19.0" + id("io.gitlab.arturbosch.detekt") version "1.21.0" } group = "dev.forst" @@ -23,9 +24,11 @@ repositories { } dependencies { - val jacksonVersion = "2.13.3" - compileOnly("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion) - compileOnly("com.fasterxml.jackson.module", "jackson-module-kotlin", jacksonVersion) + // compile only detekt plugin + detektPlugins("io.gitlab.arturbosch.detekt", "detekt-formatting", "1.21.0") + + compileOnly("com.fasterxml.jackson.core", "jackson-databind", "2.13.4.2") + compileOnly("com.fasterxml.jackson.module", "jackson-module-kotlin", "2.13.4") compileOnly(kotlin("reflect")) compileOnly(kotlin("stdlib-jdk8")) @@ -36,11 +39,9 @@ dependencies { testImplementation("io.mockk", "mockk", "1.12.3") // mock framework testImplementation("ch.qos.logback", "logback-classic", "1.2.9") // logging framework for the tests - val junitVersion = "5.8.2" - testImplementation("org.junit.jupiter", "junit-jupiter-api", junitVersion) // junit testing framework - testImplementation("org.junit.jupiter", "junit-jupiter-params", junitVersion) // generated parameters for tests - - testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junitVersion) // testing runtime + testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.9.1") // junit testing framework + testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.9.1") // generated parameters for tests + testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.9.1") // testing runtime } detekt { diff --git a/detekt-config.yml b/detekt-config.yml index 23bdb50..7dcb1dc 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -42,7 +42,7 @@ console-reports: output-reports: active: true - exclude: + exclude: [ ] # - 'TxtOutputReport' # - 'XmlOutputReport' # - 'HtmlOutputReport' @@ -66,19 +66,20 @@ comments: active: false matchTypeParameters: true matchDeclarationsOrder: true + allowParamOnConstructorProperties: false UndocumentedPublicClass: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] searchInNestedClass: true searchInInnerClass: true searchInInnerObject: true searchInInnerInterface: true UndocumentedPublicFunction: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] UndocumentedPublicProperty: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] complexity: active: true @@ -108,7 +109,7 @@ complexity: - 'with' LabeledExpression: active: false - ignoredLabels: [] + ignoredLabels: [ ] LargeClass: active: true threshold: 400 @@ -121,13 +122,14 @@ complexity: constructorThreshold: 7 ignoreDefaultParameters: false ignoreDataClasses: true - ignoreAnnotatedParameter: [] + ignoreAnnotatedParameter: [ ] MethodOverloading: active: false threshold: 6 NamedArguments: active: true threshold: 3 + ignoreArgumentsMatchingNames: false NestedBlockDepth: active: true threshold: 4 @@ -135,7 +137,7 @@ complexity: active: true StringLiteralDuplication: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] threshold: 3 ignoreAnnotation: true excludeStringsWithLessThan5Characters: true @@ -143,7 +145,7 @@ complexity: TooManyFunctions: # because we don't use classes, this is acceptable active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] thresholdInFiles: 20 thresholdInClasses: 13 thresholdInInterfaces: 13 @@ -167,6 +169,8 @@ coroutines: active: true SleepInsteadOfDelay: active: true + SuspendFunWithCoroutineScopeReceiver: + active: false SuspendFunWithFlowReturnType: active: false @@ -216,7 +220,7 @@ exceptions: - 'toString' InstanceOfCheckForException: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] NotImplementedDeclaration: active: false ObjectExtendsThrowable: @@ -242,7 +246,7 @@ exceptions: active: true ThrowingExceptionsWithoutMessageOrCause: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] exceptions: - 'ArrayIndexOutOfBoundsException' - 'Exception' @@ -256,8 +260,8 @@ exceptions: ThrowingNewInstanceOfSameException: active: true TooGenericExceptionCaught: - active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/Prompt.kt'] + active: false + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] exceptionNames: - 'ArrayIndexOutOfBoundsException' - 'Error' @@ -307,11 +311,11 @@ formatting: autoCorrect: true insertFinalNewLine: true ImportOrdering: - active: true + active: false # idea does that differently even though detekt should listen to it autoCorrect: true layout: 'idea' Indentation: - active: true + active: false # idea has different, and we want to keep Idea autoCorrect: true indentSize: 4 continuationIndentSize: 4 @@ -415,53 +419,55 @@ naming: active: true BooleanPropertyNaming: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] allowedPattern: '^(is|has|are)' + ignoreOverridden: true ClassNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] classPattern: '[A-Z][a-zA-Z0-9]*' ConstructorParameterNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] parameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true EnumNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] enumEntryPattern: '[A-Z][_a-zA-Z0-9]*' ForbiddenClassName: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - forbiddenName: [] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] + forbiddenName: [ ] FunctionMaxLength: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] maximumFunctionNameLength: 30 FunctionMinLength: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] minimumFunctionNameLength: 3 FunctionNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)' + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] + functionPattern: '[a-z][a-zA-Z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true FunctionParameterNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] parameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true InvalidPackageDeclaration: active: true rootPackage: '' + requireRootInDeclaration: false LambdaParameterNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] parameterPattern: '[a-z][A-Za-z0-9]*|_' MatchingDeclarationName: active: true @@ -473,34 +479,34 @@ naming: active: true NonBooleanPropertyPrefixedWithIs: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] ObjectPropertyNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] constantPattern: '[A-Za-z][_A-Za-z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' PackageNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*' TopLevelPropertyNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' VariableMaxLength: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] maximumVariableNameLength: 64 VariableMinLength: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] minimumVariableNameLength: 1 VariableNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' @@ -512,10 +518,10 @@ performance: active: true ForEachOnRange: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] SpreadOperator: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] UnnecessaryTemporaryInstantiation: active: true @@ -533,8 +539,19 @@ potential-bugs: active: true DoubleMutabilityForCollection: active: true + mutableTypes: + - 'kotlin.collections.MutableList' + - 'kotlin.collections.MutableMap' + - 'kotlin.collections.MutableSet' + - 'java.util.ArrayList' + - 'java.util.LinkedHashSet' + - 'java.util.HashSet' + - 'java.util.LinkedHashMap' + - 'java.util.HashMap' DuplicateCaseInWhenExpression: active: true + ElseCaseInsteadOfExhaustiveWhen: + active: false EqualsAlwaysReturnsTrueOrFalse: active: true EqualsWithHashCodeExist: @@ -566,16 +583,18 @@ potential-bugs: active: true LateinitUsage: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] ignoreOnClassesPattern: '' MapGetWithNotNullAssertionOperator: active: true MissingPackageDeclaration: active: true - excludes: ['**/*.kts'] + excludes: [ '**/*.kts' ] MissingWhenCase: active: true allowElseExpression: true + NullCheckOnMutableProperty: + active: true NullableToStringCall: active: true RedundantElseInWhen: @@ -592,7 +611,7 @@ potential-bugs: active: true UnsafeCallOnNullableType: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] UnsafeCast: active: true UnusedUnaryOperator: @@ -604,6 +623,8 @@ potential-bugs: style: active: true + CanBeNonNullable: + active: true ClassOrdering: active: false CollapsibleIfStatements: @@ -637,7 +658,7 @@ style: customMessage: '' ForbiddenImport: active: false - imports: [] + imports: [ ] forbiddenPatterns: '' ForbiddenMethodCall: active: false @@ -646,7 +667,7 @@ style: - 'kotlin.io.println' ForbiddenPublicDataClass: active: true - excludes: ['**'] + excludes: [ '**' ] ignorePackages: - '*.internal' - '*.internal.*' @@ -661,16 +682,16 @@ style: excludedFunctions: '' LibraryCodeMustSpecifyReturnType: active: true - excludes: ['**'] + excludes: [ '**' ] LibraryEntitiesShouldNotBePublic: active: true - excludes: ['**'] + excludes: [ '**' ] LoopWithTooManyJumpStatements: active: true maxJumpCount: 1 MagicNumber: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] ignoreNumbers: - '-1' - '0' @@ -748,6 +769,7 @@ style: UnderscoresInNumericLiterals: active: true acceptableLength: 4 + allowNonStandardGrouping: false UnnecessaryAbstractClass: active: true UnnecessaryAnnotationUseSiteTarget: @@ -758,10 +780,12 @@ style: active: true UnnecessaryInheritance: active: true + UnnecessaryInnerClass: + active: true UnnecessaryLet: active: true UnnecessaryParentheses: - active: true + active: false UntilInsteadOfRangeTo: active: false UnusedImports: @@ -804,6 +828,6 @@ style: active: true WildcardImport: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] excludeImports: - 'java.util.*' diff --git a/src/main/kotlin/dev/forst/katlib/DateExtensions.kt b/src/main/kotlin/dev/forst/katlib/DateExtensions.kt index 806886d..d1a7bbd 100644 --- a/src/main/kotlin/dev/forst/katlib/DateExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/DateExtensions.kt @@ -12,7 +12,6 @@ import java.util.Locale import java.util.stream.Stream import kotlin.streams.toList - /** * Returns list of days from [this] date to [to] date (both inclusive). * @@ -20,7 +19,6 @@ import kotlin.streams.toList */ fun LocalDate.getDateRangeTo(to: LocalDate): List = this.getDateRangeToAsStream(to).toList() - /** * Returns stream of days from [this] date to [to] date (both inclusive). * diff --git a/src/main/kotlin/dev/forst/katlib/IterableExtensions.kt b/src/main/kotlin/dev/forst/katlib/IterableExtensions.kt index 490844e..8582227 100644 --- a/src/main/kotlin/dev/forst/katlib/IterableExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/IterableExtensions.kt @@ -8,7 +8,6 @@ import kotlin.collections.component1 import kotlin.collections.component2 import kotlin.random.Random - /** * Function that will return a random element from the iterable. */ @@ -203,7 +202,6 @@ inline fun Iterable.singleOrEmpty(predicate: (T) -> Boolean): T? { return single } - /** * Returns single element, or `null` if the collection is empty. * Throws [IllegalArgumentException] when multiple elements are matching predicate. @@ -252,7 +250,6 @@ inline fun Iterable.setDifferenceBy(other: Iterable, selector: (T) .filterValues { it.size == 1 && it.single().second } .map { (_, value) -> value.single().first } - /** * Returns a [Map] containing key-value pairs provided by elements of the given collection. * @@ -292,7 +289,6 @@ inline fun Iterable.assoc(transform: (T) -> Pair): Map return assocTo(LinkedHashMap(defaultMapCapacity()), transform) } - /** * Populates and returns the [destination] mutable map with key-value pairs * provided by [transform] function applied to each element of the given collection. @@ -358,7 +354,8 @@ inline fun Iterable.assocBy(keySelector: (T) -> K, valueTransform: * If any two elements had the same key returned by [keySelector] the last one gets added to the map and the method creates a warning. */ inline fun > Iterable.assocByTo( - destination: M, keySelector: (T) -> K, + destination: M, + keySelector: (T) -> K, valueTransform: (T) -> V ): M { var size = 0 @@ -370,7 +367,6 @@ inline fun > Iterable.assocByTo( return destination } - /** * Returns a [Map] where keys are elements from the given collection and values are * produced by the [valueSelector] function applied to each element. @@ -443,7 +439,7 @@ inline fun Iterable.itemsToString( itemToString: (TItem) -> String = { item -> item.toShortString() } ): String { val sb = StringBuilder("${this.count()} $itemsType") - var currentSeparator = ": " // before the first item + var currentSeparator = ": " // before the first item for (item in this) { sb.append(currentSeparator) currentSeparator = separator // before other than first item @@ -478,12 +474,11 @@ internal inline fun > M.checkUniqueness(expecte val stack = Throwable().stackTraceToString() iterableLogger.warning { @Suppress("MagicNumber") // specified carefully, don't need constant - val entries = duplicatedKeys.entries.toString().take(500) //ensures that huge collections will not consume too much space + val entries = duplicatedKeys.entries.toString().take(500) // ensures that huge collections will not consume too much space "The map should contain $expectedSize entries but the actual size is ${this.size}. The affected entries are $entries.$newLine$stack" } } - /** * Returns default capacity for the maps based on the Guava's approach. */ @@ -491,7 +486,6 @@ internal inline fun > M.checkUniqueness(expecte internal fun Iterable.defaultMapCapacity() = mapCapacity(collectionSizeOrDefault(DEFAULT_COLLECTION_SIZE)).coerceAtLeast(DEFAULT_COERCE_MINIMUM_VALUE) - /** * Calculate the initial capacity of a map, based on Guava's com.google.common.collect.Maps approach. This is equivalent * to the Collection constructor for HashSet, (c.size()/.75f) + 1, but provides further optimisations for very small or @@ -586,14 +580,12 @@ fun Iterable>.cartesianProduct(): List> = fold(listOf(listOf())) { acc, set -> acc.flatMap { list -> set.map { element -> list + element } } } } - /** * Lazy cartesian production. */ fun Iterable>.lazyCartesianProduct(): Sequence> = if (isEmpty()) emptySequence() else lazyCartesianProductAcc(this, emptyList()) - private fun lazyCartesianProductAcc(l: Iterable>, acc: List): Sequence> = sequence { if (l.isEmpty()) { yield(acc) @@ -629,7 +621,6 @@ inline fun Iterable.zip(b: Iterable, c: Iterable, transfor return list } - /** * Sum collection by float as this is missing in the stdlib even after version 1.4.0. * @@ -652,4 +643,4 @@ inline fun Iterable.withEach(action: T.() -> Unit) = forEach { it.action( * Performs the given [action] with each element as a receiver, providing sequential index with the element. * @param [action] function that takes the index of an element and performs the action on the element. */ -inline fun Iterable.withEachIndexed(action: T.(index: Int) -> Unit) = forEachIndexed{ index, it -> it.action(index)} +inline fun Iterable.withEachIndexed(action: T.(index: Int) -> Unit) = forEachIndexed { index, it -> it.action(index) } diff --git a/src/main/kotlin/dev/forst/katlib/JacksonExtensions.kt b/src/main/kotlin/dev/forst/katlib/JacksonExtensions.kt index c6f3a67..e555bd8 100644 --- a/src/main/kotlin/dev/forst/katlib/JacksonExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/JacksonExtensions.kt @@ -61,7 +61,6 @@ fun createPrettyJson(value: T): String = jacksonMapper() .writerWithDefaultPrettyPrinter() .writeValueAsString(value) - /** * Serializes given object to byte array. */ diff --git a/src/main/kotlin/dev/forst/katlib/MapExtensions.kt b/src/main/kotlin/dev/forst/katlib/MapExtensions.kt index 7fea607..2bf118c 100644 --- a/src/main/kotlin/dev/forst/katlib/MapExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/MapExtensions.kt @@ -6,7 +6,6 @@ package dev.forst.katlib import kotlin.random.Random - /** * Randomly selects item with respect to the current weight distribution. */ @@ -28,7 +27,6 @@ fun Map.getWeightedRandom(rand: Random): T { } } - /** * Randomly sorts the items with respect to the current weight distribution. * [normalizer] is used to normalize the random value obtained from [rand] to control @@ -249,5 +247,3 @@ fun Iterable>>.flatMerge(): Map> { val keys = this.map { it.keys }.union() return keys.assocWith { key -> this.flatMap { map -> map[key] ?: emptyList() } } } - - diff --git a/src/main/kotlin/dev/forst/katlib/OtherExtensions.kt b/src/main/kotlin/dev/forst/katlib/OtherExtensions.kt index bdc2409..c6789da 100644 --- a/src/main/kotlin/dev/forst/katlib/OtherExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/OtherExtensions.kt @@ -22,13 +22,11 @@ inline fun T.whenNull(block: () -> Unit): T { return this } - /** * Creates a single element list from [this]. */ fun T.asList() = listOf(this) - /** * Returns true when there is at least one element x for which *x in this* and *x in other* returns true. */ @@ -59,7 +57,7 @@ inline fun T.validate(isValidSelector: (T) -> Boolean, invalidBlock: (T) -> */ fun Pair.propagateNull(): Pair? { if (first != null && second != null) { - @Suppress("UNCHECKED_CAST") //the cast is safe because it is checked that both values are not null + @Suppress("UNCHECKED_CAST") // the cast is safe because it is checked that both values are not null return this as Pair } diff --git a/src/main/kotlin/dev/forst/katlib/SequenceExtensions.kt b/src/main/kotlin/dev/forst/katlib/SequenceExtensions.kt index 8bc6728..38be3fb 100644 --- a/src/main/kotlin/dev/forst/katlib/SequenceExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/SequenceExtensions.kt @@ -1,6 +1,5 @@ package dev.forst.katlib - /** * Default values taken from Guava. */ @@ -160,7 +159,6 @@ inline fun > Sequence.assocWithTo(destinatio internal fun Sequence.defaultMapCapacity() = mapCapacity(collectionSizeOrDefault(DEFAULT_COLLECTION_SIZE)).coerceAtLeast(DEFAULT_COERCE_MINIMUM_VALUE) - /** * Returns the size of this iterable if it is known, or the specified [default] value otherwise. */ diff --git a/src/main/kotlin/dev/forst/katlib/SetExtensions.kt b/src/main/kotlin/dev/forst/katlib/SetExtensions.kt index ee19ef3..910e077 100644 --- a/src/main/kotlin/dev/forst/katlib/SetExtensions.kt +++ b/src/main/kotlin/dev/forst/katlib/SetExtensions.kt @@ -2,7 +2,6 @@ package dev.forst.katlib import java.util.SortedSet - /** * Returns the first item in this sorted set. */ diff --git a/src/test/kotlin/dev/forst/katlib/ArrayExtensionsTest.kt b/src/test/kotlin/dev/forst/katlib/ArrayExtensionsTest.kt index b25d8d3..79d642e 100644 --- a/src/test/kotlin/dev/forst/katlib/ArrayExtensionsTest.kt +++ b/src/test/kotlin/dev/forst/katlib/ArrayExtensionsTest.kt @@ -66,19 +66,17 @@ class ArrayExtensionsTest { } @Test - fun `Array minus element Test`() - { - val arrayA = Array(100) { it } - val arrayB = Array(100) { it + 200} - val combinedArray = arrayA + arrayB - assertContentEquals(arrayA, combinedArray - arrayB) - } + fun `Array minus element Test`() { + val arrayA = Array(100) { it } + val arrayB = Array(100) { it + 200 } + val combinedArray = arrayA + arrayB + assertContentEquals(arrayA, combinedArray - arrayB) + } - @Test - fun `Array minus elements Test`() - { - val arrayA = Array(5){it} - val arrayB = Array(4){it} - assertContentEquals(arrayA - 4, arrayB) - } + @Test + fun `Array minus elements Test`() { + val arrayA = Array(5) { it } + val arrayB = Array(4) { it } + assertContentEquals(arrayA - 4, arrayB) + } } diff --git a/src/test/kotlin/dev/forst/katlib/DateExtensionsTest.kt b/src/test/kotlin/dev/forst/katlib/DateExtensionsTest.kt index 77306ba..d8745c7 100644 --- a/src/test/kotlin/dev/forst/katlib/DateExtensionsTest.kt +++ b/src/test/kotlin/dev/forst/katlib/DateExtensionsTest.kt @@ -105,7 +105,6 @@ internal class DateExtensionsTest { val week2Date = LocalDate.of(2022, 1, 10) assertEquals(week2Date, year.setWeekOfYearMonday(2)) - val week52Date = LocalDate.of(2022, 12, 26) assertEquals(week52Date, year.setWeekOfYearMonday(52)) @@ -136,5 +135,4 @@ internal class DateExtensionsTest { assertEquals(expectedLocalDate, date.toUtcLocalDate()) } - } diff --git a/src/test/kotlin/dev/forst/katlib/InstantExtensionsTest.kt b/src/test/kotlin/dev/forst/katlib/InstantExtensionsTest.kt index 579bd3f..e1ea122 100644 --- a/src/test/kotlin/dev/forst/katlib/InstantExtensionsTest.kt +++ b/src/test/kotlin/dev/forst/katlib/InstantExtensionsTest.kt @@ -46,5 +46,4 @@ internal class InstantExtensionsTest { fun `durationToInMilli smaller to bigger test`() { assertDurationTo(100, 101, 1) } - } diff --git a/src/test/kotlin/dev/forst/katlib/IterableExtensionsTest.kt b/src/test/kotlin/dev/forst/katlib/IterableExtensionsTest.kt index 8049c26..cd012fd 100644 --- a/src/test/kotlin/dev/forst/katlib/IterableExtensionsTest.kt +++ b/src/test/kotlin/dev/forst/katlib/IterableExtensionsTest.kt @@ -355,16 +355,15 @@ internal class IterableExtensionsTest { @Test fun `test withEach`() { - val pairs = List(100){ Pair(it, it * 2) } + val pairs = List(100) { Pair(it, it * 2) } pairs.withEach { assertEquals(first * 2, second) } } @Test - fun `test withEachIndexed`() - { - val pairs = List(100){ it } + fun `test withEachIndexed`() { + val pairs = List(100) { it } pairs.withEachIndexed { index -> assertEquals(index, this) } diff --git a/src/test/kotlin/dev/forst/katlib/MapExtensionsTest.kt b/src/test/kotlin/dev/forst/katlib/MapExtensionsTest.kt index 310e4e7..8860409 100644 --- a/src/test/kotlin/dev/forst/katlib/MapExtensionsTest.kt +++ b/src/test/kotlin/dev/forst/katlib/MapExtensionsTest.kt @@ -63,7 +63,6 @@ internal class MapExtensionsTest { assertEquals(mapOf("a" to 2, "b" to 10, "c" to 3, "d" to 0, "e" to 4), sumReduction) } - @Test fun testJoin() { val map1 = mapOf("a" to 5, "b" to 10, "c" to 11) @@ -101,7 +100,6 @@ internal class MapExtensionsTest { val swappedk2withk1 = map.swapKeys { k1, k2, k3 -> Triple(k2, k1, k3) } - val expectedk2withk1 = mapOf( 1 to mapOf("a" to mapOf(4.5 to false, 4.2 to true)), 8 to mapOf("b" to mapOf(1.5 to false, 7.2 to true)), @@ -125,7 +123,6 @@ internal class MapExtensionsTest { assertEquals(expectedk3withk1, swappedk3withk1) } - @Test fun testToTwoDimensionalMap() { val map = mapOf( @@ -220,7 +217,10 @@ internal class MapExtensionsTest { val map2 = mapOf(2 to listOf("d"), 3 to listOf("c", "d", "e"), 4 to listOf("f")) val map3 = mapOf(2 to listOf("x"), 3 to listOf("y"), 4 to listOf("z", "k")) val expected = mapOf( - 1 to listOf("a", "b"), 2 to listOf("b", "d", "x"), 3 to listOf("c", "c", "d", "e", "y"), 4 to listOf("f", "z", "k") + 1 to listOf("a", "b"), + 2 to listOf("b", "d", "x"), + 3 to listOf("c", "c", "d", "e", "y"), + 4 to listOf("f", "z", "k") ) assertEquals(expected, listOf(map1, map2, map3).flatMerge()) } diff --git a/src/test/kotlin/dev/forst/katlib/SettableRandom.kt b/src/test/kotlin/dev/forst/katlib/SettableRandom.kt index 8d66406..177116a 100644 --- a/src/test/kotlin/dev/forst/katlib/SettableRandom.kt +++ b/src/test/kotlin/dev/forst/katlib/SettableRandom.kt @@ -30,5 +30,4 @@ internal class SettableRandom : Random() { nextIntValues = values.iterator() return this } - } diff --git a/src/test/kotlin/dev/forst/katlib/StringExtensionsTest.kt b/src/test/kotlin/dev/forst/katlib/StringExtensionsTest.kt index 72aa975..ae632b5 100644 --- a/src/test/kotlin/dev/forst/katlib/StringExtensionsTest.kt +++ b/src/test/kotlin/dev/forst/katlib/StringExtensionsTest.kt @@ -17,8 +17,12 @@ internal class StringExtensionsTest { @Test fun `test startsWithLetter`() { val examples = mapOf( - "a lPha" to true, "Běta7" to true, "Čermák" to false, - " delta" to false, "30" to false, "_" to false + "a lPha" to true, + "Běta7" to true, + "Čermák" to false, + " delta" to false, + "30" to false, + "_" to false ) for ((key, value) in examples) { val result = key.startsWithLetter() @@ -46,5 +50,4 @@ internal class StringExtensionsTest { assertFalse("example".isEmail()) assertFalse("".isEmail()) } - }