日期:2014-05-20  浏览次数:20602 次

有关hashmap的key
Java code

package StartDiaguo;

import java.io.Serializable;
//import java.util.*;

public class Appointment implements Serializable {
    private String clientName;
    
    private String startTime;
    private String endTime;
    private String date;
    private Appointment next;
    
    
        
    public Appointment(){
        clientName = null;
        date = null;
        startTime = null;
        endTime = null;
        next = null;
        
    }
    public Appointment(String name,String d, String s, String e){
        clientName = name;
        date = d;
        startTime = s;
        endTime = e;
        next = null;
        
    }
    
    public Appointment getNext(){
        return next;
    }

    public void setNext(Appointment ap){
        next = ap;
    }
    
    public String getName(){
        return clientName;
    }
    
    public void setName(String name){
        clientName = name;
    }

    public String getTime(){
        return startTime +"-"+ endTime;
    }
    
    public void setTime(String s, String e){
        startTime = s;
        endTime = e;
    }
    public String getStartTime(){
        return startTime;
    }
    public void setStartTime(String s){
        startTime = s;
    }
    public void setEndTime(String e){
        endTime = e;
    }
    public String getEndTime(){
        return endTime;
    }
    public String getDate(){
        return date;
    }
    public void setDate(String d){
        date = d;
    }

    public void setAppointment(String n, String d, String s, String e) {
        clientName = n;
        startTime = s;
        endTime = e;
        date = d;
    }
}



private Map<String, Appointment> appBook; 来存一个Appointment
Appointment 是一个linkedlist的形式  
我用hashmap来存这个自定linkedlist类,当我想改Appointment.next 的内容后 怎么返回第一个app
还是有什么办法更改hashmap的key

------解决方案--------------------
这是我提供的 管理约会的一个解决方案,一组有序列的约会抽象为AppSeries,那里面提供了对约会事件的基本增加和删除操作
对于你关注的一次约会序列当中 找一次约会的下一次约会,可以通过查找对应的index然后index+1再通过AppSeries调用提供的API实现,下面的TestApp有演示
Java code


import java.io.Serializable;
//import java.util.*;

public class Appointment implements Serializable {
    private String clientName;

    private String startTime;
    private String endTime;
    private String date;
//    private Appointment next;

    @Override
    public String toString() {
        return "Appointment{" +
                "clientName='" + clientName + '\'' +
                ", startTime='" + startTime + '\'' +
                ", endTime='" + endTime + '\'' +
                ", date='" + date + '\'' +
                '}';
    }

    public Appointment(){
        clientName = null;
        date = null;
        startTime = null;
        endTime = null;
//        next = null;

    }
    public Appointment(String name,String d, String s, String e){
        clientName = name;
        date = d;
        startTime = s;
        endTime = e;
//        next = null;

    }
       
    public String getName(){
        return clientName;
    }

    public void setName(String name){
        clientName = name;
    }

    public String getTime(){
        return startTime +"-"+ endTime;
    }

    public void setTime(String s, String e){
        startTime = s;
        endTime = e;
    }
    public String getStartTime(){
        return startTime;
    }
    public void setStartTime(String s){
        startTime = s;
    }
    public void setEndTime(String e){
        endTime = e;
    }
    public String getEndTime(){
        return endTime;
    }
    public String getDate(){
        return date;
    }
    public void setDate(String d){
        date = d;
    }

    public void setAppointment(String n, String d, String s, String e) {
        clientName = n;
        startTime = s;
        endTime = e;
        date = d;
    }
}