From d3d8bc1901d8bbfd176b0d4e7bfaec615fe65946 Mon Sep 17 00:00:00 2001 From: James Barr Date: Fri, 24 Aug 2018 18:24:07 -0700 Subject: [PATCH] Simplify enum and use data classes --- .../com/commit451/resourcespoet/Plural.kt | 4 +- .../com/commit451/resourcespoet/StyleItem.kt | 2 +- .../com/commit451/resourcespoet/Type.kt | 81 ++++--------------- 3 files changed, 18 insertions(+), 69 deletions(-) diff --git a/src/main/kotlin/com/commit451/resourcespoet/Plural.kt b/src/main/kotlin/com/commit451/resourcespoet/Plural.kt index 51a594c..0914a1e 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/Plural.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/Plural.kt @@ -4,13 +4,13 @@ package com.commit451.resourcespoet * Represents an Android Plural * See //developer.android.com/guide/topics/resources/string-resource.html#Plurals">https://developer.android.com/guide/topics/resources/string-resource.html#Plurals */ -class Plural +data class Plural /** * Construct a new plural * @param quantity the quantity * @param value the value */ -(var quantity: Quantity, var value: String) { +(val quantity: Quantity, val value: String) { enum class Quantity { zero, diff --git a/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt b/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt index a98b780..137e74b 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt @@ -5,4 +5,4 @@ package com.commit451.resourcespoet * * @android:color/black */ -class StyleItem(var name: String, var value: String) +data class StyleItem(val name: String, val value: String) diff --git a/src/main/kotlin/com/commit451/resourcespoet/Type.kt b/src/main/kotlin/com/commit451/resourcespoet/Type.kt index fb70148..d16c536 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/Type.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/Type.kt @@ -5,72 +5,21 @@ package com.commit451.resourcespoet * * [Available Resources](https://developer.android.com/guide/topics/resources/available-resources.html) */ -enum class Type { +enum class Type(private val xmlName: String) { - ATTR { - override fun toString(): String { - return "attr" - } - }, - BOOL { - override fun toString(): String { - return "bool" - } - }, - COLOR { - override fun toString(): String { - return "color" - } - }, - DRAWABLE { - override fun toString(): String { - return "drawable" - } - }, - DIMENSION { - override fun toString(): String { - return "dimen" - } - }, - ID { - override fun toString(): String { - return "item" - } - }, - INTEGER { - override fun toString(): String { - return "integer" - } - }, - INTEGER_ARRAY { - override fun toString(): String { - return "integer-array" - } - }, - PLURALS { - override fun toString(): String { - return "plurals" - } - }, - STRING { - override fun toString(): String { - return "string" - } - }, - STRING_ARRAY { - override fun toString(): String { - return "string-array" - } - }, - STYLE { - override fun toString(): String { - return "style" - } - }, - TYPED_ARRAY { - override fun toString(): String { - return "array" - } - } + ATTR("attr"), + BOOL("bool"), + COLOR("color"), + DRAWABLE("drawable"), + DIMENSION("dimen"), + ID("item"), + INTEGER("integer"), + INTEGER_ARRAY("integer-array"), + PLURALS("plurals"), + STRING("string"), + STRING_ARRAY("string-array"), + STYLE("style"), + TYPED_ARRAY("array"); + override fun toString() = xmlName }