Skip to content

Commit

Permalink
Move UpdateBuilder to builders package
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Apr 3, 2024
1 parent 6fb3b59 commit 4d2689d
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.srnyx.magicmongo;
package xyz.srnyx.magicmongo.builders;

import com.mongodb.client.model.Updates;

Expand All @@ -19,12 +19,17 @@ public class UpdateBuilder {
*/
@Nullable private Bson update;

/**
* Creates a new {@link UpdateBuilder} instance with no starting {@link #update}
*/
public UpdateBuilder() {}

/**
* Creates a new {@link UpdateBuilder} instance with the given {@link #update}
*
* @param update the {@link Bson update} to start with
*/
public UpdateBuilder(@NotNull Bson update) {
public UpdateBuilder(@Nullable Bson update) {
this.update = update;
}

Expand Down Expand Up @@ -56,9 +61,17 @@ public UpdateBuilder(@NotNull UpdateBuilder updateBuilder) {
}

/**
* Creates a new {@link UpdateBuilder} instance with no starting {@link #update}
* Returns the final/built {@link Bson update}
*
* @return the final/built {@link Bson update}
*
* @throws IllegalStateException if the {@link #update} is null (only ever happens if {@link UpdateBuilder the builder} is created with no starting {@link #update})
*/
public UpdateBuilder() {}
@NotNull
public Bson build() {
if (update == null) throw new IllegalStateException("update cannot be null");
return update;
}

/**
* Combines the given {@link Bson update} with the current {@link #update}
Expand All @@ -72,17 +85,4 @@ public UpdateBuilder add(@NotNull Bson newUpdate) {
update = Updates.combine(update, newUpdate);
return this;
}

/**
* Returns the final/built {@link Bson update}
*
* @return the final/built {@link Bson update}
*
* @throws IllegalStateException if the {@link #update} is null (only ever happens if {@link UpdateBuilder the builder} is created with no starting {@link #update})
*/
@NotNull
public Bson build() {
if (update == null) throw new IllegalStateException("update cannot be null");
return update;
}
}

0 comments on commit 4d2689d

Please sign in to comment.