From b779d4d734954d7a7d952208684c21e3af400c58 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Tue, 27 Aug 2019 14:17:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=80=E4=BA=9B=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fanruan/api/cal/ParameterKit.java | 22 +++++- .../com/fanruan/api/design/DesignKit.java | 73 +++++++++++++++++++ .../java/com/fanruan/api/i18n/I18nKit.java | 14 ++++ .../com/fanruan/api/layout/LayoutKit.java | 7 ++ .../com/fanruan/api/security/SecurityKit.java | 18 +++++ .../java/com/fanruan/api/util/GeneralKit.java | 45 ++++++++++++ src/main/java/com/fanruan/api/util/IOKit.java | 12 +++ src/main/java/com/fanruan/api/xml/XmlKit.java | 33 +++++++++ .../com/fanruan/api/util/GeneralKitTest.java | 19 +++++ 9 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/fanruan/api/design/DesignKit.java create mode 100644 src/main/java/com/fanruan/api/i18n/I18nKit.java create mode 100644 src/main/java/com/fanruan/api/layout/LayoutKit.java create mode 100644 src/main/java/com/fanruan/api/xml/XmlKit.java diff --git a/src/main/java/com/fanruan/api/cal/ParameterKit.java b/src/main/java/com/fanruan/api/cal/ParameterKit.java index d3ce791..1c2717a 100644 --- a/src/main/java/com/fanruan/api/cal/ParameterKit.java +++ b/src/main/java/com/fanruan/api/cal/ParameterKit.java @@ -2,6 +2,7 @@ package com.fanruan.api.cal; import com.fr.base.ParameterHelper; import com.fr.base.ParameterMapNameSpace; +import com.fr.script.CalculatorMap; import com.fr.stable.ParameterProvider; import com.fr.stable.script.NameSpace; import org.jetbrains.annotations.NotNull; @@ -14,8 +15,7 @@ import java.util.Map; * Created by richie on 2019-08-16 * 参数相关的工具类 */ -public class ParameterKit { - +public class ParameterKit{ /** * 分析公式中所携带的参数 * @param text 公式内容 @@ -24,6 +24,15 @@ public class ParameterKit { public static @NotNull ParameterProvider[] analyze4ParametersFromFormula(String text) { return ParameterHelper.analyze4ParametersFromFormula(text); } + /** + * 分析一组字符串中的参数 + * @param paramTexts 字符串组 + * @param isFormula 是否是公式类型的字符串数组 + * @return 参数集合 + */ + public static @NotNull ParameterProvider[] analyze4Parameters(String[] paramTexts, boolean isFormula) { + return ParameterHelper.analyze4Parameters(paramTexts, isFormula); + } /** * 创建一个用于计算的参数对名字空间 @@ -33,4 +42,13 @@ public class ParameterKit { public static @NotNull NameSpace createParameterMapNameSpace(Map map) { return ParameterMapNameSpace.create(map); } + /** + * 创建一个用于计算的参数对名字空间 + * @param ps ParameterProvider的数组 + * @return 名字空间,用于传递给算子做计算 + */ + + public static @NotNull ParameterMapNameSpace createParameterProvider(ParameterProvider[] ps) { + return ParameterMapNameSpace.create(ps); + } } diff --git a/src/main/java/com/fanruan/api/design/DesignKit.java b/src/main/java/com/fanruan/api/design/DesignKit.java new file mode 100644 index 0000000..212a761 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/DesignKit.java @@ -0,0 +1,73 @@ +package com.fanruan.api.design; +import com.fr.base.TableData; +import com.fr.design.data.datapane.preview.PreviewTablePane; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.gui.itextfield.UIIntNumberField; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class DesignKit { + public static class UpdateAction extends com.fr.design.actions.UpdateAction{ + @Override + public void actionPerformed(ActionEvent evt) {} + } + /** + * 直接预览数据集,没有实际值及显示值 + * @param tableData 数据集 + */ + public static void previewTableData(TableData tableData){ + PreviewTablePane.previewTableData(tableData, -1, -1); + } + public static class ParameterTableModel extends com.fr.design.gui.itableeditorpane.ParameterTableModel{ + + } + public static class UITableEditAction extends com.fr.design.gui.itableeditorpane.UITableEditAction{ + @Override + public void checkEnabled() { + } + @Override + public void actionPerformed(ActionEvent e) { + + } + + } + public static class BasicPane extends com.fr.design.dialog.BasicPane{ + @Override + protected String title4PopupWindow() { + return ""; + } + } + /** + * 标题布局 + * @param components 组件 + * @param rowSize 行宽 + * @param columnSize 列宽 + * @return 布局后的组件 + */ + public static JPanel createTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize) { + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + /** + * 生成一个边界布局 + * @param args 布局内部的元素,位置等 + * @return 具有边界布局的面板 + */ + public static JPanel createBorderLayoutPane(Object... args) { + return GUICoreUtils.createBorderLayoutPane(args); + } + /** + * 产生一个Flow Pane, flowAligment是FlowLayout.LEFT, CENTER, RIGHT. + * @param comps 组件 + * @param flowAlignment 对齐方式 + * @return 具有边界布局的面板 + */ + public static JPanel createFlowPane(Component comps, int flowAlignment) { + return GUICoreUtils.createFlowPane(comps,flowAlignment); + } + public static class UIIntNumberField extends com.fr.design.gui.itextfield.UIIntNumberField{ + + } +} diff --git a/src/main/java/com/fanruan/api/i18n/I18nKit.java b/src/main/java/com/fanruan/api/i18n/I18nKit.java new file mode 100644 index 0000000..a2f3cb1 --- /dev/null +++ b/src/main/java/com/fanruan/api/i18n/I18nKit.java @@ -0,0 +1,14 @@ +package com.fanruan.api.i18n; +import com.fr.locale.InterProviderFactory; + +public class I18nKit { + /** + * 获取国际化文本 + * + * @param string 需要国际化的值对应的键 + * @return 返回国际化文本 + */ + public static String getLocText(String string) { + return InterProviderFactory.getProvider().getLocText(string); + } +} diff --git a/src/main/java/com/fanruan/api/layout/LayoutKit.java b/src/main/java/com/fanruan/api/layout/LayoutKit.java new file mode 100644 index 0000000..b1e4ba5 --- /dev/null +++ b/src/main/java/com/fanruan/api/layout/LayoutKit.java @@ -0,0 +1,7 @@ +package com.fanruan.api.layout; +import com.fr.design.layout.TableLayout; + +public class LayoutKit { + public static final double PREFERRED = TableLayout.PREFERRED; + public static final double FILL = TableLayout.FILL; +} diff --git a/src/main/java/com/fanruan/api/security/SecurityKit.java b/src/main/java/com/fanruan/api/security/SecurityKit.java index 517182b..5a72db1 100644 --- a/src/main/java/com/fanruan/api/security/SecurityKit.java +++ b/src/main/java/com/fanruan/api/security/SecurityKit.java @@ -1,5 +1,7 @@ package com.fanruan.api.security; +import com.fr.security.SecurityToolbox; + /** * @author richie * @version 10.0 @@ -7,4 +9,20 @@ package com.fanruan.api.security; * 文本加密解密相关的工具类 */ public class SecurityKit { + /** + * RSA加密 + * @param plainText 要加密的文本内容 + * @return 加密后的内容 + */ + public static String encrypt(String plainText) { + return SecurityToolbox.encrypt(plainText); + } + /** + * RSA解密 + * @param cipherText 密文数据 + * @return 解密后的内容 + */ + public static String decrypt(String cipherText) { + return SecurityToolbox.decrypt(cipherText); + } } diff --git a/src/main/java/com/fanruan/api/util/GeneralKit.java b/src/main/java/com/fanruan/api/util/GeneralKit.java index 7b69760..5e3b64b 100644 --- a/src/main/java/com/fanruan/api/util/GeneralKit.java +++ b/src/main/java/com/fanruan/api/util/GeneralKit.java @@ -1,10 +1,14 @@ package com.fanruan.api.util; import com.fr.general.GeneralUtils; +import com.fr.stable.StableUtils; +import com.fr.base.TemplateUtils; +import com.fr.third.guava.base.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; +import java.util.Map; /** * @author richie @@ -12,6 +16,47 @@ import java.io.IOException; * Created by richie on 2019-08-09 */ public class GeneralKit { + /** + * 根据参数来计算文档字符串 + * @param query 文档来源 + * @param map 参数map + * @return 计算后结果 + */ + public static String renderParameter4Tpl(String query, Map map) throws Exception { + return TemplateUtils.renderParameter4Tpl(query, map); + } + /** + * 返回多个属性合并计算的哈希值 + * @param args 对象列表 + * @return 哈希值 + */ + public static int hashCode(Object... args) { + return Objects.hashCode(args); + } + /** + * 判断两个对象是否相等 + * @param source 对象1 + * @param des 对象2 + * @return 如果两个对象相等,则返回true,否则返回false + */ + public static boolean equals(Object source, Object des) { + if (source == null && des == null) { + return true; + } else if (source == null) { + return false; + } else { + return source!=null && source.equals(des); + } + } + /** + * 判断指定的类是否是另一个类的子类 + * @param childClass 指定的类 + * @param parentClass 另一个类 + * @return 如果指定类是另一个类的子类则返回true,否则返回false + */ + public static boolean classInstanceOf(Class childClass, Class parentClass) { + return StableUtils.classInstanceOf(childClass, parentClass); + } /** * 返回系统的首选MAC地址 diff --git a/src/main/java/com/fanruan/api/util/IOKit.java b/src/main/java/com/fanruan/api/util/IOKit.java index 9ee5efa..5b223e7 100644 --- a/src/main/java/com/fanruan/api/util/IOKit.java +++ b/src/main/java/com/fanruan/api/util/IOKit.java @@ -2,6 +2,7 @@ package com.fanruan.api.util; import com.fr.general.CommonIOUtils; import com.fr.general.IOUtils; +import com.fr.io.utils.ResourceIOUtils; import javax.swing.*; import java.awt.image.BufferedImage; @@ -21,6 +22,17 @@ import java.nio.charset.Charset; * Created by richie on 2019-08-16 */ public class IOKit { + /** + * 读取文件到流 + * 相对路径下如果是仓库资源从仓库读取,其它从本地读取 + * 据对路径按绝对路径读 + * + * @param path 路径 + * @return 流 + */ + public static InputStream read(String path) { + return ResourceIOUtils.read(path); + } /** * 重命名指定的文件为另外一个文件.(不抛异常) diff --git a/src/main/java/com/fanruan/api/xml/XmlKit.java b/src/main/java/com/fanruan/api/xml/XmlKit.java new file mode 100644 index 0000000..bea0a76 --- /dev/null +++ b/src/main/java/com/fanruan/api/xml/XmlKit.java @@ -0,0 +1,33 @@ +package com.fanruan.api.xml; + +import com.fr.stable.xml.XMLReadable; +import com.fr.stable.xml.XMLTools; +import com.fr.stable.xml.XMLableReader; +import com.fr.stable.xml.XMLPrintWriter; + +import java.io.InputStream; + +public class XmlKit { + /** + * 从输入流中读取对象 + * @param xmlReadable xml读取对象 + * @param inputStream xml输入流 + * + */ + public static class XMLFileManager extends com.fr.file.XMLFileManager { + @Override + public String fileName() { + return ""; + } + @Override + public void writeXML(XMLPrintWriter writer) { + + } + @Override + public void readXML(XMLableReader reader) { + } + } + public static void readInputStreamXML(XMLReadable xmlReadable, InputStream inputStream) throws Exception { + XMLTools.readInputStreamXML(xmlReadable, inputStream); + } +} diff --git a/src/test/java/com/fanruan/api/util/GeneralKitTest.java b/src/test/java/com/fanruan/api/util/GeneralKitTest.java index cbead61..b0fd425 100644 --- a/src/test/java/com/fanruan/api/util/GeneralKitTest.java +++ b/src/test/java/com/fanruan/api/util/GeneralKitTest.java @@ -1,6 +1,7 @@ package com.fanruan.api.util; import com.fanruan.api.Prepare; +import com.fr.third.guava.base.Objects; import org.junit.Assert; import org.junit.Test; @@ -15,4 +16,22 @@ public class GeneralKitTest extends Prepare { public void getMacAddress() throws Exception{ Assert.assertEquals(GeneralKit.getMacAddress(), com.fr.general.GeneralUtils.getMacAddress()); } + + @Test + public void equals() throws Exception{ + Integer x = 5; + Integer y = 10; + Integer z =5; + Short a = 5; + Assert.assertEquals(GeneralKit.equals(x, y), false); + Assert.assertEquals(GeneralKit.equals(x, z), true); + Assert.assertEquals(GeneralKit.equals(z, a), false); + } + + @Test + public void hashCodes(){ + class A{}; + Object a = new A(); + Assert.assertEquals(GeneralKit.hashCode(a), Objects.hashCode(a)); + } } \ No newline at end of file