Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tristate method to TextDecoration.State #495

Merged
merged 4 commits into from Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,6 +25,7 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.Index;
import net.kyori.adventure.util.TriState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -166,5 +167,16 @@ public String toString() {
public static @NotNull State byBoolean(final @Nullable Boolean flag) {
return flag == null ? NOT_SET : byBoolean(flag.booleanValue());
}

/**
* Gets a state from a {@link net.kyori.adventure.util.TriState}.
*
* @param flag the tristate
* @return the state
* @since 4.10.0
*/
public static @NotNull State byTriState(final @NotNull TriState flag) {
return byBoolean(flag.toBoolean());
KingOfSquares marked this conversation as resolved.
Show resolved Hide resolved
KingOfSquares marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Up @@ -23,6 +23,7 @@
*/
package net.kyori.adventure.text.format;

import net.kyori.adventure.util.TriState;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -34,4 +35,11 @@ void testByBoolean() {
assertEquals(TextDecoration.State.FALSE, TextDecoration.State.byBoolean(false));
assertEquals(TextDecoration.State.TRUE, TextDecoration.State.byBoolean(true));
}

@Test
void testByTristate() {
assertEquals(TextDecoration.State.NOT_SET, TextDecoration.State.byTriState(TriState.NOT_SET));
assertEquals(TextDecoration.State.FALSE, TextDecoration.State.byTriState(TriState.FALSE));
assertEquals(TextDecoration.State.TRUE, TextDecoration.State.byTriState(TriState.TRUE));
}
}