Add shorthand methods for string creation

This commit is contained in:
Kieran Wallbanks 2021-04-18 22:45:38 +01:00
parent 3651a132fe
commit 0ac6d1aa37
2 changed files with 33 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package net.minestom.server.utils.identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@ -21,6 +22,16 @@ public interface NamedAndIdentified extends Named<Component>, Identified {
return of(EMPTY, UUID.randomUUID());
}
/**
* Creates a {@link NamedAndIdentified} instance with a given name and a random UUID.
*
* @param name the name
* @return the named and identified instance
*/
static @NotNull NamedAndIdentified named(@NotNull String name) {
return of(name, UUID.randomUUID());
}
/**
* Creates a {@link NamedAndIdentified} instance with a given name and a random UUID.
*
@ -41,6 +52,17 @@ public interface NamedAndIdentified extends Named<Component>, Identified {
return of(EMPTY, uuid);
}
/**
* Creates a {@link NamedAndIdentified} instance with a given name and UUID.
*
* @param name the name
* @param uuid the uuid
* @return the named and identified instance
*/
static @NotNull NamedAndIdentified of(@NotNull String name, @NotNull UUID uuid) {
return new NamedAndIdentifiedImpl(name, uuid);
}
/**
* Creates a {@link NamedAndIdentified} instance with a given name and UUID.
*

View File

@ -15,6 +15,17 @@ class NamedAndIdentifiedImpl implements NamedAndIdentified {
private final Component name;
private final UUID uuid;
/**
* Creates a new named and identified implementation.
*
* @param name the name
* @param uuid the uuid
* @see NamedAndIdentified#of(String, UUID)
*/
NamedAndIdentifiedImpl(@NotNull String name, @NotNull UUID uuid) {
this(Component.text(name), uuid);
}
/**
* Creates a new named and identified implementation.
*