importjava.math.BigDecimal;importjava.util.ArrayList;importjava.util.List;/*** @description: 区间工具类

*@author: wyj

* @time: 2020/3/1 15:05*/

public classSectionUtil {//最小值

privateString min_entity;//最大值

privateString max_entity;//左侧括号状态:false -开区间 true-- 闭区间

private boolean left_sate = false;//右侧括号状态:false -开区间 true-- 闭区间

private boolean right_sate = false;privateSectionUtil() {

}public SectionUtil(String min_entity, String max_entity, boolean left_sate, booleanright_sate) {this.min_entity =min_entity;this.max_entity =max_entity;this.left_sate =left_sate;this.right_sate =right_sate;

}publicString getMin_entity() {returnmin_entity;

}publicString getMax_entity() {returnmax_entity;

}public booleanisLeft_sate() {returnleft_sate;

}public booleanisRight_sate() {returnright_sate;

}/*** @description: 创建负区间((负无穷,X])

*@paramvalue 区间最大值

*@paramright_sate 区间开闭状态

* @Date: 2020/3/2 14:37*/

public static SectionUtil creatFu(String value, booleanright_sate) {return new SectionUtil("", value, false, right_sate);

}/*** @description: 创建正区间[X,正无穷))

*@paramvalue 区间最小值

*@paramleft_sate 区间开闭状态

* @Date: 2020/3/2 14:37*/

public static SectionUtil creatZheng(String value, booleanleft_sate) {return new SectionUtil(value, "", left_sate, false);

}/*** @description: 创建闭合区间([X,Y])

*@parammin 区间最小值

*@parammax 区间最大值

*@paramleft_sate 区间左侧开闭状态

*@paramright_sate 区间右侧开闭状态

*@return* @Date: 2020/3/2 14:41*/

public static SectionUtil creat(String min, boolean left_sate, String max, booleanright_sate) {return newSectionUtil(min, max, left_sate, right_sate);

}/*** @description: 将实体类转换成区间集合

*@paramrecord 待转换的实体类

*@return转换后的区间集合类(不等于时转换后为2个区间,所以采用集合)

* @Date: 2020/3/2 14:19*/

public static ListgetSections(ReqRespResearchProductQuestionnaireItem record) {

List list = new ArrayList<>();

String record_max=record.getMaxValue();

String record_min=record.getMinValue();switch(record.getSymbol()) {case 1:

list.add(creatZheng(record_max,false));break;case 2:

list.add(creatFu(record_max,false));break;case 3:

list.add(creat(record_max,true, record_max, true));break;case 4:

list.add(creatFu(record_max,false));

list.add(creatZheng(record_max,false));break;case 5:

list.add(creatZheng(record_max,true));break;case 6:

list.add(creatFu(record_max,true));break;case 7:

list.add(creat(record_min,true, record_max, true));break;case 8:

list.add(creat(record_min,true, record_max, false));break;case 9:

list.add(creat(record_min,false, record_max, true));break;case 10:

list.add(creat(record_min,false, record_max, false));break;

}returnlist;

}public intcompareTo(String first_value, String second_value) {//first_value为空表示为正无穷,second_value为空表示为负无穷

if (isBlank(first_value) ||isBlank(second_value)) {return 1;

}returncompareToValue(first_value,second_value);

}//判断字符串是否为空

public static booleanisBlank(String str) {intstrLen;if (str == null || (strLen = str.length()) == 0) {return true;

}for (int i = 0; i < strLen; i++) {if ((Character.isWhitespace(str.charAt(i)) == false)) {return false;

}

}return true;

}/***@paramrecord 判断区间是否有重合

*@returntrue-有重合 false -无重合

* @description: 判断当前区间是否和指定区间重合

* @Date: 2020/3/2 10:20*/

public booleanisChonghe(SectionUtil record) {

String min_entity=record.getMin_entity();

String max_entity=record.getMax_entity();boolean left_sate =record.isLeft_sate();boolean right_sate =record.isRight_sate();boolean left_isok = false;boolean right_isok = false;//重合条件,第一个区间最大值大于第二个区间最小值并且第一个区间的最小值小于第二个区间的最大值//注意传值顺序,第一个值为第一个区间的最大值(此处不能反)

int first_result = compareTo(this.max_entity, min_entity);if ((first_result == 0 && this.right_sate && left_sate) || (first_result > 0)) {

left_isok= true;

}//注意传值顺序,第一个值为第二个区间的最大值(此处不能反)

int second_result = compareTo(max_entity, this.min_entity);//此处本应该是second_result<0,但由于上一步参数传递时时反正传递,故此此处为second_result>0

if ((second_result == 0 && this.left_sate && right_sate) || second_result > 0) {

right_isok= true;

}return left_isok &&right_isok;

}/*** @description: 比较集合中区间是否有重叠

*@paramlist1 待比较集合1

*@paramlist2 待比较集合2

*@return* @Date: 2020/3/2 11:49*/

public static boolean isChonghe(List list1, Listlist2) {boolean chonghed = false;for(SectionUtil item1 : list1) {for(SectionUtil item2 : list2) {

chonghed=item1.isChonghe(item2);if(chonghed) {return true;

}

}

}returnchonghed;

}//比较大小

public static intcompareToValue(String value1, String value2) {

BigDecimal b1= newBigDecimal(value1);

BigDecimal b2= newBigDecimal(value2);returnb1.compareTo(b2);

}

}

