Java容器涉及的类(代码)
Customer:
public class Customer implements Comparable{
private Integer customerId;
private String customerName;
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Customer(Integer customerId, String customerName) {
this.customerId = customerId;
this.customerName = customerName;
}
@Override
public String toString() {
return "Customer [customerId=" + customerId + ", customerName="
+ customerName + "]";
}
public Customer() {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + customerId;
result = prime * result
+ ((customerName == null) ? 0 : customerName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Customer other = (Customer) obj;
if (customerId != other.customerId)
return false;
if (customerName == null) {
if (other.customerName != null)
return false;
} else if (!customerName.equals(other.customerName))
return false;
return true;
}
//TreeSet类按照compareTo方法比较返回
//按id或name排序
@Override
public int compareTo(Object o) {
if(o instanceof Customer){
Customer c=(Customer) o;
//给整体添加'-'号改变正/逆序
// return this.customerId-c.customerId;
return this.customerName.compareTo(c.customerName);
}
return 0;
}
}
CustomerComparator:
import java.util.Comparator;
public class CustomerComparator implements Comparator{
@Override
public int compare(Object o1, Object o2) {
if(o1 instanceof Customer && o2 instanceof Customer){
Customer cust1=(Customer) o1;
Customer cust2=(Customer) o2;
return -cust1.getCustomerName().compareTo(cust2.getCustomerName());
}
return 0;
}
}
Java容器涉及的类(代码)的更多相关文章
- Java集合涉及的类(代码)
Customer: public class Customer implements Comparable{ private Integer customerId; pri ...
- java容器(二) Map类框架图解
- java容器(一) Collection类框架图解
- 【Java心得总结六】Java容器中——Collection
在[Java心得总结五]Java容器上——容器初探这篇博文中,我对Java容器类库从一个整体的偏向于宏观的角度初步认识了Java容器类库.而在这篇博文中,我想着重对容器类库中的Collection容器 ...
- java容器一:Collection概述
Collection概览 java容器有两类,第一类是Collection,存储的是对象的集合:第二类是Map,存储的是键值对(两个对象以及它们之间的对应关系)的集合 Collection接口下面有三 ...
- 图解JAVA容器核心类库
JAVA容器详解 类继承结构图 HashMap 1. 对象的HashCode是用来在散列存储结构中确定对象的存储地址的. 2. 如果两个对象的HashCode相同,即在数组中的地址相同.而数组的元 ...
- JAVA微信支付代码(WeChatPay.java 才是调用类)
微信官方文档:https://pay.weixin.qq.com/wiki/doc/api/index.html MD5Util.java package weixin; import java.se ...
- Java初始化方法:类、容器
Java初始化方法:类.容器 初始化类(非final): Struts2的DefaultActionMapper类中: public DefaultActionMapper() { ...
- grpc proto文件生成java、.net实体类以及客户端代码
背景 工作中对接对方服务是GRPC,对方只提供了proto契约文件,需要自己生成对应的实体类以及客户端代码,故记录下操作流程. Java 代码生成 实体类: 通过protoc插件生成实体类 在 htt ...
随机推荐
- 业余时间正在开发一个REACT小视频站点
业余时间正在开发一个REACT小视频站点,数据接口来源于吐槽弹幕网(C站),供C站用户移动端的观看.因现存在移动网络屏蔽C站的关系,最好使用非移动网络进行观看.否则会比较卡,影响用户体验. 站点测试入 ...
- bzoj1660 / P2866 [USACO06NOV]糟糕的一天Bad Hair Day
P2866 [USACO06NOV]糟糕的一天Bad Hair Day 奶牛题里好多单调栈..... 维护一个单调递减栈,存每只牛的高度和位置,顺便统计一下答案. #include<iostre ...
- 散列表(HashTable)
散列表 i. 散列函数 i. 冲突解决 ii. 分离链表法 ii. 开放地址法 iii. 线性探测法 iii. 平方探测法 iii. 双散列 ii. 再散列 ii. 可扩散列 i. 装填因子:元素个数 ...
- Easyui 官网网址
http://www.jeasyui.com/download/list.php 下载版本1.5.2的easyui中文API,可在CSDN网站http://download.csdn.net/down ...
- Python3基础 delattr 删除对象的属性
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- jquery hover最后解决 - 不再疑惑 - 例子在这里
hover具有动画累计的bug, 可以使用 stop 或 filter(:not(:animated))来消除, 但是, 即使这样, 当鼠标反复滑入或滑出的时候, 虽然没有动画累计的问题, 但是 下面 ...
- Linq 对List的一些操作
代码: public class Person { public int ID { get; set; } public string Name { get; set; } public int Ag ...
- [BZOJ1497]最大获利
Description 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一 ...
- Pairs Forming LCM (LCM+ 唯一分解定理)题解
Pairs Forming LCM Find the result of the following code: ; i <= n; i++ ) for( int j = i; j ...
- BZOJ3296: [USACO2011 Open] Learning Languages 并查集
Description 农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1<= M <=30,000)种语言,编号从1 .. M., ...