Skip to content

Commit

Permalink
Add LazyEmbed.Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Aug 21, 2024
1 parent 4d0cd12 commit c995e57
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.*;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;


/**
Expand Down Expand Up @@ -317,6 +318,16 @@ public LazyEmbed replace(@NotNull String key, @Nullable Object value) {
return this;
}

/**
* Convenience method for {@link Factory#Factory(LazyEmbed) new Factory(LazyEmbed)} using this {@link LazyEmbed}
*
* @return the {@link Factory} instance
*/
@NotNull
public Factory toFactory() {
return new Factory(this);
}

/**
* Builds the {@link MessageEmbed}
*
Expand Down Expand Up @@ -647,6 +658,68 @@ public LazyEmbed setTimestamp(@Nullable Date timestamp) {
return setTimestamp(timestamp == null ? null : timestamp.getTime());
}

/**
* A factory for storing a base {@link LazyEmbed} to copy from
*/
public static class Factory {
/**
* The base {@link LazyEmbed} to copy from
*/
@NotNull private LazyEmbed embed;

/**
* Constructs a new {@link Factory} with an empty {@link LazyEmbed}
*/
public Factory() {
this.embed = new LazyEmbed();
}

/**
* Constructs a new {@link Factory} with a base {@link LazyEmbed}
*
* @param embed the base {@link LazyEmbed}
*/
public Factory(@NotNull LazyEmbed embed) {
this.embed = embed;
}

/**
* Returns a new {@link LazyEmbed} from the base {@link LazyEmbed}
*
* @return the new {@link LazyEmbed}
*/
@NotNull
public LazyEmbed newEmbed() {
return embed.copy();
}

/**
* Sets the base {@link LazyEmbed}
*
* @param embed the base {@link LazyEmbed}
*
* @return this
*/
@NotNull
public Factory setEmbed(@NotNull LazyEmbed embed) {
this.embed = embed;
return this;
}

/**
* Updates the base {@link LazyEmbed} with a consumer
*
* @param updater the consumer to update the base {@link LazyEmbed}
*
* @return this
*/
@NotNull
public Factory updateEmbed(@NotNull Consumer<LazyEmbed> updater) {
updater.accept(embed);
return this;
}
}

/**
* All possible (defaultable) keys an {@link LazyEmbed embed} can have ({@link LazySettings#embedDefaults})
*/
Expand Down

0 comments on commit c995e57

Please sign in to comment.