mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Add][Fix] 添加新的CacheStore子类型, 修复 CacheStoreFactory 方法命名错误;
[Fix] CacheStoreFactory 修复 newMapCacheStore():SingleCacheStore 方法命名错误(更名为 newSingleCacheStore); [Add] MapCacheStore 初步添加映射表型缓存存储容器接口; [Add] CacheStoreFactory 增加对 MapCacheStore 的获取方法;
This commit is contained in:
parent
372363085d
commit
a7495156ff
@ -33,7 +33,7 @@ public interface CacheStoreFactory {
|
||||
* @param converter 类型的转换器.
|
||||
* @return 返回 CacheStore 对象.
|
||||
*/
|
||||
<V> SingleCacheStore<V> newMapCacheStore(String identify, StringConverter<V> converter);
|
||||
<V> SingleCacheStore<V> newSingleCacheStore(String identify, StringConverter<V> converter);
|
||||
|
||||
/**
|
||||
* 获取一个新的有序列表缓存存储容器.
|
||||
@ -53,4 +53,12 @@ public interface CacheStoreFactory {
|
||||
*/
|
||||
<E> SetCacheStore<E> newSetCacheStore(String identify, StringConverter<E> converter);
|
||||
|
||||
/**
|
||||
* 获取一个新的映射表缓存存储容器.
|
||||
* @param identify 缓存标识
|
||||
* @param converter 字段值类型与 String 的转换器.
|
||||
* @param <V> 字段值类型.
|
||||
* @return 返回新的映射表缓存存储容器.
|
||||
*/
|
||||
<V> MapCacheStore<V> newMapCacheStore(String identify, StringConverter<V> converter);
|
||||
}
|
||||
|
129
ContentGrabbingJi-CacheStore-api/src/main/java/net/lamgc/cgj/bot/cache/MapCacheStore.java
vendored
Normal file
129
ContentGrabbingJi-CacheStore-api/src/main/java/net/lamgc/cgj/bot/cache/MapCacheStore.java
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2020 LamGC
|
||||
*
|
||||
* ContentGrabbingJi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* ContentGrabbingJi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.lamgc.cgj.bot.cache;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Map 缓存存储容器.
|
||||
* @author LamGC
|
||||
*/
|
||||
public interface MapCacheStore<V> extends CacheStore<Map<String, V>> {
|
||||
|
||||
/**
|
||||
* 获取 Map 字段数量.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @return 返回 Map 字段数量, 如果缓存项不存在或获取失败, 返回 -1.
|
||||
* @throws NullPointerException 当 key 为 null 时抛出.
|
||||
*/
|
||||
int mapSize(String key);
|
||||
|
||||
/**
|
||||
* 获取 Map 字段集合.
|
||||
* @param key 待查询的 Map 缓存项的键名.
|
||||
* @return 返回 Map 字段集合, 如果缓存项不存在, 返回 null.
|
||||
* @throws NullPointerException 当 key 为 null 时抛出.
|
||||
*/
|
||||
Set<String> mapFieldSet(String key);
|
||||
|
||||
/**
|
||||
* 获取 Map 字段值集合.
|
||||
* @param key 待查询的 Map 缓存项的键名.
|
||||
* @return 返回 Map 字段值集合, 如果缓存项不存在, 返回 null.
|
||||
* @throws NullPointerException 当 key 为 null 时抛出.
|
||||
*/
|
||||
Set<V> mapValueSet(String key);
|
||||
|
||||
/**
|
||||
* 将指定的值与此映射中的指定字段关联.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @param field 字段名.
|
||||
* @param value 字段值.
|
||||
* @return 如果成功返回 true.
|
||||
* @throws NullPointerException 当 key/field/value 为 null 时抛出, 缓存存储容器不允许出现 null 值.
|
||||
*/
|
||||
boolean put(String key, String field, V value);
|
||||
|
||||
/**
|
||||
* 添加一组字段.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @param map 待添加的 Map.
|
||||
* @return 如果成功返回 true.
|
||||
* @throws NullPointerException 当 key/map 为 null 时抛出, 缓存存储容器不允许出现 null 值.
|
||||
*/
|
||||
boolean putAll(String key, Map<String, V> map);
|
||||
|
||||
/**
|
||||
* 如果字段不存在, 则会将指定的值与此映射中的指定字段关联.
|
||||
*
|
||||
* <p>该方法与 {@link #put(String, String, Object)} 类似, 但如果字段存在, 将不会执行任何操作并以失败返回.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @param field 字段名.
|
||||
* @param value 字段值.
|
||||
* @return 如果字段不存在且设置成功, 返回 true, 否则返回 false.
|
||||
* @throws NullPointerException 当 key/field/value 为 null 时抛出, 缓存存储容器不允许出现 null 值.
|
||||
*/
|
||||
boolean putIfNotExist(String key, String field, V value);
|
||||
|
||||
/**
|
||||
* 获取指定字段的字段值.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @param field 字段名.
|
||||
* @return 如果 Map 缓存项存在且字段存在, 返回字段的对应值.
|
||||
* @throws NullPointerException 当 key/field 为 null 时抛出.
|
||||
*/
|
||||
V get(String key, String field);
|
||||
|
||||
/**
|
||||
* 删除 Map 中的指定字段.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @param field 待删除的字段名.
|
||||
* @return 如果 Map 缓存项存在, 字段存在并且删除成功, 返回 true.
|
||||
* @throws NullPointerException 当 key/field 为 null 时抛出.
|
||||
*/
|
||||
boolean removeField(String key, String field);
|
||||
|
||||
/**
|
||||
* 检查 Map 中是否有指定字段.
|
||||
* @param key Map 缓存项的键名.
|
||||
* @param field 待检查的字段名.
|
||||
* @return 如果 Map 缓存项存在且字段存在, 返回 true.
|
||||
* @throws NullPointerException 当 key/field 为 null 时抛出.
|
||||
*/
|
||||
boolean containsField(String key, String field);
|
||||
|
||||
/**
|
||||
* 检查 Map 是否为空(没有任何字段).
|
||||
*
|
||||
* <p>该方法等价于 {@code mapSize(key) == 0}
|
||||
* @param key Map 缓存项的键名.
|
||||
* @return 如果 Map 缓存项存在且为空, 返回 true.
|
||||
* @throws NullPointerException 当 key 为 null 时抛出.
|
||||
*/
|
||||
boolean mapIsEmpty(String key);
|
||||
|
||||
/**
|
||||
* 清空 Map 中的所有字段(并不会删除 Map 缓存项).
|
||||
* @param key 待清空的 Map 缓存项键名.
|
||||
* @return 如果存在且清空成功, 返回 true.
|
||||
* @throws NullPointerException 当 key 为 null 时抛出.
|
||||
*/
|
||||
boolean clearMap(String key);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user