Package com.ptsmods.mysqlw.collection
Class DbMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
com.ptsmods.mysqlw.collection.DbMap<K,V>
- All Implemented Interfaces:
DbCollection
,Map<K,
V>
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) containsKeyAsync
(Object key) boolean
containsValue
(Object value) containsValueAsync
(Object value) entrySet()
@NotNull CompletableFuture<Set<Map.Entry<K,
V>>> @NotNull Database
getDb()
@NotNull BiFunction<String,
DbCollection, K> @NotNull BiFunction<K,
DbCollection, String> static <K,
V> DbMap<K, V> getMap
(@NotNull Database db, @NotNull String name, @NotNull BiFunction<K, DbCollection, String> keyToString, @NotNull BiFunction<V, DbCollection, String> valueToString, @NotNull BiFunction<String, DbCollection, K> keyFromString, @NotNull BiFunction<String, DbCollection, V> valueFromString) Gets a map from cache or creates a new one.static <K,
V> DbMap<K, V> Gets a map from cache or creates a new one.getName()
@NotNull String
getTable()
@NotNull BiFunction<String,
DbCollection, V> @NotNull BiFunction<V,
DbCollection, String> boolean
isEmpty()
keySet()
@NotNull CompletableFuture<Set<K>>
static <K,
V> DbMap<K, V> parseString
(Database db, String s, BiFunction<K, DbCollection, String> keyToString, BiFunction<V, DbCollection, String> valueToString, BiFunction<String, DbCollection, K> keyFromString, BiFunction<String, DbCollection, V> valueFromString) Parses a String representation of a DbMap into a DbMap.void
putAllAsync
(@NotNull Map<? extends K, ? extends V> m) @Nullable CompletableFuture<V>
removeAsync
(Object key) <T> CompletableFuture<T>
void
setExecutor
(Executor executor) int
size()
toString()
@NotNull Collection<V>
values()
@NotNull CompletableFuture<Collection<V>>
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
parseString
public static <K,V> DbMap<K,V> parseString(Database db, String s, BiFunction<K, DbCollection, String> keyToString, BiFunction<V, DbCollection, String> valueToString, BiFunction<String, DbCollection, K> keyFromString, BiFunction<String, DbCollection, V> valueFromString) Parses a String representation of a DbMap into a DbMap.- Type Parameters:
K
- The key type of this map.V
- The value type of this map.- Parameters:
db
- The database this map belongs to. Used when creating a new map.s
- The String to parse.keyToString
- The function used to convert a key object of this map into a String. Used when creating a new map.valueToString
- The function used to convert a value object of this map into a String. Used when creating a new map.keyFromString
- The function used to convert a String into a key object of this map. Used when creating a new map.valueFromString
- The function used to convert a String into a value object of this map. Used when creating a new map.- Returns:
- A new DbMap or a cached one if available.
-
getMap
public static <K,V> DbMap<K,V> getMap(Database db, String name, Class<K> keyType, Class<V> valueType) Gets a map from cache or creates a new one.- Type Parameters:
K
- The type of the keys in this map.V
- The type of the values in this map.- Parameters:
db
- The database this map belongs to. Used when creating a new map.name
- The name of this map.keyType
- The class of the type of the keys in this map, registered atDbCF
. Used when creating a new map.valueType
- The class of the type of the values in this map, registered atDbCF
. Used when creating a new map.- Returns:
- A new DbMap or a cached one if available.
-
getMap
public static <K,V> DbMap<K,V> getMap(@NotNull @NotNull Database db, @NotNull @NotNull String name, @NotNull @NotNull BiFunction<K, DbCollection, String> keyToString, @NotNull @NotNull BiFunction<V, DbCollection, String> valueToString, @NotNull @NotNull BiFunction<String, DbCollection, K> keyFromString, @NotNull @NotNull BiFunction<String, DbCollection, V> valueFromString) Gets a map from cache or creates a new one.- Type Parameters:
K
- The type of the keys in this map.V
- The type of the values in this map.- Parameters:
db
- The database this map belongs to. Used when creating a new map.name
- The name of this map.keyToString
- The function used to convert a key object of this map into a String. Used when creating a new map.valueToString
- The function used to convert a value object of this map into a String. Used when creating a new map.keyFromString
- The function used to convert a String into a key object of this map. Used when creating a new map.valueFromString
- The function used to convert a String into a value object of this map. Used when creating a new map.- Returns:
- A new DbMap or a cached one if available.
-
setExecutor
-
getExecutor
-
runAsync
-
runAsync
-
size
public int size() -
sizeAsync
-
isEmpty
public boolean isEmpty() -
isEmptyAsync
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
containsKeyAsync
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classAbstractMap<K,
V>
-
containsValueAsync
-
get
-
getAsync
-
put
-
putAsync
-
remove
-
removeAsync
-
putAll
-
putAllAsync
-
clear
public void clear() -
clearAsync
-
keySet
-
keySetAsync
-
values
-
valuesAsync
-
entrySet
-
entrySetAsync
-
toString
- Overrides:
toString
in classAbstractMap<K,
V>
-
getDb
- Specified by:
getDb
in interfaceDbCollection
- Returns:
- The database this collection works with.
-
getTable
- Specified by:
getTable
in interfaceDbCollection
- Returns:
- The table this collection works with.
-
getName
- Specified by:
getName
in interfaceDbCollection
- Returns:
- The name of this collection. Used to cache and parse from Strings.
-
getKeyToString
-
getValueToString
-
getKeyFromString
-
getValueFromString
-