区间重合判断 java_java判断多个区间是否有重合相关推荐

  1. mysql判断是否在日期区间_通过sql判断时间区间是否存在数据

    在做项目的时候遇到过一个问题,用户需要获取当前月或者几个月的数据,但是有一个要求,如果已经存在一张单已经包含了这几个月的数据,那么就不能再提取到重复的数据. 其实这个问题,我做完了我的方式之后才发现, ...

  2. python判断序列值横穿整个区间的次数

    这里需要用的集合的知识,一般python集合会用intervals库或portion库,这里我们用portion库 intervals库github:https://github.com/kveste ...

  3. js 日期比较大小,js判断日期是否在区间内,js判断时间段是否在另外一个时间段内...

    /** * 日期解析,字符串转日期 * @param dateString 可以为2017-02-16,2017/02/16,2017.02.16 * @returns {Date} 返回对应的日期对 ...

  4. python判断当前时间是否在两个时间之间_Python 判断时间是否在时间区间内的实例...

    判断时间是否在时间区间内 大家都知道 3<4<5这种连等式判断在python中是可行的 >>> 3<4<5 True 那么给定时间是否在时间区间内,也可以用连 ...

  5. java区间合并_贪心算法:合并区间

    ❝ 最近文章阅读量少了很多啊打卡也少了, 是不是年底了很多录友在忙期末考试啊,哈哈. 给出一个区间的集合,请合并所有重叠的区间. 示例 1: 输入: intervals = [[1,3],[2,6], ...

  6. 区间相关问题的学习: 最多不相交区间问题,区间选点问题与区间覆盖问题

    区间相关问题包括: 1)最多不相交区间问题; 2)区间选点问题; 3)区间覆盖问题等. 最多不相交区间问题(又叫选择不相交区间,最大不相交覆盖等等),是指数轴上有n个开区间(a,b),选择尽量多个区间 ...

  7. 逻辑判断-if语句/文件目录属性判断/case判断

    逻辑判断IF -gt :大于 -lt :小于 -eq :等于 -ne :不等于 -ge :大于或等于 -le :小于或等于 格式1: if 条件 :then 语句: fi a=5 if [ $a -g ...

  8. 【HDU - 1698】 Just a Hook(线段树模板 区间覆盖更新(laz标记) + 区间和查询 )

    题干: In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroe ...

  9. 动态分区分配算法代码_【代码】巩敦卫等TEVC论文:基于区间相似度分析的协同动态区间多目标进化优化算法...

    分享代码:巩敦卫等TEVC论文:基于区间相似度分析的协同动态区间多目标进化优化算法. 说明:该代码基于Matlab2012a及Intlab5.5编写,对应文献:"Dunwei Gong, B ...

最新文章

  1. DevExpress WPF MVVM入门例子
  2. Ubuntu12.04使用技巧
  3. MySQL编程技巧_PHP与MySQL开发的8个技巧小结
  4. 鼠标滚轮事件绑定的兼容性问题
  5. 接触Jenkins(Hudson)API,第1部分
  6. 机器学习模型中step与epoch,batch_size之间的关系
  7. impala sql清单
  8. vue import组件的使用
  9. 对于最近爆火的区块链,投资人怎么看? | 聚焦
  10. python拥有庞大的计算生态_Python稳定基础训练中的易出错概念问题1(包括答案和分析),稳基,修炼,之,计算机,等级,考试,易错,含答案,与,解析...
  11. jQuery comet
  12. 老王讲设计模式(三)——单例模式
  13. php 简转繁体,PHP简体转繁体——MediaWiki-zhconvert
  14. 手机当台式电脑摄像头
  15. 【数据结构与算法】起始篇
  16. HG2821T-U电信光猫修改SSID去掉ChinaNet
  17. if-else过多,使用策略模式(Strategy)解决if-else乱象
  18. 使用Xshell连接Ubuntu 20.4系统时提示
  19. 了解Maxicode二维码
  20. python爬虫之请求(url)构造 —— 寻找参数来源以及中文编码

热门文章

  1. 英语写作的常用句型(二)
  2. zookeeper源码编译的坑
  3. 实用 Windows 软件系列分享(四)
  4. VS2012皮肤下载地址
  5. Visual Studio 20周年,我和VS不得不说的故事(内含福利)
  6. arr 安卓调用qmui_MUI框架-读取手机通讯录
  7. 知识图谱与文献计量你一定做错了! citespace
  8. C#使用windows自带的性能监视器显示
  9. 什么在占用你的Mac磁盘空间?DaisyDisk如何清理磁盘空间?
  10. 1.8 数学大事年表