-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package xyz.srnyx.magicmongo; | ||
|
||
import com.mongodb.client.model.Updates; | ||
|
||
import org.bson.conversions.Bson; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class UpdateBuilder { | ||
@Nullable private Bson update; | ||
|
||
public UpdateBuilder(@NotNull Bson update) { | ||
this.update = update; | ||
} | ||
|
||
public UpdateBuilder(@NotNull Bson... updates) { | ||
update = Updates.combine(updates); | ||
} | ||
|
||
public UpdateBuilder(@NotNull List<Bson> updates) { | ||
update = Updates.combine(updates); | ||
} | ||
|
||
public UpdateBuilder(@NotNull UpdateBuilder updateBuilder) { | ||
this.update = updateBuilder.update; | ||
} | ||
|
||
public UpdateBuilder() {} | ||
|
||
@NotNull | ||
public UpdateBuilder add(@NotNull Bson newUpdate) { | ||
update = Updates.combine(update, newUpdate); | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public Bson build() { | ||
if (update == null) throw new IllegalStateException("update cannot be null"); | ||
return update; | ||
} | ||
} |