From 23383b91aa42f7a788cc66bf3c9e492088bf27ee Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 16:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fanruan/api/data/TableDataKit.java | 35 +++++++++++++++++-- .../fanruan/api/data/TableDataKitTest.java | 19 ++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/fanruan/api/data/TableDataKit.java b/src/main/java/com/fanruan/api/data/TableDataKit.java index 6039b01..333245f 100644 --- a/src/main/java/com/fanruan/api/data/TableDataKit.java +++ b/src/main/java/com/fanruan/api/data/TableDataKit.java @@ -3,11 +3,15 @@ package com.fanruan.api.data; import com.fr.base.TableData; import com.fr.data.TableDataSource; import com.fr.data.api.TableDataAssist; +import com.fr.file.TableDataConfig; import com.fr.script.Calculator; import com.fr.stable.script.CalculatorProvider; +import com.fr.third.guava.collect.Maps; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Map; + /** * @author richie * @version 10.0 @@ -26,7 +30,7 @@ public class TableDataKit { * @param name 数据集名字 * @return 数据集 */ - public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, String name) { + public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, @NotNull String name) { return TableDataAssist.getTableData((Calculator) cal, name); } @@ -40,7 +44,34 @@ public class TableDataKit { * @param name 数据集名字 * @return 数据集 */ - public static @Nullable TableData getTableData(@NotNull TableDataSource source, String name) { + public static @Nullable TableData getTableData(@NotNull TableDataSource source, @NotNull String name) { return TableDataAssist.getTableData(source, name); } + + /** + * 获取所有的服务器数据集 + * @return 所有的服务器数据集组成的键值对集合 + */ + public static @NotNull Map getAllServerTableData() { + Map 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); + } } diff --git a/src/test/java/com/fanruan/api/data/TableDataKitTest.java b/src/test/java/com/fanruan/api/data/TableDataKitTest.java index f898f40..cb8e78f 100644 --- a/src/test/java/com/fanruan/api/data/TableDataKitTest.java +++ b/src/test/java/com/fanruan/api/data/TableDataKitTest.java @@ -2,13 +2,10 @@ package com.fanruan.api.data; import com.fanruan.api.Prepare; import com.fr.base.TableData; -import com.fr.config.Configuration; import com.fr.data.TableDataSource; import com.fr.file.TableDataConfig; import com.fr.main.impl.WorkBook; import com.fr.script.Calculator; -import com.fr.transaction.Configurations; -import com.fr.transaction.Worker; import org.junit.Assert; import org.junit.Test; @@ -22,17 +19,7 @@ public class TableDataKitTest extends Prepare { @Test public void getTableData() { TestTD td = new TestTD(); - Configurations.update(new Worker() { - @Override - public void run() { - TableDataConfig.getInstance().addTableData("first", td); - } - - @Override - public Class[] targets() { - return new Class[]{TableDataConfig.class}; - } - }); + TableDataConfig.getInstance().addTableData("first", td); Calculator calculator = Calculator.createCalculator(); calculator.setAttribute(TableDataSource.KEY, new WorkBook()); TableData r = TableDataKit.getTableData(calculator, "first"); @@ -42,11 +29,9 @@ public class TableDataKitTest extends Prepare { @Test public void testGetTableData() { TestTD td = new TestTD(); - Calculator calculator = Calculator.createCalculator(); WorkBook workBook = new WorkBook(); workBook.putTableData("test", td); - calculator.setAttribute(TableDataSource.KEY, workBook); - TableData r = TableDataKit.getTableData(calculator, "test"); + TableData r = TableDataKit.getTableData(workBook, "test"); Assert.assertEquals(td, r); }