插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7 KiB

package com.fanruan.api.data;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import com.fr.data.api.TableDataAssist;
5 years ago
import com.fr.file.TableDataConfig;
import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider;
5 years ago
import com.fr.third.guava.collect.Maps;
import org.jetbrains.annotations.NotNull;
5 years ago
import org.jetbrains.annotations.Nullable;
5 years ago
import java.util.Map;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-09
* 数据集获取工具类
*/
public class TableDataKit {
/**
* 根据名字获取数据集
* 根据以下步骤获取数据集
* 1先查询当前模板是否具有该名字的数据集如果有则返回如果没有则进行第二步
* 2再查询服务器数据集配置是否具有该名字的服务器数据集如果有则返回如果没有则返回null
*
* @param cal 算子
* @param name 数据集名字
* @return 数据集
*/
5 years ago
public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, @NotNull String name) {
return TableDataAssist.getTableData((Calculator) cal, name);
}
/**
* 根据名字获取数据集
* 根据以下步骤获取数据集
* 1先查询当前模板是否具有该名字的数据集如果有则返回如果没有则进行第二步
* 2再查询服务器数据集配置是否具有该名字的服务器数据集如果有则返回如果没有则返回null
*
* @param source 模板
* @param name 数据集名字
* @return 数据集
*/
5 years ago
public static @Nullable TableData getTableData(@NotNull TableDataSource source, @NotNull String name) {
return TableDataAssist.getTableData(source, name);
}
5 years ago
/**
* 获取所有的服务器数据集
* @return 所有的服务器数据集组成的键值对集合
*/
public static @NotNull Map<String, TableData> getAllServerTableData() {
Map<String, TableData> maps = TableDataConfig.getInstance().getTableDatas();
return Maps.newHashMap(maps);
}
/**
* 根据名字获取服务器数据集
* @param name 待查找的服务器数据集的名字
* @return 服务器数据集如果没有这个名字的服务器数据集则返回null
*/
public static @Nullable TableData findTableData(@NotNull String name) {
return TableDataConfig.getInstance().getTableData(name);
}
/**
* 重命名数据集
* @param oldName 原来的名字
* @param newName 新名字
*/
public static void renameTableData(@NotNull String oldName, @NotNull String newName) {
TableDataConfig.getInstance().renameTableData(oldName, newName);
}
}