From 402a8f55342c4565431c2a2e7287a70592f3fe33 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 6 Oct 2022 12:51:27 +0200 Subject: style: Eliminate use of wildcard imports This change updates the repository to remove the use of wildcard imports everywhere. Wildcard imports are not allowed by default by Ktlint as well as Google's Java style guide. --- .../jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt | 10 +++++++--- .../simulator/flow/internal/FlowConsumerContextImpl.kt | 7 +++++-- .../kotlin/org/opendc/simulator/flow/internal/FlowDeque.kt | 2 +- .../org/opendc/simulator/flow/internal/FlowEngineImpl.kt | 7 +++++-- .../opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt | 8 +++++++- .../org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt | 9 ++++++++- .../org/opendc/simulator/flow/FlowConsumerContextTest.kt | 7 +++++-- .../kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt | 14 +++++++++++--- .../test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt | 8 ++++++-- .../simulator/flow/mux/ForwardingFlowMultiplexerTest.kt | 6 +++++- .../opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt | 3 ++- 11 files changed, 62 insertions(+), 19 deletions(-) (limited to 'opendc-simulator/opendc-simulator-flow/src') diff --git a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt index 86fbe8e4..58f84d82 100644 --- a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt +++ b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt @@ -22,13 +22,18 @@ package org.opendc.simulator.flow -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import org.opendc.simulator.flow.mux.ForwardingFlowMultiplexer import org.opendc.simulator.flow.mux.MaxMinFlowMultiplexer import org.opendc.simulator.flow.source.TraceFlowSource import org.opendc.simulator.kotlin.runSimulation -import org.openjdk.jmh.annotations.* +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Fork +import org.openjdk.jmh.annotations.Measurement +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.Setup +import org.openjdk.jmh.annotations.State +import org.openjdk.jmh.annotations.Warmup import java.util.concurrent.ThreadLocalRandom import java.util.concurrent.TimeUnit @@ -36,7 +41,6 @@ import java.util.concurrent.TimeUnit @Fork(1) @Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) -@OptIn(ExperimentalCoroutinesApi::class) class FlowBenchmarks { private lateinit var trace: Sequence diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt index bc6bae71..393a2635 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt @@ -23,8 +23,11 @@ package org.opendc.simulator.flow.internal import mu.KotlinLogging -import org.opendc.simulator.flow.* -import java.util.* +import org.opendc.simulator.flow.FlowConsumerContext +import org.opendc.simulator.flow.FlowConsumerLogic +import org.opendc.simulator.flow.FlowSource +import org.opendc.simulator.flow.batch +import java.util.ArrayDeque import kotlin.math.min /** diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowDeque.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowDeque.kt index 94232954..403a9aec 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowDeque.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowDeque.kt @@ -22,7 +22,7 @@ package org.opendc.simulator.flow.internal -import java.util.* +import java.util.ArrayDeque /** * A specialized [ArrayDeque] that tracks the [FlowConsumerContextImpl] instances that have updated in an interpreter diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowEngineImpl.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowEngineImpl.kt index 3c79d54e..6fd1ef31 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowEngineImpl.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowEngineImpl.kt @@ -26,9 +26,12 @@ import kotlinx.coroutines.Delay import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.Runnable -import org.opendc.simulator.flow.* +import org.opendc.simulator.flow.FlowConsumerContext +import org.opendc.simulator.flow.FlowConsumerLogic +import org.opendc.simulator.flow.FlowEngine +import org.opendc.simulator.flow.FlowSource import java.time.Clock -import java.util.* +import java.util.ArrayDeque import kotlin.coroutines.ContinuationInterceptor import kotlin.coroutines.CoroutineContext diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt index c50e9bbc..53f94a94 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt @@ -22,7 +22,13 @@ package org.opendc.simulator.flow.mux -import org.opendc.simulator.flow.* +import org.opendc.simulator.flow.FlowConnection +import org.opendc.simulator.flow.FlowConsumer +import org.opendc.simulator.flow.FlowConvergenceListener +import org.opendc.simulator.flow.FlowCounters +import org.opendc.simulator.flow.FlowEngine +import org.opendc.simulator.flow.FlowForwarder +import org.opendc.simulator.flow.FlowSource import java.util.ArrayDeque /** diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt index f2a4c1a4..a52a5b0e 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt @@ -22,7 +22,14 @@ package org.opendc.simulator.flow.mux -import org.opendc.simulator.flow.* +import org.opendc.simulator.flow.FlowConnection +import org.opendc.simulator.flow.FlowConsumer +import org.opendc.simulator.flow.FlowConsumerContext +import org.opendc.simulator.flow.FlowConsumerLogic +import org.opendc.simulator.flow.FlowConvergenceListener +import org.opendc.simulator.flow.FlowCounters +import org.opendc.simulator.flow.FlowEngine +import org.opendc.simulator.flow.FlowSource import org.opendc.simulator.flow.internal.D_MS_TO_S import org.opendc.simulator.flow.internal.MutableFlowCounters import kotlin.math.min diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt index d782d036..f89133dd 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt @@ -22,8 +22,11 @@ package org.opendc.simulator.flow -import io.mockk.* -import org.junit.jupiter.api.* +import io.mockk.spyk +import io.mockk.verify +import net.bytebuddy.matcher.ElementMatchers.any +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.internal.FlowConsumerContextImpl import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.kotlin.runSimulation diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt index 2025dd52..f75e5037 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt @@ -22,9 +22,17 @@ package org.opendc.simulator.flow -import io.mockk.* -import kotlinx.coroutines.* -import org.junit.jupiter.api.Assertions.* +import io.mockk.spyk +import io.mockk.verify +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.yield +import net.bytebuddy.matcher.ElementMatchers.any +import org.junit.jupiter.api.Assertions.assertAll +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt index 22a84edb..746d752d 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt @@ -24,9 +24,13 @@ package org.opendc.simulator.flow import io.mockk.spyk import io.mockk.verify -import kotlinx.coroutines.* -import org.junit.jupiter.api.* +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.yield import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.flow.source.FixedFlowSource import org.opendc.simulator.flow.source.FlowSourceRateAdapter diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt index cfd2bdf0..1a71580b 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt @@ -27,7 +27,11 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll import org.junit.jupiter.api.assertThrows -import org.opendc.simulator.flow.* +import org.opendc.simulator.flow.FlowConnection +import org.opendc.simulator.flow.FlowForwarder +import org.opendc.simulator.flow.FlowSink +import org.opendc.simulator.flow.FlowSource +import org.opendc.simulator.flow.consume import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.flow.source.FixedFlowSource import org.opendc.simulator.flow.source.FlowSourceRateAdapter diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt index 4e242292..34198f17 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt @@ -25,8 +25,9 @@ package org.opendc.simulator.flow.mux import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.yield -import org.junit.jupiter.api.* +import org.junit.jupiter.api.Assertions.assertAll import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test import org.opendc.simulator.flow.FlowSink import org.opendc.simulator.flow.consume import org.opendc.simulator.flow.internal.FlowEngineImpl -- cgit v1.2.3 From 47357afd16f928260db34d4dd3e686fb9ee7c5ff Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 6 Oct 2022 13:13:10 +0200 Subject: build: Switch to Spotless for formatting This change updates the build configuration to use Spotless for code formating of both Kotlin and Java. --- .../org/opendc/simulator/flow/FlowForwarder.kt | 5 +++-- .../flow/internal/FlowConsumerContextImpl.kt | 20 ++++++++++++-------- .../simulator/flow/mux/MaxMinFlowMultiplexer.kt | 8 ++++---- .../flow/mux/ForwardingFlowMultiplexerTest.kt | 2 +- .../simulator/flow/mux/MaxMinFlowMultiplexerTest.kt | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) (limited to 'opendc-simulator/opendc-simulator-flow/src') diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt index 6fa2971a..5202c252 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt @@ -226,10 +226,11 @@ public class FlowForwarder( * Reset the delegate. */ private fun reset() { - if (isCoupled) + if (isCoupled) { _innerCtx?.close() - else + } else { _innerCtx?.push(0.0) + } delegate = null hasDelegateStarted = false diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt index 393a2635..fba3af5f 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt @@ -87,19 +87,21 @@ internal class FlowConsumerContextImpl( get() = _flags and ConnConvergeSource == ConnConvergeSource set(value) { _flags = - if (value) + if (value) { _flags or ConnConvergeSource - else + } else { _flags and ConnConvergeSource.inv() + } } override var shouldConsumerConverge: Boolean get() = _flags and ConnConvergeConsumer == ConnConvergeConsumer set(value) { _flags = - if (value) + if (value) { _flags or ConnConvergeConsumer - else + } else { _flags and ConnConvergeConsumer.inv() + } } /** @@ -109,10 +111,11 @@ internal class FlowConsumerContextImpl( get() = _flags and ConnDisableTimers != ConnDisableTimers set(value) { _flags = - if (!value) + if (!value) { _flags or ConnDisableTimers - else + } else { _flags and ConnDisableTimers.inv() + } } /** @@ -241,10 +244,11 @@ internal class FlowConsumerContextImpl( // IMPORTANT: Re-fetch the flags after the callback might have changed those flags = _flags - if (duration != Long.MAX_VALUE) + if (duration != Long.MAX_VALUE) { now + duration - else + } else { duration + } } else { deadline } diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt index a52a5b0e..d9c6f893 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt +++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt @@ -255,7 +255,6 @@ public class MaxMinFlowMultiplexer( * This method is invoked when one of the inputs converges. */ fun convergeInput(input: Input, now: Long) { - val lastConverge = _lastConverge val lastConvergeInput = _lastConvergeInput val parent = parent @@ -518,7 +517,7 @@ public class MaxMinFlowMultiplexer( private val engine: FlowEngine, private val scheduler: Scheduler, @JvmField val isCoupled: Boolean, - initialCapacity: Double, + initialCapacity: Double ) : FlowConsumer, FlowConsumerLogic, Comparable { /** * A flag to indicate that the consumer is active. @@ -787,10 +786,11 @@ public class MaxMinFlowMultiplexer( return if (_isActivationOutput) { // If this output is the activation output, synchronously run the scheduler and return the new deadline val deadline = scheduler.runScheduler(now) - if (deadline == Long.MAX_VALUE) + if (deadline == Long.MAX_VALUE) { deadline - else + } else { deadline - now + } } else { // Output is not the activation output, so trigger activation output and do not install timer for this // output (by returning `Long.MAX_VALUE`) diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt index 1a71580b..2409e174 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt @@ -59,7 +59,7 @@ internal class ForwardingFlowMultiplexerTest { TraceFlowSource.Fragment(duration * 1000, 3500.0), TraceFlowSource.Fragment(duration * 1000, 0.0), TraceFlowSource.Fragment(duration * 1000, 183.0) - ), + ) ) val switch = ForwardingFlowMultiplexer(engine) diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt index 34198f17..a6bf8ad8 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt @@ -73,7 +73,7 @@ internal class MaxMinFlowMultiplexerTest { TraceFlowSource.Fragment(duration * 1000, 3500.0), TraceFlowSource.Fragment(duration * 1000, 0.0), TraceFlowSource.Fragment(duration * 1000, 183.0) - ), + ) ) val switch = MaxMinFlowMultiplexer(scheduler) @@ -111,7 +111,7 @@ internal class MaxMinFlowMultiplexerTest { TraceFlowSource.Fragment(duration * 1000, 3500.0), TraceFlowSource.Fragment(duration * 1000, 0.0), TraceFlowSource.Fragment(duration * 1000, 183.0) - ), + ) ) val workloadB = TraceFlowSource( -- cgit v1.2.3