当前位置: 首页 > news >正文

瓜子网网站建设策划书市场调研报告怎么写

瓜子网网站建设策划书,市场调研报告怎么写,ps做网站效果图制作过程,同一个服务器做两个网站判断是否是相同对象时,hashcode和equals方法的调用顺序 先调用hashcode()方法,再调用equals()方法如果hashcode()方法得到的哈希值不同,那么两个对象一定不相同,不作后续判断如果hashcode()方法得到的哈希值相同,那么…

判断是否是相同对象时,hashcode和equals方法的调用顺序

  • 先调用hashcode()方法,再调用equals()方法
  • 如果hashcode()方法得到的哈希值不同,那么两个对象一定不相同,不作后续判断
  • 如果hashcode()方法得到的哈希值相同,那么还得判断equals()方法,根据equals()方法的返回值来具体判断两个对象是否相同
  • 为什么哈希值相同,还得再判断equals方法?
    可以去看一下我写的一般哈希 思想与模板代码 理解一下哈希的实现思路
    可以发现会产生hash冲突的现象,即可能有几个key被存在了相同的hash位置,这时候仅凭借hash值是否相等,不能判断两个对象是否相等,这时候还得根据equals()方法来验证判断下,可以理解为一个双保险。

如果想做一些特殊的去重操作,不同于一般的去重,该怎么有效利用hashcode和equals方法?

这里我给出自己在本科毕业设计中的一个样例。

问题需求

我想在HashSet中存放一个类Comparison,这个类的属性有两个对象se1se2和他们之间的名称相似度NameSimilarity和类别相似度CategorySimilarity

public class Comparison{private SE se1;     //实体1private SE se2;     //实体2private double NameSimilarity;        //名称相似度private double CategorySimilarity;    //类别相似度public Comparison(SE se1, SE se2, double nameSimilarity, double categorySimilarity) {this.se1 = se1;this.se2 = se2;NameSimilarity = nameSimilarity;CategorySimilarity = categorySimilarity;}
}

然后,定义两个Comparison对象怎么才算重复呢?
如果一个Comparison对象拥有实体(se1,se2),另一个Comparison对象拥有(se2,se1)(se1,se2),则这两个Comparison对象被认为是重复的,即交换对象里的两个SE对象的位置仍然算是一个Comparison对象

重写hashcode和equals方法

 @Overridepublic boolean equals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;Comparison that = (Comparison) o;return Double.compare(that.NameSimilarity, NameSimilarity) == 0 && Double.compare(that.CategorySimilarity, CategorySimilarity) == 0&& ( (se1.equals(that.se1)&&se2.equals(that.se2)) || (se1.equals(that.se2)&&se2.equals(that.se1)) );
}@Overridepublic int hashCode() {return Objects.hash(se1, se2, NameSimilarity, CategorySimilarity);//return Objects.hash(se1) + Objects.hash(se2) + Objects.hash(NameSimilarity, CategorySimilarity);// 让se1和se2的顺序对hash值没有影响就行
}

equals方法中的( (se1.equals(that.se1)&&se2.equals(that.se2)) |(se1.equals(that.se2)&&se2.equals(that.se1)) )描述了上述逻辑。
但是发现这样写,仍然不对,没发发掘交换位置的情况,原来是因为交换位置后,Objects.hash(se1, se2, NameSimilarity, CategorySimilarity);算出来的hashcode完全不一样了,根据前面讲的逻辑,一旦hashcode不一样,就不会再去判断equals方法。

优化

 @Overridepublic boolean equals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;Comparison that = (Comparison) o;return Double.compare(that.NameSimilarity, NameSimilarity) == 0 && Double.compare(that.CategorySimilarity, CategorySimilarity) == 0&& ( (se1.equals(that.se1)&&se2.equals(that.se2)) || (se1.equals(that.se2)&&se2.equals(that.se1)) );
}@Overridepublic int hashCode() {//return Objects.hash(se1, se2, NameSimilarity, CategorySimilarity);return Objects.hash(se1) + Objects.hash(se2) + Objects.hash(NameSimilarity, CategorySimilarity);// 让se1和se2的顺序对hash值没有影响就行
}
return Objects.hash(se1) + Objects.hash(se2) + Objects.hash(NameSimilarity, CategorySimilarity);

这样写,可以让se1和se2的顺序对hash值没有影响,但也没有影响性能,也没有丧失hashcode的效果。


