Skip to content

Commit

Permalink
chore(api): more api migrations to jspecify
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed Oct 12, 2023
1 parent a7b3b4c commit 8ab0155
Show file tree
Hide file tree
Showing 29 changed files with 237 additions and 210 deletions.
37 changes: 19 additions & 18 deletions api/src/main/java/net/kyori/adventure/inventory/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

/**
* Represents the in-game interface of a book.
Expand All @@ -48,6 +48,7 @@
* @since 4.0.0
*/
@ApiStatus.NonExtendable
@NullMarked
public interface Book extends Buildable<Book, Book.Builder>, Examinable {
/**
* Creates a book.
Expand All @@ -58,7 +59,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @return a book
* @since 4.0.0
*/
static @NonNull Book book(final @NonNull Component title, final @NonNull Component author, final @NonNull Collection<Component> pages) {
static Book book(final Component title, final Component author, final Collection<Component> pages) {
return new BookImpl(title, author, new ArrayList<>(pages));
}

Expand All @@ -71,7 +72,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @return a book
* @since 4.0.0
*/
static @NonNull Book book(final @NonNull Component title, final @NonNull Component author, final @NonNull Component@NonNull... pages) {
static Book book(final Component title, final Component author, final Component... pages) {
return book(title, author, Arrays.asList(pages));
}

Expand All @@ -81,7 +82,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @return a builder
* @since 4.0.0
*/
static @NonNull Builder builder() {
static Builder builder() {
return new BookImpl.BuilderImpl();
}

Expand All @@ -91,7 +92,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @return the title
* @since 4.0.0
*/
@NonNull Component title();
Component title();

/**
* Changes the book's title.
Expand All @@ -101,15 +102,15 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @since 4.0.0
*/
@Contract(value = "_ -> new", pure = true)
@NonNull Book title(final @NonNull Component title);
Book title(final Component title);

/**
* Gets the author.
*
* @return the author
* @since 4.0.0
*/
@NonNull Component author();
Component author();

/**
* Changes the book's author.
Expand All @@ -119,7 +120,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @since 4.0.0
*/
@Contract(value = "_ -> new", pure = true)
@NonNull Book author(final @NonNull Component author);
Book author(final Component author);

/**
* Gets the list of pages.
Expand All @@ -129,7 +130,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @return the list of pages
* @since 4.0.0
*/
@Unmodifiable @NonNull List<Component> pages();
@Unmodifiable List<Component> pages();

/**
* Returns an updated book with the provided pages.
Expand All @@ -139,7 +140,7 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @since 4.0.0
*/
@Contract(value = "_ -> new", pure = true)
default @NonNull Book pages(final @NonNull Component@NonNull... pages) {
default Book pages(final Component... pages) {
return this.pages(Arrays.asList(pages));
}

Expand All @@ -151,15 +152,15 @@ public interface Book extends Buildable<Book, Book.Builder>, Examinable {
* @since 4.0.0
*/
@Contract(value = "_ -> new", pure = true)
@NonNull Book pages(final @NonNull List<Component> pages);
Book pages(final List<Component> pages);

/**
* Create a new builder initialized with the attributes of this book.
*
* @return the builder
*/
@Override
default @NonNull Builder toBuilder() {
default Builder toBuilder() {
return builder()
.title(this.title())
.author(this.author())
Expand All @@ -180,7 +181,7 @@ interface Builder extends AbstractBuilder<Book>, Buildable.Builder<Book> {
* @since 4.0.0
*/
@Contract("_ -> this")
@NonNull Builder title(final @NonNull Component title);
Builder title(final Component title);

/**
* Set the author.
Expand All @@ -190,7 +191,7 @@ interface Builder extends AbstractBuilder<Book>, Buildable.Builder<Book> {
* @since 4.0.0
*/
@Contract("_ -> this")
@NonNull Builder author(final @NonNull Component author);
Builder author(final Component author);

/**
* Add a page to the book.
Expand All @@ -203,7 +204,7 @@ interface Builder extends AbstractBuilder<Book>, Buildable.Builder<Book> {
* @since 4.0.0
*/
@Contract("_ -> this")
@NonNull Builder addPage(final @NonNull Component page);
Builder addPage(final Component page);

/**
* Add pages to the book.
Expand All @@ -214,7 +215,7 @@ interface Builder extends AbstractBuilder<Book>, Buildable.Builder<Book> {
* @since 4.0.0
*/
@Contract("_ -> this")
@NonNull Builder pages(final @NonNull Component@NonNull... pages);
Builder pages(final Component... pages);

/**
* Add pages to the book.
Expand All @@ -225,14 +226,14 @@ interface Builder extends AbstractBuilder<Book>, Buildable.Builder<Book> {
* @since 4.0.0
*/
@Contract("_ -> this")
@NonNull Builder pages(final @NonNull Collection<Component> pages);
Builder pages(final Collection<Component> pages);

/**
* Builds.
*
* @return a new book
*/
@Override
@NonNull Book build();
Book build();
}
}
31 changes: 16 additions & 15 deletions api/src/main/java/net/kyori/adventure/inventory/BookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,54 @@
import net.kyori.adventure.internal.Internals;
import net.kyori.adventure.text.Component;
import net.kyori.examination.ExaminableProperty;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

import static java.util.Objects.requireNonNull;

@NullMarked
final class BookImpl implements Book {
private final Component title;
private final Component author;
private final List<Component> pages;

BookImpl(final @NonNull Component title, final @NonNull Component author, final @NonNull List<Component> pages) {
BookImpl(final Component title, final Component author, final List<Component> pages) {
this.title = requireNonNull(title, "title");
this.author = requireNonNull(author, "author");
this.pages = Collections.unmodifiableList(requireNonNull(pages, "pages"));
}

@Override
public @NonNull Component title() {
public Component title() {
return this.title;
}

@Override
public @NonNull Book title(final @NonNull Component title) {
public Book title(final Component title) {
return new BookImpl(requireNonNull(title, "title"), this.author, this.pages);
}

@Override
public @NonNull Component author() {
public Component author() {
return this.author;
}

@Override
public @NonNull Book author(final @NonNull Component author) {
public Book author(final Component author) {
return new BookImpl(this.title, requireNonNull(author, "author"), this.pages);
}

@Override
public @NonNull List<Component> pages() {
public List<Component> pages() {
return this.pages;
}

@Override
public @NonNull Book pages(final @NonNull List<Component> pages) {
public Book pages(final List<Component> pages) {
return new BookImpl(this.title, this.author, new ArrayList<>(requireNonNull(pages, "pages")));
}

@Override
public @NonNull Stream<? extends ExaminableProperty> examinableProperties() {
public Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("title", this.title),
ExaminableProperty.of("author", this.author),
Expand Down Expand Up @@ -114,37 +115,37 @@ static final class BuilderImpl implements Book.Builder {
private final List<Component> pages = new ArrayList<>();

@Override
public @NonNull Builder title(final @NonNull Component title) {
public Builder title(final Component title) {
this.title = requireNonNull(title, "title");
return this;
}

@Override
public @NonNull Builder author(final @NonNull Component author) {
public Builder author(final Component author) {
this.author = requireNonNull(author, "author");
return this;
}

@Override
public @NonNull Builder addPage(final @NonNull Component page) {
public Builder addPage(final Component page) {
this.pages.add(requireNonNull(page, "page"));
return this;
}

@Override
public @NonNull Builder pages(final @NonNull Collection<Component> pages) {
public Builder pages(final Collection<Component> pages) {
this.pages.addAll(requireNonNull(pages, "pages"));
return this;
}

@Override
public @NonNull Builder pages(final @NonNull Component@NonNull... pages) {
public Builder pages(final Component... pages) {
Collections.addAll(this.pages, pages);
return this;
}

@Override
public @NonNull Book build() {
public Book build() {
return new BookImpl(this.title, this.author, new ArrayList<>(this.pages));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import net.kyori.adventure.util.Codec;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

/**
* Holds a compound binary tag.
Expand All @@ -37,6 +37,7 @@
*
* @since 4.0.0
*/
@NullMarked
public interface BinaryTagHolder {
/**
* Encodes {@code nbt} using {@code codec}.
Expand All @@ -49,7 +50,7 @@ public interface BinaryTagHolder {
* @throws EX if an error occurred while encoding the binary tag
* @since 4.0.0
*/
static <T, EX extends Exception> @NonNull BinaryTagHolder encode(final @NonNull T nbt, final @NonNull Codec<? super T, String, ?, EX> codec) throws EX {
static <T, EX extends Exception> BinaryTagHolder encode(final T nbt, final Codec<? super T, String, ?, EX> codec) throws EX {
return new BinaryTagHolderImpl(codec.encode(nbt));
}

Expand All @@ -60,7 +61,7 @@ public interface BinaryTagHolder {
* @return the encoded binary tag
* @since 4.10.0
*/
static @NonNull BinaryTagHolder binaryTagHolder(final @NonNull String string) {
static BinaryTagHolder binaryTagHolder(final String string) {
return new BinaryTagHolderImpl(string);
}

Expand All @@ -74,7 +75,7 @@ public interface BinaryTagHolder {
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
static @NonNull BinaryTagHolder of(final @NonNull String string) {
static BinaryTagHolder of(final String string) {
return new BinaryTagHolderImpl(string);
}

Expand All @@ -84,7 +85,7 @@ public interface BinaryTagHolder {
* @return the raw string value
* @since 4.0.0
*/
@NonNull String string();
String string();

/**
* Gets the held value as a binary tag.
Expand All @@ -96,5 +97,5 @@ public interface BinaryTagHolder {
* @throws DX if an error occurred while retrieving the binary tag
* @since 4.0.0
*/
<T, DX extends Exception> @NonNull T get(final @NonNull Codec<T, String, DX, ?> codec) throws DX;
<T, DX extends Exception> T get(final Codec<T, String, DX, ?> codec) throws DX;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
package net.kyori.adventure.nbt.api;

import net.kyori.adventure.util.Codec;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

import static java.util.Objects.requireNonNull;

@NullMarked
final class BinaryTagHolderImpl implements BinaryTagHolder {
private final String string;

Expand All @@ -36,12 +37,12 @@ final class BinaryTagHolderImpl implements BinaryTagHolder {
}

@Override
public @NonNull String string() {
public String string() {
return this.string;
}

@Override
public <T, DX extends Exception> @NonNull T get(final @NonNull Codec<T, String, DX, ?> codec) throws DX {
public <T, DX extends Exception> T get(final Codec<T, String, DX, ?> codec) throws DX {
return codec.decode(this.string);
}

Expand Down
Loading

0 comments on commit 8ab0155

Please sign in to comment.