001//
002// MIT License
003//
004// Copyright (c) 2021 Alexander Söderberg & Contributors
005//
006// Permission is hereby granted, free of charge, to any person obtaining a copy
007// of this software and associated documentation files (the "Software"), to deal
008// in the Software without restriction, including without limitation the rights
009// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010// copies of the Software, and to permit persons to whom the Software is
011// furnished to do so, subject to the following conditions:
012//
013// The above copyright notice and this permission notice shall be included in all
014// copies or substantial portions of the Software.
015//
016// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
022// SOFTWARE.
023//
024package cloud.commandframework.captions;
025
026import org.checkerframework.checker.nullness.qual.NonNull;
027
028import java.util.Objects;
029
030/**
031 * This is a reference to a caption and does not contain any message itself
032 */
033public final class Caption {
034
035    private final String key;
036
037    private Caption(final @NonNull String key) {
038        this.key = key;
039    }
040
041    /**
042     * Create a new caption with a given key
043     *
044     * @param key Caption key
045     * @return Created caption
046     */
047    public static @NonNull Caption of(final @NonNull String key) {
048        return new Caption(key);
049    }
050
051    @Override
052    public boolean equals(final Object o) {
053        if (this == o) {
054            return true;
055        }
056        if (o == null || getClass() != o.getClass()) {
057            return false;
058        }
059        final Caption caption = (Caption) o;
060        return Objects.equals(key, caption.key);
061    }
062
063    /**
064     * Get the caption key
065     *
066     * @return Caption key
067     */
068    public @NonNull String getKey() {
069        return this.key;
070    }
071
072    @Override
073    public int hashCode() {
074        return Objects.hash(key);
075    }
076
077    @Override
078    public String toString() {
079        return String.format(
080                "Caption{key='%s'}",
081                this.key
082        );
083    }
084
085}