Skip to content

Commit

Permalink
Remove dependencies to apache commons
Browse files Browse the repository at this point in the history
  • Loading branch information
sknull committed Mar 29, 2024
1 parent e4e765c commit ae46c00
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 70 deletions.
10 changes: 0 additions & 10 deletions klanglicht-module-dmx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,11 @@
</dependency>

<!-- commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>

<!-- jackson -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.visualdigits.kotlin.klanglicht.model.color

import org.apache.commons.lang3.StringUtils
import java.lang.Long.decode
import kotlin.math.min
import kotlin.math.roundToInt
Expand Down Expand Up @@ -28,7 +27,7 @@ class RGBAColor(
constructor(hex: String) : this(decode(if (hex.startsWith("#") || hex.startsWith("0x")) hex else "#$hex"))

override fun toString(): String {
return "[" + StringUtils.join(listOf(red, green, blue, amber), ", ") + "]"
return "[" + listOf(red, green, blue, amber).joinToString(", ") + "]"
}

override fun repr(): String {
Expand All @@ -55,7 +54,7 @@ class RGBAColor(

override fun value(): Long = (red.toLong() shl 24) or (green.toLong() shl 16) or (blue.toLong() shl 8) or amber.toLong()

override fun hex(): String = StringUtils.leftPad(java.lang.Long.toHexString(value()), 8, '0')
override fun hex(): String = java.lang.Long.toHexString(value()).padStart(8, '0')

override fun web(): String = "#${hex()}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.visualdigits.kotlin.klanglicht.model.color

import org.apache.commons.lang3.StringUtils
import java.lang.Long.decode
import java.lang.Long.toHexString
import kotlin.math.max
Expand All @@ -23,7 +22,7 @@ abstract class RGBBaseColor<T : RGBBaseColor<T>>(
constructor(hex: String) : this(decode(if (hex.startsWith("#") || hex.startsWith("0x")) hex else "#$hex"))

override fun toString(): String {
return "[" + StringUtils.join(listOf(red, green, blue), ", ") + "]"
return "[" + listOf(red, green, blue).joinToString(", ") + "]"
}

open fun repr(): String {
Expand All @@ -50,7 +49,7 @@ abstract class RGBBaseColor<T : RGBBaseColor<T>>(

override fun value(): Long = red.toLong() shl 16 or (green.toLong() shl 8) or blue.toLong()

override fun hex(): String = StringUtils.leftPad(toHexString(value()), 6, '0')
override fun hex(): String = toHexString(value()).padStart( 6, '0')

override fun web(): String = "#${hex()}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.visualdigits.kotlin.klanglicht.model.color

import org.apache.commons.lang3.StringUtils
import java.lang.Long.decode
import java.lang.Long.toHexString
import kotlin.math.min
import kotlin.math.roundToInt

Expand All @@ -24,7 +24,7 @@ class RGBWAColor(
constructor(hex: String) : this(decode(if (hex.startsWith("#") || hex.startsWith("0x")) hex else "#$hex"))

override fun toString(): String {
return "[" + StringUtils.join(listOf(red, green, blue, white, amber), ", ") + "]"
return "[" +listOf(red, green, blue, white, amber).joinToString(", ") + "]"
}

override fun repr(): String {
Expand Down Expand Up @@ -53,7 +53,7 @@ class RGBWAColor(

override fun value(): Long = (red.toLong() shl 32) or (green.toLong() shl 24) or (blue.toLong() shl 16) or (white.toLong() shl 8) or amber.toLong()

override fun hex(): String = StringUtils.leftPad(java.lang.Long.toHexString(value()), 10, '0')
override fun hex(): String = toHexString(value()).padStart( 10, '0')

override fun web(): String = "#${hex()}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.visualdigits.kotlin.klanglicht.model.color

import org.apache.commons.lang3.StringUtils
import java.lang.Long.decode
import java.lang.Long.toHexString
import kotlin.math.min
import kotlin.math.roundToInt

Expand Down Expand Up @@ -31,7 +31,7 @@ class RGBWColor(
}

override fun toString(): String {
return "[" + StringUtils.join(listOf(red, green, blue, white), ", ") + "]"
return "[" + listOf(red, green, blue, white).joinToString(", ") + "]"
}

override fun repr(): String {
Expand All @@ -58,7 +58,7 @@ class RGBWColor(

override fun value(): Long = (red.toLong() shl 24) or (green.toLong() shl 16) or (blue.toLong() shl 8) or white.toLong()

override fun hex(): String = StringUtils.leftPad(java.lang.Long.toHexString(value()), 8, '0')
override fun hex(): String = toHexString(value()).padStart(8, '0')

override fun web(): String = "#${hex()}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.visualdigits.kotlin.klanglicht.model.dmx

import com.google.common.primitives.Bytes
import org.apache.commons.lang3.StringUtils
import java.lang.Integer.toHexString
import java.util.Arrays


Expand Down Expand Up @@ -38,7 +37,7 @@ class DmxFrame(
/**
* Returns the bytes for a complete frame including header and footer.
*/
fun getFrameBytes(): ByteArray = Bytes.concat(header, data, footer)
fun getFrameBytes(): ByteArray = header + data + footer

/**
* Sets all data bytes to 0.
Expand All @@ -58,9 +57,9 @@ class DmxFrame(
fun dump(): String {
val l: MutableList<String> = ArrayList()
for (b in data) {
l.add("0x" + StringUtils.leftPad(Integer.toHexString(b.toInt() and 0xff), 2, '0'))
l.add("0x" + toHexString(b.toInt() and 0xff).padStart( 2, '0'))
}
return StringUtils.join(l, ", ")
return l.joinToString(", ")
}

fun clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.visualdigits.kotlin.klanglicht.model.dmx

import jssc.SerialPort
import jssc.SerialPortException
import org.apache.commons.lang3.StringUtils
import java.lang.Integer.toHexString


open class DmxInterface {
Expand All @@ -28,7 +28,7 @@ open class DmxInterface {
fun repr(): String {
val lst = ArrayList<String>()
for (b in dmxFrame.getFrameBytes()) {
lst.add(StringUtils.leftPad(Integer.toHexString(b.toInt()), 8, '0'))
lst.add(toHexString(b.toInt()).padStart( 8, '0'))
}
return lst.toString()
}
Expand All @@ -39,7 +39,7 @@ open class DmxInterface {
* @param portName The port name (i.e. 'COM9'.
*/
open fun open(portName: String) {
if (serialPort == null && !StringUtils.isEmpty(portName)) {
if (serialPort == null && portName.isNotEmpty()) {
try {
serialPort = SerialPort(portName)
serialPort?.openPort()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.visualdigits.kotlin.klanglicht.model.hybrid

import de.visualdigits.kotlin.klanglicht.model.preferences.Preferences
import org.apache.commons.lang3.SystemUtils
import de.visualdigits.kotlin.util.SystemUtils
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import java.io.File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package de.visualdigits.kotlin.klanglicht.model.preferences
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import de.visualdigits.kotlin.klanglicht.model.hybrid.HybridScene
import org.apache.commons.lang3.SystemUtils
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import java.io.File
Expand Down
4 changes: 2 additions & 2 deletions klanglicht-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
</dependency>

<!-- common stuff -->
<dependency>
<!--dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
</dependency-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package de.visualdigits.kotlin.klanglicht.rest.configuration
import de.visualdigits.kotlin.klanglicht.model.hybrid.HybridScene
import de.visualdigits.kotlin.klanglicht.model.parameter.Fadeable
import de.visualdigits.kotlin.klanglicht.model.preferences.Preferences
import de.visualdigits.kotlin.util.SystemUtils
import jakarta.annotation.PostConstruct
import jakarta.annotation.PreDestroy
import kotlinx.coroutines.runBlocking
import org.apache.commons.lang3.SystemUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.html.LMScene
import de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.html.LMScenes
import de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.html.LMZones
import jakarta.annotation.PostConstruct
import org.apache.commons.lang3.StringUtils
import org.jsoup.Jsoup
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
Expand All @@ -25,7 +24,7 @@ class LightmanagerClient(

@PostConstruct
fun initialize() {
if (StringUtils.isEmpty(lightmanagerUrl)) {
if (lightmanagerUrl?.isEmpty() == true) {
lightmanagerUrl = configHolder!!.preferences?.getService("lmair")?.url
}
client = LightmanagerFeignClient.client(lightmanagerUrl)
Expand Down Expand Up @@ -108,8 +107,8 @@ class LightmanagerClient(
LMMarker(
id = id,
name = elem.text(),
colorOff = if (StringUtils.isNotEmpty(colorOff)) colorOff else COLOR_OFF,
colorOn = if (StringUtils.isNotEmpty(colorOn)) colorOn else COLOR_ON,
colorOff = colorOff.ifEmpty { COLOR_OFF },
colorOn = colorOn.ifEmpty { COLOR_ON },
state = markerState[id],
separate = false,
actorId = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.html
import com.fasterxml.jackson.annotation.JsonIgnore
import de.visualdigits.kotlin.klanglicht.rest.configuration.ConfigHolder
import de.visualdigits.kotlin.klanglicht.rest.lightmanager.feign.LightmanagerClient
import org.apache.commons.lang3.StringUtils

class LMActor(
var id: Int? = null,
Expand Down Expand Up @@ -77,18 +76,18 @@ class LMActor(
colorOn = marker?.colorOn
isSeparate = marker?.separate
}
else if (!markers.isEmpty()) {
else if (markers.isNotEmpty()) {
hasSeparateMarkers = true
}
if (StringUtils.isEmpty(colorOff)) {
if (colorOff?.isEmpty() == true) {
colorOff =
if (StringUtils.isNotEmpty(colorOff)) colorOff else LightmanagerClient.COLOR_OFF
colorOff.ifEmpty { LightmanagerClient.COLOR_OFF }
}
if (StringUtils.isEmpty(colorOn)) {
colorOn = if (StringUtils.isNotEmpty(colorOn)) colorOn else LightmanagerClient.COLOR_ON
if (colorOn?.isEmpty() == true) {
colorOn = colorOn.ifEmpty { LightmanagerClient.COLOR_ON }
}
val lmRequests = requests.values.toList()
if (!lmRequests.isEmpty() && lmRequests.first() is LMDefaultRequest) {
if (lmRequests.isNotEmpty() && lmRequests.first() is LMDefaultRequest) {
if (hasSeparateMarkers == true || isSeparate == true) {
sb.append(" <div class=\"double-button\">\n")
// Collections.reverse(lmRequests);
Expand Down Expand Up @@ -116,8 +115,7 @@ class LMActor(
else {
val rq0 = lmRequests.first() as LMDefaultRequest
val smkState0 = determineSmkState(rq0)
var rq: LMRequest? = null
rq = if (markerIsOn == true && !smkState0 || markerIsOn != true && smkState0) {
val rq: LMRequest? = if (markerIsOn == true && !smkState0 || markerIsOn != true && smkState0) {
rq0
}
else if (lmRequests.size > 1) {
Expand Down Expand Up @@ -215,7 +213,7 @@ class LMActor(

fun addMarker(marker: LMMarker?) {
var markerState = marker?.markerState!!
if (StringUtils.isEmpty(markerState)) {
if (markerState.isEmpty()) {
markerState = "unified"
}
markers[markerState] = marker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.html

import org.apache.commons.lang3.StringUtils

class LMMarkers(
var name: String? = null,
var markers: MutableMap<Int, LMMarker> = mutableMapOf()
Expand All @@ -10,7 +8,7 @@ class LMMarkers(
val attributes = LMNamedAttributes(marker.name, "separate", "actorId", "state")
if (attributes.matched()) {
val name = attributes.name
if (StringUtils.isNotEmpty(name)) {
if (name?.isNotEmpty() == true) {
marker.name = name
}
marker.separate = attributes.getOrDefault("separate", "false").toBoolean()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.html

import de.visualdigits.kotlin.klanglicht.rest.configuration.ConfigHolder
import org.apache.commons.lang3.StringUtils


class LMScene(
Expand All @@ -17,7 +16,7 @@ class LMScene(
val lightmanagerUrl = configHolder.preferences?.getService("lmair")?.url
val sb = StringBuilder()
sb.append(" <div class=\"button\"")
if (StringUtils.isNotEmpty(color)) {
if (color?.isNotEmpty() == true) {
if (color?.contains(",") == true) {
sb.append(" style=\"background: -moz-linear-gradient(left, ")
.append(color)
Expand Down
Loading

0 comments on commit ae46c00

Please sign in to comment.