//package com.consum.base.util;
|
//
|
//import com.consum.model.po.PTempProjectStageNode;
|
//import com.walker.infrastructure.utils.CollectionUtils;
|
//
|
//import java.util.*;
|
//
|
///**
|
// * @ClassName RangeMergeUtil
|
// * @Author cy
|
// * @Date 2023/9/25
|
// * @Description
|
// * @Version 1.0
|
// **/
|
//public class RangeMergeUtil {
|
//
|
// /**
|
// * 根据节点中节点开始时间、持续时间,将节点转为link
|
// *
|
// * @param tempProjectStageNodes
|
// * @return
|
// */
|
// public static ArrayList<Link> tempNode2Link(List<PTempProjectStageNode> tempProjectStageNodes) {
|
// ArrayList<Link> links = new ArrayList<>();
|
// tempProjectStageNodes.forEach(item -> {
|
// Integer nodeTimeStart = item.getNodeTimeStart();
|
// Integer nodeTimeDays = item.getNodeTimeDays();
|
// if (nodeTimeStart != null && nodeTimeDays != null) {
|
// Link link = new Link(nodeTimeStart, nodeTimeStart + nodeTimeDays - 1);
|
// links.add(link);
|
// }
|
// });
|
// return links;
|
// }
|
//
|
// /**
|
// * 对给定区间进行合并
|
// *
|
// * @param info_dict
|
// * @return
|
// */
|
// public static ArrayList<Link> merge(ArrayList<Link> info_dict) {
|
// //首先对info_dict进行排序,排序规则为根据Link的left排序,如果left相等,根据right排序
|
// Collections.sort(info_dict, (o1, o2) -> {
|
// int a = o1.getLeft() - o2.getLeft();
|
// return a == 0 ? o1.getRight() - o2.getRight() : a;
|
// });
|
//
|
// //创建一个用于接受合并后结果的dict,同时设置一个类似滑动窗口一样的start和end
|
// ArrayList<Link> result_dict = new ArrayList<>();
|
// double start = -2e9, end = -2e9;
|
// for (Link i : info_dict) {
|
// //判断两种情况
|
// //第一种是当end小于i.getLeft()时,说明我们遇到了一个新的没有交集的区间
|
// //那么就将start和end移动过来,并且将它添加到result_dict中
|
// if (end + 1 < i.getLeft()) {
|
// if (start != -2e9) {
|
// result_dict.add(new Link((int) start, (int) end));
|
// }
|
// start = i.getLeft();
|
// end = i.getRight();
|
// }
|
// //第二种情况是当有交集时,如果在当前滑动区间内,不变,如果其right大于当前end,将滑动区间的end设置为right
|
// else {
|
// end = Math.max(end, i.getRight());
|
// }
|
// }
|
//
|
// //排空滑动区间
|
// if (start != -2e9) {
|
// result_dict.add(new Link((int) start, (int) end));
|
// }
|
// //返回result_dict中区间的个数
|
// return result_dict;
|
// }
|
//
|
// /**
|
// * 获取节点元素中的最值信息
|
// *
|
// * @param mergeList
|
// * @return
|
// */
|
// public static Map<String, Integer> getMergeMaxMinInfo(ArrayList<Link> mergeList) {
|
// if (CollectionUtils.isEmpty(mergeList)) {
|
// return null;
|
// }
|
// int maxLeft = Integer.MIN_VALUE;
|
// int minLeft = Integer.MAX_VALUE;
|
// int maxRight = Integer.MIN_VALUE;
|
// int minRight = Integer.MAX_VALUE;
|
//
|
// for (Link link : mergeList) {
|
// int left = link.getLeft();
|
// int right = link.getRight();
|
// maxLeft = Math.max(maxLeft, left);
|
// minLeft = Math.min(minLeft, left);
|
// maxRight = Math.max(maxRight, right);
|
// minRight = Math.min(minRight, right);
|
// }
|
// HashMap<String, Integer> rtnInfo = new HashMap<>();
|
// rtnInfo.put("maxLeft", maxLeft);
|
// rtnInfo.put("minLeft", minLeft);
|
// rtnInfo.put("maxRight", maxRight);
|
// rtnInfo.put("minRight", minRight);
|
// return rtnInfo;
|
// }
|
//
|
// /**
|
// * 校验是否有日期空档并返回区间最值信息
|
// * @param tempProjectStageNodes
|
// * @return
|
// */
|
// public static Map<String, Integer> checkDateGap(List<PTempProjectStageNode> tempProjectStageNodes) {
|
// ArrayList<Link> info_dict = tempNode2Link(tempProjectStageNodes);
|
// ArrayList<Link> mergeList = merge(info_dict);
|
// if (mergeList.size() > 1) {
|
// return null;
|
// }
|
// return getMergeMaxMinInfo(mergeList);
|
// }
|
//
|
// /**
|
// * 校验是否有重叠
|
// * @param list
|
// * @return
|
// */
|
// public static Boolean checkOverlap(List<Map<String, Integer>> list) {
|
// for (int i = 0; i < list.size(); i++) {
|
// Integer minLeft1 = list.get(i).get("minLeft");
|
// Integer maxRight1 = list.get(i).get("maxRight");
|
// for (int j = i + 1; j < list.size(); j++) {
|
// Integer minLeft2 = list.get(j).get("minLeft");
|
// Integer maxRight2 = list.get(j).get("maxRight");
|
// if (minLeft1 <= maxRight2 && maxRight1 >= minLeft2) {
|
// return true;
|
// }
|
// }
|
// }
|
// return false;
|
// }
|
//
|
// public static void main(String[] args) {
|
// List<PTempProjectStageNode> tempProjectStageNodes = new ArrayList<>();
|
// PTempProjectStageNode node1 = new PTempProjectStageNode();
|
// node1.setNodeTimeStart(2);
|
// node1.setNodeTimeDays(1);
|
// tempProjectStageNodes.add(node1);
|
//
|
// PTempProjectStageNode node2 = new PTempProjectStageNode();
|
// node2.setNodeTimeStart(1);
|
// node2.setNodeTimeDays(5);
|
// tempProjectStageNodes.add(node2);
|
//
|
// PTempProjectStageNode node3 = new PTempProjectStageNode();
|
// node3.setNodeTimeStart(3);
|
// node3.setNodeTimeDays(6);
|
// tempProjectStageNodes.add(node3);
|
//
|
// PTempProjectStageNode node4 = new PTempProjectStageNode();
|
// node4.setNodeTimeStart(80);
|
// node4.setNodeTimeDays(6);
|
// tempProjectStageNodes.add(node4);
|
//
|
// ArrayList<Link> info_dict = tempNode2Link(tempProjectStageNodes);
|
// ArrayList<Link> mergeList = merge(info_dict);
|
// System.out.println("合并后区间数量为:" + mergeList.size());
|
// Map<String, Integer> mergeMaxMinInfo = getMergeMaxMinInfo(mergeList);
|
// System.out.println("合并后区间中left:Max的值为:" + mergeMaxMinInfo.get("maxLeft"));
|
// System.out.println("合并后区间中left:Min的值为:" + mergeMaxMinInfo.get("minLeft"));
|
// System.out.println("合并后区间中right:Max的值为:" + mergeMaxMinInfo.get("maxRight"));
|
// System.out.println("合并后区间中right:Min的值为:" + mergeMaxMinInfo.get("minRight"));
|
//
|
// }
|
//}
|
//
|
//class Link {
|
// private int left;
|
// private int right;
|
//
|
// public int getLeft() {
|
// return left;
|
// }
|
//
|
// public void setLeft(int left) {
|
// this.left = left;
|
// }
|
//
|
// public int getRight() {
|
// return right;
|
// }
|
//
|
// public void setRight(int right) {
|
// this.right = right;
|
// }
|
//
|
// public Link(int left, int right) {
|
// this.left = left;
|
// this.right = right;
|
// }
|
//}
|