544245
parent
202811aa8f
commit
7ead7b67a4
|
@ -1,11 +1,12 @@
|
|||
package com.muyu.rule.common.engine;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.etl.domain.DataValue;
|
||||
import com.muyu.rule.common.basic.abstracts.DataEngineDataSetActuator;
|
||||
import com.muyu.rule.common.domain.DataValueRows;
|
||||
import com.muyu.rule.common.exception.DeliteException;
|
||||
import com.muyu.rule.common.utils.ArrayUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -20,16 +21,18 @@ public class ENGINE_DataSet_asdf_S1 extends DataEngineDataSetActuator {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
DataValueRows dataValueRows = get();
|
||||
DataValue[][] dataValues = dataValueRows.getDataValue();
|
||||
String key = dataValueRows.getKey();
|
||||
JSONObject jsonObject = JSON.parseObject(key);
|
||||
String o = (String) jsonObject.get(key);
|
||||
if (dataValues == null || "".equals(dataValues) || "null".equals(dataValues)) {
|
||||
throw new DeliteException();
|
||||
}else {
|
||||
System.out.println("数据检测无异常");
|
||||
DataValue[][] dataValue = dataValueRows.getDataValue();
|
||||
ArrayUtil<DataValue[]> arrayUtil = new ArrayUtil<>(dataValue);
|
||||
while (arrayUtil.hasNext()) {
|
||||
DataValue[] dataStructures = arrayUtil.next();
|
||||
List<DataValue> dataStructureList = Arrays.stream(dataStructures).filter(dataStructure -> dataStructure.getKey().equals("name") && dataStructure.getValue() == null).toList();
|
||||
if (dataStructureList.size() > 0) {
|
||||
arrayUtil.remove();
|
||||
}
|
||||
}
|
||||
DataValue[][] currentArray = arrayUtil.getCurrentArray();
|
||||
dataValueRows.setDataValue(currentArray);
|
||||
set(dataValueRows);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ public class ENGINE_ROW_HANG_R1 extends DataEngineRowActuator {
|
|||
DataValueRow dataValueRow = get();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package com.muyu.rule.common.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.etl.domain.DataValue;
|
||||
import com.muyu.etl.enums.DataType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.common.utils
|
||||
* @Project:cloud-etl-rule
|
||||
* @name: 数组压栈工具
|
||||
* @Date:2024/9/10 14:46
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Log4j2
|
||||
public class ArrayUtil<T> implements Iterator<T> {
|
||||
|
||||
|
||||
private final T[] originalArray; // 原始数组
|
||||
private T[] currentArray; // 当前数组,用于迭代
|
||||
private int currentIndex; // 当前索引
|
||||
private int lastReturnedIndex; // 上一次调用next()方法时返回的索引
|
||||
private boolean canRemove = false; // 标记是否可以移除元素
|
||||
|
||||
public ArrayUtil(T[] array) {
|
||||
this.originalArray = array;
|
||||
this.currentArray = Arrays.copyOf(array, array.length);
|
||||
this.currentIndex = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < currentArray.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (!hasNext()) {
|
||||
throw new IllegalStateException("No more elements");
|
||||
}
|
||||
lastReturnedIndex = currentIndex;
|
||||
canRemove = true; // 调用next()后可以调用remove()
|
||||
return currentArray[currentIndex++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (!canRemove) {
|
||||
throw new IllegalStateException("Cannot call remove() without calling next()");
|
||||
}
|
||||
// 删除元素并更新数组
|
||||
System.arraycopy(currentArray, lastReturnedIndex + 1, currentArray, lastReturnedIndex, currentArray.length - lastReturnedIndex - 1);
|
||||
currentArray = Arrays.copyOf(currentArray, currentArray.length - 1); // 缩小数组大小
|
||||
currentIndex--; // 因为我们移除了当前元素,所以索引应该减一
|
||||
canRemove = false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DataValue[] dataStructures = new DataValue[6];
|
||||
dataStructures[0] = DataValue.builder().value("aaa1").key("name").type(DataType.VARCHAR).label("姓名").build();
|
||||
dataStructures[1] = DataValue.builder().value("aaa2").key("name").type(DataType.VARCHAR).label("姓名").build();
|
||||
dataStructures[2] = DataValue.builder().value("aaa3").key("name").type(DataType.VARCHAR).label("姓名").build();
|
||||
dataStructures[3] = DataValue.builder().value("aaa4").key("name").type(DataType.VARCHAR).label("姓名").build();
|
||||
dataStructures[4] = DataValue.builder().value("aaa5").key("name").type(DataType.VARCHAR).label("姓名").build();
|
||||
dataStructures[5] = DataValue.builder().value("aaa6").key("name").type(DataType.VARCHAR).label("姓名").build();
|
||||
|
||||
ArrayUtil<DataValue> dataStructureArrayUtil = new ArrayUtil<>(dataStructures);
|
||||
log.info(dataStructureArrayUtil.originalArray.length);
|
||||
log.info(JSONObject.toJSONString(dataStructureArrayUtil.originalArray));
|
||||
while (dataStructureArrayUtil.hasNext()){
|
||||
DataValue next = dataStructureArrayUtil.next();
|
||||
if (next.getValue().equals("aaa3")){
|
||||
dataStructureArrayUtil.remove();
|
||||
}
|
||||
}
|
||||
log.info(dataStructureArrayUtil.currentArray.length);
|
||||
log.info(Arrays.toString(dataStructureArrayUtil.currentArray));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue