From 52a3ec63a0f310e5fa45251210ab11c88ed0dffe Mon Sep 17 00:00:00 2001 From: inter Date: Thu, 4 Sep 2025 14:09:02 +0800 Subject: [PATCH] Add File --- .../easyai/randomForest/DataTable.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/main/java/org/dromara/easyai/randomForest/DataTable.java diff --git a/src/main/java/org/dromara/easyai/randomForest/DataTable.java b/src/main/java/org/dromara/easyai/randomForest/DataTable.java new file mode 100644 index 0000000..e5c7abd --- /dev/null +++ b/src/main/java/org/dromara/easyai/randomForest/DataTable.java @@ -0,0 +1,79 @@ +package org.dromara.easyai.randomForest; + + +import java.lang.reflect.Method; +import java.util.*; + +/** + * @author lidapeng + * @description 内存数据表 + * @date 3:48 下午 2020/2/17 + */ +public class DataTable {//数据表 + private final Map> table = new HashMap<>(); + private Set keyType;//表的属性 + private String key;//最终分类字段 + private int length; + + public String getKey() { + return key; + } + + public int getLength() { + return length; + } + + public int getSize() {//获取属性的数量 + return keyType.size(); + } + + public Map> getTable() { + return table; + } + + public Set getKeyType() { + return keyType; + } + + public void setKey(String key) throws Exception { + if (keyType.contains(key)) { + this.key = key; + } else { + throw new Exception("NOT FIND KEY"); + } + } + + public DataTable(Set key) throws Exception {//表的属性 + if (key != null) { + this.keyType = key; + for (String name : key) { + if (name == null) { + throw new Exception("属性列表中,有一个属性的值为null"); + } + table.put(name, new ArrayList<>()); + } + } else { + throw new Exception("属性列表为空"); + } + } + + public void insert(Object ob) { + try { + Class body = ob.getClass(); + length++; + for (String name : keyType) { + String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1); + Method method = body.getMethod(methodName); + Object dm = method.invoke(ob); + List list = table.get(name); + if (dm instanceof Integer) {//数据表只允许加入Integer类型数据 + list.add((int) dm); + } else { + throw new Exception("数据表只允许加入Integer类型数据"); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } +}