diff --git a/sop-java/src/main/kotlin/sop/Profile.kt b/sop-java/src/main/kotlin/sop/Profile.kt index 725bbe5..2125c57 100644 --- a/sop-java/src/main/kotlin/sop/Profile.kt +++ b/sop-java/src/main/kotlin/sop/Profile.kt @@ -20,22 +20,17 @@ import sop.util.UTF8Util * in the IETF namespace that begins with the string `draft-` should have semantics that hew as * closely as possible to the referenced Internet Draft. * @param description a free-form description of the profile. - * @param aliases list of optional profile alias names - * @see - * [SOP Spec - Profile](https://www.ietf.org/archive/id/draft-dkg-openpgp-stateless-cli-05.html#name-profile) + * @see + * SOP Spec - Profile */ -data class Profile( - val name: String, - val description: Optional, - val aliases: List = listOf() -) { +data class Profile(val name: String, val description: Optional) { @JvmOverloads constructor( name: String, - description: String? = null, - aliases: List = listOf() - ) : this(name, Optional.ofNullable(description?.trim()?.ifBlank { null }), aliases) + description: String? = null + ) : this(name, Optional.ofNullable(description?.trim()?.ifBlank { null })) init { require(name.trim().isNotBlank()) { "Name cannot be empty." } @@ -55,18 +50,8 @@ data class Profile( * * @return string */ - override fun toString(): String = buildString { - append(name) - if (!description.isEmpty || !aliases.isEmpty()) { - append(":") - } - if (!description.isEmpty) { - append(" ${description.get()}") - } - if (!aliases.isEmpty()) { - append(" (aliases: ${aliases.joinToString(separator = ", ")})") - } - } + override fun toString(): String = + if (description.isEmpty) name else "$name: ${description.get()}" companion object { @@ -79,21 +64,9 @@ data class Profile( @JvmStatic fun parse(string: String): Profile { return if (string.contains(": ")) { - val name = string.substring(0, string.indexOf(": ")) - var description = string.substring(string.indexOf(": ") + 2).trim() - if (description.contains("(aliases: ")) { - val aliases = - description.substring( - description.indexOf("(aliases: ") + 10, description.indexOf(")")) - description = description.substring(0, description.indexOf("(aliases: ")).trim() - Profile(name, description, aliases.split(", ").toList()) - } else { - if (description.isNotBlank()) { - Profile(name, description) - } else { - Profile(name) - } - } + Profile( + string.substring(0, string.indexOf(": ")), + string.substring(string.indexOf(": ") + 2).trim()) } else if (string.endsWith(":")) { Profile(string.substring(0, string.length - 1)) } else { diff --git a/sop-java/src/test/java/sop/ProfileTest.java b/sop-java/src/test/java/sop/ProfileTest.java index 41b4a2f..564a6af 100644 --- a/sop-java/src/test/java/sop/ProfileTest.java +++ b/sop-java/src/test/java/sop/ProfileTest.java @@ -5,9 +5,6 @@ package sop; import org.junit.jupiter.api.Test; -import sop.util.Optional; - -import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -22,23 +19,6 @@ public class ProfileTest { assertEquals("default: Use the implementers recommendations.", profile.toString()); } - @Test - public void withAliasesToString() { - Profile profile = new Profile( - "Foo", - Optional.of("Something something"), - Arrays.asList("Bar", "Baz")); - assertEquals("Foo: Something something (aliases: Bar, Baz)", profile.toString()); - } - - @Test - public void parseWithAliases() { - Profile profile = Profile.parse("Foo: Something something (aliases: Bar, Baz)"); - assertEquals("Foo", profile.getName()); - assertEquals("Something something", profile.getDescription().get()); - assertEquals(Arrays.asList("Bar", "Baz"), profile.getAliases()); - } - @Test public void toStringNameOnly() { Profile profile = new Profile("default");