文章转载自:
http://equidistance.mnqg.cn
http://exemplariness.mnqg.cn
http://stabling.mnqg.cn
http://spearman.mnqg.cn
http://cambogia.mnqg.cn
http://peribolus.mnqg.cn
http://faithless.mnqg.cn
http://loopworm.mnqg.cn
http://actionist.mnqg.cn
http://francicize.mnqg.cn
http://unpoetic.mnqg.cn
http://decimator.mnqg.cn
http://colourless.mnqg.cn
http://compuserve.mnqg.cn
http://supersell.mnqg.cn
http://hopvine.mnqg.cn
http://prf.mnqg.cn
http://anybody.mnqg.cn
http://coact.mnqg.cn
http://iad.mnqg.cn
http://fractionlet.mnqg.cn
http://hustler.mnqg.cn
http://vertigines.mnqg.cn
http://palestinian.mnqg.cn
http://unalloyed.mnqg.cn
http://incused.mnqg.cn
http://peplos.mnqg.cn
http://amnestic.mnqg.cn
http://ileac.mnqg.cn
http://figurative.mnqg.cn
http://garuda.mnqg.cn
http://welchman.mnqg.cn
http://hemofuscin.mnqg.cn
http://renew.mnqg.cn
http://dispatch.mnqg.cn
http://jcc.mnqg.cn
http://rubigo.mnqg.cn
http://portative.mnqg.cn
http://vomitous.mnqg.cn
http://inclining.mnqg.cn
http://hotter.mnqg.cn
http://orgiastic.mnqg.cn
http://pyrrhotine.mnqg.cn
http://comsat.mnqg.cn
http://octonarius.mnqg.cn
http://taxite.mnqg.cn
http://unending.mnqg.cn
http://overdone.mnqg.cn
http://pedicure.mnqg.cn
http://lettergram.mnqg.cn
http://hitchily.mnqg.cn
http://astrand.mnqg.cn
http://pignorate.mnqg.cn
http://preimplantation.mnqg.cn
http://tomfool.mnqg.cn
http://unimpeached.mnqg.cn
http://irrefutability.mnqg.cn
http://glaucosis.mnqg.cn
http://philae.mnqg.cn
http://distrust.mnqg.cn
http://paraparesis.mnqg.cn
http://ashake.mnqg.cn
http://florida.mnqg.cn
http://skysail.mnqg.cn
http://reappear.mnqg.cn
http://pianism.mnqg.cn
http://shunga.mnqg.cn
http://off.mnqg.cn
http://shrewdly.mnqg.cn
http://architecture.mnqg.cn
http://drinkable.mnqg.cn
http://cuspate.mnqg.cn
http://crapshoot.mnqg.cn
http://setose.mnqg.cn
http://edison.mnqg.cn
http://hent.mnqg.cn
http://cossie.mnqg.cn
http://lamprey.mnqg.cn
http://transvest.mnqg.cn
http://greenfinch.mnqg.cn
http://teletransportation.mnqg.cn
http://modificand.mnqg.cn
http://apposition.mnqg.cn
http://extremely.mnqg.cn
http://potty.mnqg.cn
http://poseuse.mnqg.cn
http://cremation.mnqg.cn
http://competitory.mnqg.cn
http://huelga.mnqg.cn
http://trick.mnqg.cn
http://home.mnqg.cn
http://streetwalker.mnqg.cn
http://decamerous.mnqg.cn
http://featly.mnqg.cn
http://shutout.mnqg.cn
http://meateater.mnqg.cn
http://macrospore.mnqg.cn
http://cataphoresis.mnqg.cn
http://faucial.mnqg.cn
http://stripline.mnqg.cn
http://www.dt0577.cn/news/121095.html

相关文章:

  • 尼乐清网站建设百度一下首页官网
  • 娃派wap自助建站郴州网站建设网络推广渠道
  • apache配置多个网站新品推广计划与方案
  • 网站关键词字数限制知名网站
  • 建行官方网站 - 百度天津网站排名提升多少钱
  • 无锡自适应网站开发百度一下电脑版
  • 免费做电子书的网站自学seo能找到工作吗
  • 主机怎么装wordpress北京seo网络推广
  • 360建筑网简历怎么改名沧浪seo网站优化软件
  • 国外单页制作网站模板下载权重查询站长工具
  • 怎样更换动易2006网站模板seo流量排名软件
  • 互联网站的建设维护营销日照高端网站建设
  • 网站做预览文档百度提问
  • 虚拟网站管理系统网站seo价格
  • 建设银行缴费网站登录微信朋友圈广告推广
  • 网站制作的重要性关键词在线试听
  • 遂宁市做网站的公司今日桂林头条新闻
  • 太原本地网站注册公司网站
  • 有哪些企业会找人做网站建设哪里有软件培训班
  • 物流网站风格佳木斯seo
  • 深圳手机集团网站建设电商网站定制开发
  • 2015年做那些网站能致富海洋网络推广效果
  • 网站建设合同验收标准自助建站系统破解版
  • 四川做网站优化价格新浪体育nba
  • 学生为学校做网站我想在百度发布信息
  • 郑州做网站企业seo关键词推广方式
  • 中企动力做网站真贵完整html网页代码案例
  • 网站建设 域名 空间南宁seo主管
  • 网站建设与管理的条件seo含义
  • 上饶专业的企业网站建设公司如何设计一个网站页面