Skip to content

Commit

Permalink
getOrCreateDefaultContainer function
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Nov 26, 2024
1 parent 187d9cd commit 8d14349
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/api/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.NonNull;
import lombok.SneakyThrows;
import me.mrnavastar.sqlib.api.database.Database;
import me.mrnavastar.sqlib.api.types.SQLibType;
import me.mrnavastar.sqlib.impl.SQLConnection;

import java.util.*;
Expand Down Expand Up @@ -38,7 +39,7 @@ public String toString() {
}

/**
* Creates a new {@link DataContainer}
* Creates a new {@link DataContainer} with a unique id.
*/
@SneakyThrows
public DataContainer createContainer() {
Expand Down Expand Up @@ -89,6 +90,14 @@ public DataContainer getOrCreateContainer(@NonNull String field, @NonNull Object
});
}

/**
* Tries to get a {@link DataContainer} with a matching key value pair or creates a new {@link DataContainer} with
* a matching key value pair if it is missing.
*/
public <T> DataContainer getOrCreateDefaultContainer(@NonNull SQLibType<T> type, @NonNull String field, @NonNull T value) {
return getOrCreateContainer(field, value, c -> c.put(type, field, value));
}

/**
* @return A {@link DataContainer}'s with a matching key value pair or null if one does not exist.
*/
Expand Down

0 comments on commit 8d14349

Please sign in to comment.