Kotlin conversion: NotationRegistry

This commit is contained in:
Paul Schaub 2023-09-04 16:44:41 +02:00
parent dc064d1727
commit 39e170064c
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 13 additions and 18 deletions

View File

@ -1,11 +1,8 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org> // SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
// //
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util; package org.pgpainless.util
import java.util.HashSet;
import java.util.Set;
/** /**
* Registry for known notations. * Registry for known notations.
@ -14,9 +11,12 @@ import java.util.Set;
* *
* To add a notation name, call {@link #addKnownNotation(String)}. * To add a notation name, call {@link #addKnownNotation(String)}.
*/ */
public class NotationRegistry { class NotationRegistry constructor(notations: Set<String> = setOf()) {
private val knownNotations: MutableSet<String>
private final Set<String> knownNotations = new HashSet<>(); init {
knownNotations = notations.toMutableSet()
}
/** /**
* Add a known notation name into the registry. * Add a known notation name into the registry.
@ -24,11 +24,8 @@ public class NotationRegistry {
* *
* @param notationName name of the notation * @param notationName name of the notation
*/ */
public void addKnownNotation(String notationName) { fun addKnownNotation(notationName: String): NotationRegistry = apply {
if (notationName == null) { knownNotations.add(notationName)
throw new NullPointerException("Notation name MUST NOT be null.");
}
knownNotations.add(notationName);
} }
/** /**
@ -37,14 +34,12 @@ public class NotationRegistry {
* @param notationName name of the notation * @param notationName name of the notation
* @return true if notation is known, false otherwise. * @return true if notation is known, false otherwise.
*/ */
public boolean isKnownNotation(String notationName) { fun isKnownNotation(notationName: String): Boolean = knownNotations.contains(notationName)
return knownNotations.contains(notationName);
}
/** /**
* Clear all known notations from the registry. * Clear all known notations from the registry.
*/ */
public void clear() { fun clear() {
knownNotations.clear(); knownNotations.clear()
} }
} }