Skip to content
7 changes: 7 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version = 3.8.1
runner.dialect = scala3

rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = no

rewrite.rules = []
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed Version Check logic for Dependabot PRs [#330](https://github.com/ie3-institute/simBench2psdm/issues/330)
- Removed Jenkins Pipeline. Now using GitHub Actions [#328](https://github.com/ie3-institute/simBench2psdm/issues/328)
- Switch to Java 21 [#343](https://github.com/ie3-institute/simBench2psdm/issues/343)
- Updated to `scala3` [#313](https://github.com/ie3-institute/simBench2psdm/issues/313)

## [1.0.0] - 2021-08-03
### Added
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ ext {
//version (changing these should be considered thoroughly!)
javaVersion = JavaVersion.VERSION_21

scalaVersion = '2.13'
scalaBinaryVersion = '2.13.17'
scalaVersion = '3'
scalaBinaryVersion = '3.7.0'
tscfgVersion = '1.2.5'
slf4jVersion = '2.0.17'

Expand Down Expand Up @@ -57,7 +57,7 @@ dependencies {
}

/* util functions */
implementation('com.github.ie3-institute:PowerSystemUtils:2.2.1') {
implementation('com.github.ie3-institute:PowerSystemUtils:3.1.0') {
exclude group: 'org.apache.logging.log4j'
exclude group: 'org.slf4j'
/* Exclude our own nested dependencies */
Expand All @@ -80,8 +80,8 @@ dependencies {

// NEW scala libs //
// CORE Scala //
implementation "org.scala-lang:scala-library:$scalaBinaryVersion"
implementation 'org.scala-lang.modules:scala-parallel-collections_2.13:1.2.0'
implementation "org.scala-lang:scala3-library_3:$scalaBinaryVersion"
implementation "org.scala-lang.modules:scala-parallel-collections_$scalaVersion:1.2.0"

// TEST Scala //
testImplementation "org.scalatest:scalatest_${scalaVersion}:3.2.19"
Expand All @@ -91,7 +91,7 @@ dependencies {

// config //
implementation 'com.typesafe:config:+'
implementation "com.github.carueda:tscfg_2.13:${tscfgVersion}"
implementation "com.github.carueda:tscfg_$scalaVersion:${tscfgVersion}"

// cmd args parser //
implementation "com.github.scopt:scopt_${scalaVersion}:+"
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spotless {

//sets a license header, removes unused imports and formats conforming to the scala fmt formatter
scala {
scalafmt()
scalafmt().configFile('.scalafmt.conf')
}

/* cf. https://github.com/diffplug/spotless/tree/master/plugin-gradle */
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/edu/ie3/simbench/config/ArgsParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package edu.ie3.simbench.config
import java.io.File
import java.nio.file.Paths

import com.typesafe.config.{ConfigFactory, Config => TypesafeConfig}
import scopt.{OptionParser => scoptOptionParser}
import com.typesafe.config.{ConfigFactory, Config as TypesafeConfig}
import scopt.OptionParser as scoptOptionParser

object ArgsParser {
// case class for allowed arguments
Expand All @@ -24,11 +24,11 @@ object ArgsParser {
)
})
.validate(value =>
if (value.trim.isEmpty) failure("config location cannot be empty")
if value.trim.isEmpty then failure("config location cannot be empty")
else success
)
.validate(value =>
if (value.contains("\\"))
if value.contains("\\") then
failure("wrong config path, expected: /, found: \\")
else success
)
Expand All @@ -48,7 +48,7 @@ object ArgsParser {

private def parseTypesafeConfig(fileName: String): TypesafeConfig = {
val file = Paths.get(fileName).toFile
if (!file.exists())
if !file.exists() then
throw new Exception(s"Missing config file on path $fileName")
parseTypesafeConfig(file)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ case object ConfigValidator {
*/
@throws[CodeValidationException]
private def checkSimbenchCodes(codes: List[java.lang.String]): Unit = {
for (code <- codes) {
for code <- codes do {
SimbenchCode.isValid(code) match {
case Success(_) =>
case Failure(exception) => throw exception
Expand Down
34 changes: 17 additions & 17 deletions src/main/scala/edu/ie3/simbench/config/SimbenchConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ object SimbenchConfig {
"directoryHierarchy"
),
fileEncoding =
if (c.hasPathOrNull("fileEncoding")) c.getString("fileEncoding")
if c.hasPathOrNull("fileEncoding") then c.getString("fileEncoding")
else "UTF-8",
fileEnding =
if (c.hasPathOrNull("fileEnding")) c.getString("fileEnding")
if c.hasPathOrNull("fileEnding") then c.getString("fileEnding")
else ".csv",
separator =
if (c.hasPathOrNull("separator")) c.getString("separator") else ";"
if c.hasPathOrNull("separator") then c.getString("separator") else ";"
)
}
}
Expand Down Expand Up @@ -78,14 +78,14 @@ object SimbenchConfig {
): SimbenchConfig.Io.Input.Download = {
SimbenchConfig.Io.Input.Download(
baseUrl =
if (c.hasPathOrNull("baseUrl")) c.getString("baseUrl")
if c.hasPathOrNull("baseUrl") then c.getString("baseUrl")
else "https://daks.uni-kassel.de/bitstreams",
failOnExistingFiles =
c.hasPathOrNull("failOnExistingFiles") && c.getBoolean(
"failOnExistingFiles"
),
directory =
if (c.hasPathOrNull("folder")) c.getString("folder")
if c.hasPathOrNull("folder") then c.getString("folder")
else "inputData/download/"
)
}
Expand All @@ -98,13 +98,13 @@ object SimbenchConfig {
): SimbenchConfig.Io.Input = {
SimbenchConfig.Io.Input(
csv = SimbenchConfig.CsvConfig(
if (c.hasPathOrNull("csv")) c.getConfig("csv")
if c.hasPathOrNull("csv") then c.getConfig("csv")
else com.typesafe.config.ConfigFactory.parseString("csv{}"),
parentPath + "csv.",
$tsCfgValidator
),
download = SimbenchConfig.Io.Input.Download(
if (c.hasPathOrNull("download")) c.getConfig("download")
if c.hasPathOrNull("download") then c.getConfig("download")
else com.typesafe.config.ConfigFactory.parseString("download{}"),
parentPath + "download.",
$tsCfgValidator
Expand All @@ -127,13 +127,13 @@ object SimbenchConfig {
SimbenchConfig.Io.Output(
compress = !c.hasPathOrNull("compress") || c.getBoolean("compress"),
csv = SimbenchConfig.CsvConfig(
if (c.hasPathOrNull("csv")) c.getConfig("csv")
if c.hasPathOrNull("csv") then c.getConfig("csv")
else com.typesafe.config.ConfigFactory.parseString("csv{}"),
parentPath + "csv.",
$tsCfgValidator
),
targetDir =
if (c.hasPathOrNull("targetFolder")) c.getString("targetFolder")
if c.hasPathOrNull("targetFolder") then c.getString("targetFolder")
else "convertedData"
)
}
Expand All @@ -146,13 +146,13 @@ object SimbenchConfig {
): SimbenchConfig.Io = {
SimbenchConfig.Io(
input = SimbenchConfig.Io.Input(
if (c.hasPathOrNull("input")) c.getConfig("input")
if c.hasPathOrNull("input") then c.getConfig("input")
else com.typesafe.config.ConfigFactory.parseString("input{}"),
parentPath + "input.",
$tsCfgValidator
),
output = SimbenchConfig.Io.Output(
if (c.hasPathOrNull("output")) c.getConfig("output")
if c.hasPathOrNull("output") then c.getConfig("output")
else com.typesafe.config.ConfigFactory.parseString("output{}"),
parentPath + "output.",
$tsCfgValidator
Expand All @@ -168,13 +168,13 @@ object SimbenchConfig {
val parentPath: java.lang.String = ""
val $result = SimbenchConfig(
conversion = SimbenchConfig.Conversion(
if (c.hasPathOrNull("conversion")) c.getConfig("conversion")
if c.hasPathOrNull("conversion") then c.getConfig("conversion")
else com.typesafe.config.ConfigFactory.parseString("conversion{}"),
parentPath + "conversion.",
$tsCfgValidator
),
io = SimbenchConfig.Io(
if (c.hasPathOrNull("io")) c.getConfig("io")
if c.hasPathOrNull("io") then c.getConfig("io")
else com.typesafe.config.ConfigFactory.parseString("io{}"),
parentPath + "io.",
$tsCfgValidator
Expand All @@ -189,7 +189,7 @@ object SimbenchConfig {
parentPath: java.lang.String,
$tsCfgValidator: $TsCfgValidator
): scala.List[java.lang.String] = {
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
cl.asScala.map(cv => $_str(cv)).toList
}
private def $_expE(
Expand All @@ -200,15 +200,15 @@ object SimbenchConfig {
new java.lang.RuntimeException(
s"${cv.origin.lineNumber}: " +
"expecting: " + exp + " got: " +
(if (u.isInstanceOf[java.lang.String]) "\"" + u + "\"" else u)
(if u.isInstanceOf[java.lang.String] then "\"" + u + "\"" else u)
)
}

private def $_str(cv: com.typesafe.config.ConfigValue): java.lang.String = {
java.lang.String.valueOf(cv.unwrapped())
}

private final class $TsCfgValidator {
final class $TsCfgValidator {
private val badPaths =
scala.collection.mutable.ArrayBuffer[java.lang.String]()

Expand All @@ -228,7 +228,7 @@ object SimbenchConfig {
}

def validate(): Unit = {
if (badPaths.nonEmpty) {
if badPaths.nonEmpty then {
throw new com.typesafe.config.ConfigException(
badPaths.mkString("Invalid configuration:\n ", "\n ", "")
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package edu.ie3.simbench.convert
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.simbench.model.datamodel.Coordinate
import edu.ie3.util.geo.GeoUtils
import org.locationtech.jts.geom.{Point, Coordinate => JTSCoordinate}
import org.locationtech.jts.geom.{Point, Coordinate as JTSCoordinate}

/** Converts a SimBench coordinate to the needed geometry position of
* PowerSystemDataModel
Expand Down
31 changes: 14 additions & 17 deletions src/main/scala/edu/ie3/simbench/convert/GridConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import edu.ie3.datamodel.models.input.graphics.{
LineGraphicInput,
NodeGraphicInput
}
import edu.ie3.datamodel.models.input.system._
import edu.ie3.datamodel.models.input.system.*
import edu.ie3.datamodel.models.result.NodeResult
import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.value.{PValue, SValue}
Expand All @@ -33,11 +33,11 @@ import edu.ie3.simbench.convert.types.{
Transformer2wTypeConverter
}
import edu.ie3.simbench.exception.ConversionException
import edu.ie3.simbench.model.datamodel._
import edu.ie3.simbench.model.datamodel.*

import scala.annotation.tailrec
import scala.collection.parallel.CollectionConverters._
import scala.jdk.CollectionConverters._
import scala.collection.parallel.CollectionConverters.*
import scala.jdk.CollectionConverters.*

case object GridConverter extends LazyLogging {

Expand All @@ -61,7 +61,7 @@ case object GridConverter extends LazyLogging {
removeSwitches: Boolean
): (
JointGridContainer,
Set[IndividualTimeSeries[_ <: PValue]],
Set[IndividualTimeSeries[? <: PValue]],
Seq[MappingEntry],
Vector[NodeResult]
) = {
Expand Down Expand Up @@ -130,11 +130,10 @@ case object GridConverter extends LazyLogging {
gridInput.lines,
subnetConverter
)
val joinOverrides = if (removeSwitches) {
val joinOverrides = if removeSwitches then {
/* If switches are meant to be removed, join all nodes at closed switches */
determineJoinOverrides(gridInput.switches, slackNodeKeys)
} else
Vector.empty
} else Vector.empty

val nodeConversion =
convertNodes(
Expand All @@ -156,10 +155,9 @@ case object GridConverter extends LazyLogging {
"Creation of three winding transformers is not yet implemented."
)
val switches =
if (!removeSwitches)
if !removeSwitches then
SwitchConverter.convert(gridInput.switches, nodeConversion).toSet.asJava
else
Set.empty[SwitchInput].asJava
else Set.empty[SwitchInput].asJava
val measurements = MeasurementConverter
.convert(gridInput.measurements, nodeConversion)
.toSet
Expand Down Expand Up @@ -284,8 +282,7 @@ case object GridConverter extends LazyLogging {
): Vector[SubnetOverride] = {
/* If the start node is among the junctions, do not travel further (Attention: Start node should not be among
* junctions when the traversing starts, otherwise nothing will happen at all.) */
if (junctions.contains(startNode))
return overrides
if junctions.contains(startNode) then return overrides

/* Get all switches, that are connected to the current starting point. If the other end of the switch is a junction,
* don't follow this path, as the other side wouldn't be touched anyways. */
Expand All @@ -297,7 +294,7 @@ case object GridConverter extends LazyLogging {
case _ => false
}

if (nextSwitches.isEmpty) {
if nextSwitches.isEmpty then {
/* There is no further switch, therefore the end is reached -> return the new mapping. Please note, as the subnet
* of the current node is only altered, if there is a next switch available, dead end nodes are not altered. */
overrides
Expand Down Expand Up @@ -585,7 +582,7 @@ case object GridConverter extends LazyLogging {
branchNodes.contains(convertedNode)
} match {
case (connectedNodes, unconnectedNodes) =>
if (unconnectedNodes.nonEmpty)
if unconnectedNodes.nonEmpty then
logger.warn(
"The nodes with following keys are not part of any branch (aka. isolated) and will be neglected in the sequel.\n\t{}",
unconnectedNodes.map(_._1.getKey).mkString("\n\t")
Expand All @@ -610,7 +607,7 @@ case object GridConverter extends LazyLogging {
nodeConversion: Map[Node, NodeInput]
): (
SystemParticipants,
Set[IndividualTimeSeries[_ <: PValue]],
Set[IndividualTimeSeries[? <: PValue]],
Seq[MappingEntry]
) = {
/* Convert all participant groups */
Expand Down Expand Up @@ -640,7 +637,7 @@ case object GridConverter extends LazyLogging {
timeSeries.getUuid
)
}.toSeq
val timeSeries: Set[IndividualTimeSeries[_ <: PValue]] =
val timeSeries: Set[IndividualTimeSeries[? <: PValue]] =
participantsToTimeSeries.map(_._2).toSet

(
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/edu/ie3/simbench/convert/LineConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import edu.ie3.simbench.model.datamodel.{Line, Node}
import edu.ie3.util.quantities.PowerSystemUnits.KILOMETRE
import tech.units.indriya.quantity.Quantities

import scala.collection.parallel.CollectionConverters._
import scala.collection.parallel.CollectionConverters.*

case object LineConverter extends LazyLogging {

Expand All @@ -31,7 +31,7 @@ case object LineConverter extends LazyLogging {
* A [[Vector]] of [[LineInput]]s
*/
def convert(
inputs: Vector[Line[_ <: LineType]],
inputs: Vector[Line[? <: LineType]],
types: Map[LineType, LineTypeInput],
nodes: Map[Node, NodeInput]
): Vector[LineInput] =
Expand Down Expand Up @@ -67,7 +67,7 @@ case object LineConverter extends LazyLogging {
* A [[LineInput]] model
*/
def convert(
input: Line[_ <: LineType],
input: Line[? <: LineType],
lineType: LineTypeInput,
nodeA: NodeInput,
nodeB: NodeInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import edu.ie3.util.quantities.PowerSystemUnits.{KILOWATTHOUR, MEGAVOLTAMPERE}
import tech.units.indriya.quantity.Quantities

import java.util.{Locale, UUID}
import scala.collection.parallel.CollectionConverters._
import scala.collection.parallel.CollectionConverters.*

case object LoadConverter extends ShuntConverter with LazyLogging {
def convert(
Expand Down
Loading
Loading