Skip to content

Commit 8d14349

Browse files
committed
getOrCreateDefaultContainer function
1 parent 187d9cd commit 8d14349

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/main/java/me/mrnavastar/sqlib/api/DataStore.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.NonNull;
66
import lombok.SneakyThrows;
77
import me.mrnavastar.sqlib.api.database.Database;
8+
import me.mrnavastar.sqlib.api.types.SQLibType;
89
import me.mrnavastar.sqlib.impl.SQLConnection;
910

1011
import java.util.*;
@@ -38,7 +39,7 @@ public String toString() {
3839
}
3940

4041
/**
41-
* Creates a new {@link DataContainer}
42+
* Creates a new {@link DataContainer} with a unique id.
4243
*/
4344
@SneakyThrows
4445
public DataContainer createContainer() {
@@ -89,6 +90,14 @@ public DataContainer getOrCreateContainer(@NonNull String field, @NonNull Object
8990
});
9091
}
9192

93+
/**
94+
* Tries to get a {@link DataContainer} with a matching key value pair or creates a new {@link DataContainer} with
95+
* a matching key value pair if it is missing.
96+
*/
97+
public <T> DataContainer getOrCreateDefaultContainer(@NonNull SQLibType<T> type, @NonNull String field, @NonNull T value) {
98+
return getOrCreateContainer(field, value, c -> c.put(type, field, value));
99+
}
100+
92101
/**
93102
* @return A {@link DataContainer}'s with a matching key value pair or null if one does not exist.
94103
*/

0 commit comments

Comments
 (0)