当前位置:网站首页>Rewrite hashcode() to compare whether the classes are the same
Rewrite hashcode() to compare whether the classes are the same
2022-07-21 20:08:00 【__ Aurora___】
java Class hashCode() function , Whether the comparison class is the same .
Want to see hashCode() Function comparison class , You can see the catalogue directly 3.
1. The problem background
Recently, I'm writing a database final assignment , Make a Web project . What I do is an online classroom reservation project . Based on the ruoyi framework 、echarts Written .
There are two tables —— Classroom schedule 、 Classroom appointment form .
There are the following entities :
classroom classroom.class
// Classroom number
private String classroom_id ;
// Capacity
private Int classroom_accept_number;
Classroom reservation classroomAppointment.class
// Classroom number
private String classId;
// Time of appointment yyyy-MM-dd
private Date appointmentDataTime;
// Appointment session
private String appointmentUserClass;
notes : A classroom in a day There are five time periods to choose ——{“12”, “34”, “56”, “78”, “90”}.appointmentUserClass = “12” Hour represents appointment 12 lesson
If The classroom number is 100
My classroom 12 section
2022 year 1 month 1 Number
Made an appointment , When the user queries 2022 year 1 month 1 Number
The number is 100
classroom when , Users can only see “34”, “56”, “78”, “90” You can make an appointment .
2. How to get rid of it Information that has been reserved
My idea of booking a classroom is , According to the user's choice Time 、 Classroom number
, Find out the classroom information , Add to classroomAppointment.class, Plus Section , Store in List< classroomAppointment > in , such 2022 year 1 month 1 Number The classroom number is 100 Of the following :
[[
classId=100
appointmentDataTime = 2022-01-01
appointmentUserClass = 12
],
[
classId=100
appointmentDataTime = 2022-01-01
appointmentUserClass = 34
],
[
classId=100
appointmentDataTime = 2022-01-01
appointmentUserClass = 56
],[
classId=100
appointmentDataTime = 2022-01-01
appointmentUserClass = 78
],
[
classId=100
appointmentDataTime = 2022-01-01
appointmentUserClass = 90
]]
Then query the reservation table , The information in the classroom number in this date .
[
classId=100
appointmentDataTime = 2022-01-01
appointmentUserClass = 12
]
3. rewrite hashCode() function
@Override
public int hashCode() {
int result = appointmentDataTime != null?appointmentDataTime.hashCode():0;
result = 31*result+(appointmentUserClass !=null ?appointmentUserClass.hashCode():0);
return result;
}
Only two classes need to be judged appointmentDataTime And appointmentUserClass Whether these two attributes are the same , To determine whether the two classes are the same .
边栏推荐
- From graphic design to software testing, I like to raise 11k+13 salary. Looking back, I'm very lucky
- As editor sets the indent position of the code on the right side of fluent development
- 对象拷贝工具类(fastjson)
- jimu积木报表打印时多一页空白页-问题解决
- flutter自定义form表单,封装form表单组件
- 单体项目-瑞吉外卖
- 从20s优化到500ms,我是如何做到的
- MySql update语句或者delete语句 where条件没走索引会锁表
- iwemeta:史玉柱的黄金酱酒:贴牌的代工厂都被关停了,谁在生产?
- Odoo God operation background call routing interface
猜你喜欢
629. K inverse pairs array
Introduction, installation and basic use of MYCAT
FL Studio 20.9水果编曲软件中文汉化补丁包
Wechat official account development access, using wechat public platform to apply for test number for local development
Pycharm创建SQLite数据库
整合ssm框架的项目
微信公众号开发接入,利用微信公众平台申请测试号进行本地开发
Fluent customizes form and encapsulates form components
图表即代码:以代码化的方式构建新一代图形库 —— Feakin
1451 - Cannot delete or update a parent row 具有多个外键约束 删除子表数据行的问题
随机推荐
2022.7.18DAY609
867. Decomposition prime factor
aws的postgreSQL是去掉了hba吗?
Linux Redis-6.2.6单机部署
14. 你能说说进程与线程的区别吗
LeetCode 76. 最小覆盖子串-滑动窗口法
JSON工具类
ES6的数组、对象拷贝
Jenkins插件开发——提供对外访问接口
Error in pulling project POM file, Jai_ core-1.1.3. Jar, solve the problem of introducing jar
NXP i.MX 8m mini core board specifications, quad core arm cortex-a53 + arm cortex-m4
使用Clip Converter网站下载Yotube视频
10行代码实现微信小程序支付功能,使用小程序云开发实现小程序支付功能(含源码
Lst list deletion and modification
2022.7.19DAY610
Bluetooth intelligent nutrition electronic scale solution
MySQL之数据库设计三范式
Development tools supporting data + code generation, yyds
Trigonometric formula of 3D mathematics
629. K inverse pairs array