From d1e83654b77e7c299ab4244c261edf9c07fa41b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Henning?= <soeren.henning@email.uni-kiel.de>
Date: Fri, 21 Jan 2022 19:38:32 +0100
Subject: [PATCH] Minor code quality fixes

---
 .../benchmark/ConfigMapResourceSet.kt         | 26 ++++++++++---------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt
index 27e3206ad..d50caec12 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt
@@ -12,7 +12,7 @@ import java.lang.IllegalArgumentException
 
 @RegisterForReflection
 @JsonDeserialize
-class ConfigMapResourceSet: ResourceSet, KubernetesResource {
+class ConfigMapResourceSet : ResourceSet, KubernetesResource {
     lateinit var name: String
     lateinit var files: List<String> // load all files, iff files is not set
 
@@ -31,7 +31,7 @@ class ConfigMapResourceSet: ResourceSet, KubernetesResource {
             throw DeploymentFailedException("Cannot find or read ConfigMap with name '$name'.", e)
         }
 
-        if (::files.isInitialized){
+        if (::files.isInitialized) {
             resources = resources.filter { files.contains(it.key) }
 
             if (resources.size != files.size) {
@@ -41,15 +41,20 @@ class ConfigMapResourceSet: ResourceSet, KubernetesResource {
 
         return try {
             resources
-                .map { Pair(
-                    getKind(resource = it.value),
-                    it) }
+                .map {
+                    Pair(
+                        getKind(resource = it.value),
+                        it
+                    )
+                }
                 .map {
                     Pair(
                         it.second.key,
-                        loader.loadK8sResource(it.first, it.second.value)) }
+                        loader.loadK8sResource(it.first, it.second.value)
+                    )
+                }
         } catch (e: IllegalArgumentException) {
-            throw DeploymentFailedException("Can not create resource set from specified configmap", e)
+            throw DeploymentFailedException("Cannot create resource set from specified ConfigMap", e)
         }
 
     }
@@ -58,10 +63,7 @@ class ConfigMapResourceSet: ResourceSet, KubernetesResource {
         val parser = YamlParserFromString()
         val resourceAsMap = parser.parse(resource, HashMap<String, String>()::class.java)
 
-        return try {
-            resourceAsMap?.get("kind") !!
-        } catch (e: NullPointerException) {
-            throw DeploymentFailedException( "Could not find field kind of Kubernetes resource: ${resourceAsMap?.get("name")}", e)
-        }
+        return resourceAsMap?.get("kind")
+            ?: throw DeploymentFailedException("Could not find field kind of Kubernetes resource: ${resourceAsMap?.get("name")}")
     }
 }
\ No newline at end of file
-- 
GitLab