From 19ceff456bf2e559c884c3cbc453f249713b9321 Mon Sep 17 00:00:00 2001 From: fujie <405295521@qq.com> Date: Mon, 13 Nov 2017 20:43:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=8F=E8=A1=A8=E9=9B=86?= =?UTF-8?q?=E5=90=88=E8=BF=90=E7=AE=97=EF=BC=88=E7=8E=B0=E8=A6=81=E6=B1=82?= =?UTF-8?q?=E5=BA=8F=E8=A1=A8B=E5=AD=97=E6=AE=B5=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=BA=8F=E8=A1=A8A=E7=9A=84=E5=AD=97=E6=AE=B5,=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=BB=A5=E5=BA=8F=E8=A1=A8A=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BA=E5=87=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractDataSetOperateFunction.java | 22 +++++++++---------- .../function/DataSetIntersectionFunction.java | 2 +- .../function/DataSetSubtractFunction.java | 2 +- .../function/DataSetUnionFunction.java | 4 ++-- .../dataset/function/DataSetXorFunction.java | 2 +- .../tinyscript/dataset/util/DataSetUtil.java | 8 ++----- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/AbstractDataSetOperateFunction.java b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/AbstractDataSetOperateFunction.java index 09e129d..188b0d1 100644 --- a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/AbstractDataSetOperateFunction.java +++ b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/AbstractDataSetOperateFunction.java @@ -76,7 +76,8 @@ public abstract class AbstractDataSetOperateFunction extends AbstractScriptFunct ScriptContext subContext = new DefaultScriptContext(); subContext.setParent(context); for (int i = 0; i < dataSet.getFields().size(); i++) { - subContext.put(dataSet.getFields().get(i).getName(), dataSet.getData(row, dataSet.getShowIndex(i))); + subContext.put(dataSet.getFields().get(i).getName(), + dataSet.getData(dataSet.getShowIndex(row), dataSet.getShowIndex(i))); } return keyFunction.execute(subContext).getResult().toString(); @@ -93,19 +94,16 @@ public abstract class AbstractDataSetOperateFunction extends AbstractScriptFunct * @throws Exception */ protected boolean checkField(DataSet dataSet1, DataSet dataSet2) throws Exception { - if (dataSet1.getColumns() != dataSet2.getColumns()) { - return false; - } else { - Set fields = new HashSet(); - for (int i = 0; i < dataSet1.getFields().size(); i++) { - fields.add(dataSet1.getFields().get(i)); - } - for (int i = 0; i < dataSet2.getFields().size(); i++) { - if (!fields.contains(dataSet2.getFields().get(i))) { - return false; - } + Set fields = new HashSet(); + for (int i = 0; i < dataSet2.getFields().size(); i++) { + fields.add(dataSet2.getFields().get(i)); + } + for (int i = 0; i < dataSet1.getFields().size(); i++) { + if (!fields.contains(dataSet1.getFields().get(i))) { + return false; } } + return true; } diff --git a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetIntersectionFunction.java b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetIntersectionFunction.java index 329d912..74d7dc7 100644 --- a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetIntersectionFunction.java +++ b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetIntersectionFunction.java @@ -69,7 +69,7 @@ public class DataSetIntersectionFunction extends AbstractDataSetOperateFunction newMap.put(key, map.get(key)); } } - return DataSetUtil.createDynamicDataSet(newMap); + return DataSetUtil.createDynamicDataSet(newMap, dataSet1.getFields()); } } diff --git a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetSubtractFunction.java b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetSubtractFunction.java index 091eaf6..ce346a4 100644 --- a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetSubtractFunction.java +++ b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetSubtractFunction.java @@ -56,7 +56,7 @@ public class DataSetSubtractFunction extends AbstractDataSetOperateFunction { map.remove(key); } } - return DataSetUtil.createDynamicDataSet(map); + return DataSetUtil.createDynamicDataSet(map, dataSet1.getFields()); } } diff --git a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetUnionFunction.java b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetUnionFunction.java index ae0daba..d61bc5a 100644 --- a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetUnionFunction.java +++ b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetUnionFunction.java @@ -54,10 +54,10 @@ public class DataSetUnionFunction extends AbstractDataSetOperateFunction { Map map = createMapDataSetRows(dataSet1, pks, context); for (int i = 0; i < dataSet2.getRows(); i++) { String key = createRowKey(dataSet2, pks, i, context); - DataSetRow row = new DefaultDataSetRow(dataSet2, i); + DataSetRow row = new DefaultDataSetRow(dataSet2, dataSet2.getShowIndex(i)); map.put(key, row); } - return DataSetUtil.createDynamicDataSet(map); + return DataSetUtil.createDynamicDataSet(map, dataSet1.getFields()); } } diff --git a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetXorFunction.java b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetXorFunction.java index d2aec6b..05c6e3a 100644 --- a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetXorFunction.java +++ b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/function/DataSetXorFunction.java @@ -60,7 +60,7 @@ public class DataSetXorFunction extends AbstractDataSetOperateFunction { } } newMap.putAll(map); - return DataSetUtil.createDynamicDataSet(newMap); + return DataSetUtil.createDynamicDataSet(newMap,dataSet1.getFields()); } } diff --git a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/util/DataSetUtil.java b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/util/DataSetUtil.java index 1ff65b6..8930664 100644 --- a/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/util/DataSetUtil.java +++ b/org.tinygroup.tinyscript.dataset/src/main/java/org/tinygroup/tinyscript/dataset/util/DataSetUtil.java @@ -55,8 +55,8 @@ public final class DataSetUtil { * @return * @throws Exception */ - public static DynamicDataSet createDynamicDataSet(Map map) throws Exception { - List fields = null; + public static DynamicDataSet createDynamicDataSet(Map map, List fields) + throws Exception { Object[][] data = new Object[map.keySet().size()][]; int rowId = 0; boolean isIndexFromOne = false; @@ -64,10 +64,6 @@ public final class DataSetUtil { for (String key : map.keySet()) { DataSetRow row = map.get(key); isIndexFromOne = row.isIndexFromOne(); - if (fields == null) { - fields = row.getFields(); - } - data[rowId] = new Object[fields.size()]; for (int i = 0; i < fields.size(); i++) { data[rowId][i] = row.getData(isIndexFromOne ? i + 1 : i); -- Gitee