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. 作为从业人员,如果一定要学一门新的编程语言,那么它一定是c++

    作为从业人员,如果一定要学一门新的编程语言,那么它一定是c++. 无论各种编程语言排行榜如何变化,什么语言最赚钱,想成为真正的程序员,那么c/c++是必修课,因为几乎所有的底层都是c/c++编写的,各 ...

  2. 20145101《Java程序设计》第二周学习总结

    20145101 <Java程序设计>第2周学习总结 教材学习内容总结 在第三章的学习中,我学到了很多新知识点,了解到Java语言中的类型及其变量主要类型为:整数,还有char型,bool ...

  3. 20145334赵文豪《网络对抗》-逆向及Bof基础实践

    本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. 该程序同时包含另一个代码片段,getShell,会返 ...

  4. 20165310java_blog_week7

    2165310 <Java程序设计>第7周学习总结 教材学习内容总结 通过JDBC管理数据库 原理图: 链接数据库方式 - `Connection getConnection(java.l ...

  5. DTMF在VOIP中的解决方案

    双音多频DTMF(Dual Tone Multi-Frequency)信令,因其提供更高的拨号速率,迅速取代了传统转盘式电话机使用的拨号脉冲信令.DTMF也应用在交互式控制中,诸如语言菜单.语言邮件. ...

  6. duilib中edit获得鼠标焦点后右边框被覆盖

    转载:http://www.cnblogs.com/minggong/p/6457734.html 用duilib做了一个窗口,窗口内有一个供用户输入使用的是edit控件. XML中是这样写的: &l ...

  7. 【传输对象】kafka传递实体类消息

    工具类 负责对象字节数组的相互转换,传输数据用 package com.yq.utils; import java.io.ByteArrayInputStream; import java.io.By ...

  8. extgcd 扩展欧几里得算法模板

    #include <bits/stdc++.h> using namespace std; int extgcd (int a,int b,int &x,int &y){ ...

  9. jerichotab 初始化页面显示tab页中的第一个

    tab初始化默认显示第一个内容,但是tab标签显示最后一个. 源代码: $.fn.initJerichoTab({ renderTo: '#consumable', uniqueId: 'jerich ...

  10. C# asp.net 比较两个时间的差求天数

    string str1 = "2017-2-13 23:59:59"; string str2 = "2017-2-14 0:00:01"; DateTime ...