Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions libs/model/src/main/kotlin/de/cyface/model/osm/Way.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2024 Cyface GmbH
* Copyright 2019-2025 Cyface GmbH
*
* This file is part of the Serialization.
*
Expand All @@ -18,14 +18,11 @@
*/
package de.cyface.model.osm

import org.apache.commons.lang3.Validate
import java.util.Locale
import java.util.Objects
import java.util.Optional
import java.util.stream.Collectors



/**
* A POJO representing an Open Street Map way.
*
Expand All @@ -46,18 +43,18 @@ class Way<T : MapTag> : Comparable<Way<out MapTag>> {
var nodes: Array<Node> = emptyArray()
get() = field.copyOf()
set(value) {
Validate.notNull(value)
requireNotNull(value)
field = value.copyOf()
}

var tags: Map<String, T> = emptyMap()
set(value) {
Validate.notNull(value)
requireNotNull(value)
field = value.toMap()
}

/**
* A no argument constructor as required by Apache flink
* A no argument constructor as required by Apache Flink
*/
@Suppress("unused") // Part of the API
constructor()
Expand All @@ -71,8 +68,8 @@ class Way<T : MapTag> : Comparable<Way<out MapTag>> {
*/
@Suppress("unused") // Part of the API
constructor(identifier: Long, nodes: Array<Node>, tags: Collection<T>) {
Validate.isTrue(identifier > 0L)
Validate.notNull(nodes)
require(identifier > 0L) { "Identifier must be > 0 but was $identifier" }
requireNotNull(nodes)

this.identifier = identifier
this.nodes = nodes
Expand All @@ -92,7 +89,7 @@ class Way<T : MapTag> : Comparable<Way<out MapTag>> {
* @param tags The tags associated with the way. This might be an empty `Collection`
*/
fun setTags(tags: Collection<T>) {
Validate.notNull(tags)
requireNotNull(tags)

this.tags = tags.stream().collect(Collectors.toMap({ it.key }, { it }))
}
Expand All @@ -102,7 +99,7 @@ class Way<T : MapTag> : Comparable<Way<out MapTag>> {
}

override fun compareTo(other: Way<out MapTag>): Int {
Validate.notNull(other)
requireNotNull(other)
return this.identifier.compareTo(other.identifier)
}

Expand Down