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容器涉及的类(代码)的更多相关文章

  1. Java集合涉及的类(代码)

    Customer: public class Customer implements Comparable{        private Integer customerId;        pri ...

  2. java容器(二) Map类框架图解

  3. java容器(一) Collection类框架图解

  4. 【Java心得总结六】Java容器中——Collection

    在[Java心得总结五]Java容器上——容器初探这篇博文中,我对Java容器类库从一个整体的偏向于宏观的角度初步认识了Java容器类库.而在这篇博文中,我想着重对容器类库中的Collection容器 ...

  5. java容器一:Collection概述

    Collection概览 java容器有两类,第一类是Collection,存储的是对象的集合:第二类是Map,存储的是键值对(两个对象以及它们之间的对应关系)的集合 Collection接口下面有三 ...

  6. 图解JAVA容器核心类库

    JAVA容器详解 类继承结构图 HashMap 1. 对象的HashCode是用来在散列存储结构中确定对象的存储地址的.   2. 如果两个对象的HashCode相同,即在数组中的地址相同.而数组的元 ...

  7. JAVA微信支付代码(WeChatPay.java 才是调用类)

    微信官方文档:https://pay.weixin.qq.com/wiki/doc/api/index.html MD5Util.java package weixin; import java.se ...

  8. Java初始化方法:类、容器

    Java初始化方法:类.容器   初始化类(非final): Struts2的DefaultActionMapper类中:      public DefaultActionMapper() {   ...

  9. grpc proto文件生成java、.net实体类以及客户端代码

    背景 工作中对接对方服务是GRPC,对方只提供了proto契约文件,需要自己生成对应的实体类以及客户端代码,故记录下操作流程. Java 代码生成 实体类: 通过protoc插件生成实体类 在 htt ...

随机推荐

  1. CDC画图

    CDC* pdc: CRect rcBounds: 1. 画直线 pdc->MoveTo(rcBounds.TopLeft());//将画笔移动到左上角这个点,使用这个点作为起点画图 pdc-& ...

  2. C#调用托管ocx、dll

    前篇文章是调用非托管,比较复杂,这里是调用托管,很简单[所以在遇到非托管dll时可以通过二次封装成托管的方式,再通过这边文章来使用] 1.注意这是基于COM的ocx或者dll,所以用regsvr32先 ...

  3. 又一个改写MBR的病毒(TDSS TDL4)

    此毒为TDSS TDL4 的又一个变种.RIS2011 目前尚未收录此毒.此毒的主要行为是改写MBR,并在硬盘尾部的190个扇区内写入病毒代码.病毒的上述动作可穿透还原类软件对系统的保护.我在Acro ...

  4. 关于ActiveMQ、RocketMQ、RabbitMQ、Kafka一些总结和区别

    这是一篇分享文 转自:http://www.cnblogs.com/williamjie/p/9481780.html  尊重原作,谢谢 消息队列 为什么写这篇文章? 博主有两位朋友分别是小A和小B: ...

  5. github issues的操作

    https://help.github.com/en/articles/searching-issues-and-pull-requests 根据 reporter筛选issues https://h ...

  6. Facebook广告API系列 Business Manager

    Facebook广告API系列 Business Manager Business Manager,是个很牛叉的东西,有多牛叉呢? 因为facebook已经越来越商业化了,上面的每个账号,页面,往往都 ...

  7. 使用Hyper-V创建虚拟机

    很多想使用Linux的小伙伴们不敢在自己的电脑上安装,害怕出错误删文件啥的,当然,对于新手确实很容易发生这样的事,特别是一点硬盘分区知识都木有的.这时候就要借助于虚拟机了.Windows平台下经常使用 ...

  8. Pyinstaller 中 pandas出错问题的解决(详细)

    环境配置 pip install pyinstaller pyinstaller中的参数 -F 表示生成单个可执行文件 -c 显示命令行窗口,一般一开始的时候使用,如果没有错误,那就使用-w命令 -w ...

  9. Ubuntu 登陆界面无限循环问题 以及 root用户无法使用命令问题

    在Ubuntu下配置好了eclipse之后,马上着手用eclipse试运行ns3.在./waf编译的时候出现了"Permission denied"问题. 在网络上查阅了相关资料之 ...

  10. maven+nexus配置本地私有仓库

    以下是settting.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <settings> ...