capacitymap.java

来自「基于Java的软件信息系统-项目管理」· Java 代码 · 共 98 行

JAVA
98
字号
package db;import java.util.*;import java.io.*;public class CapacityMap{    private Map m_capacityMap;    public CapacityMap ()    {        m_capacityMap = new TreeMap ();    }    public void addReservations (List reservations)    {        for (Iterator iter = reservations.listIterator ();            iter.hasNext (); )        {            addReservation ((Reservation)iter.next());        }    }    public void addReservation (Reservation res)    {        GregorianCalendar cal = new GregorianCalendar ();        cal.setTime (res.getDate());        for (int i = 0; i < res.getDays(); i++)        {            addEntry (cal.getTime(), res.getRoomType ());            cal.add (Calendar.DAY_OF_YEAR, 1);        }    }    public void removeReservation (Reservation res)    {        GregorianCalendar cal = new GregorianCalendar ();        cal.setTime (res.getDate());        for (int i = 0; i < res.getDays(); i++)        {            removeEntry (cal.getTime(), res.getRoomType ());            cal.add (Calendar.DAY_OF_YEAR, 1);        }    }    public Map getDateMap (Date date)    {	if (! m_capacityMap.containsKey (date))	    return null;	return (Map) m_capacityMap.get (date);    }    public CapacityInfo getInfoEntry (Map dateMap, Date date, int roomType)    {	Integer roomKey = new Integer (roomType);	if (! dateMap.containsKey (roomKey))	    return null;	return (CapacityInfo) dateMap.get (roomKey);    }    public Map ensureDateMap (Date date)    {	if (! m_capacityMap.containsKey (date))	    m_capacityMap.put (date, new TreeMap ());	return (Map) m_capacityMap.get (date);    }    public CapacityInfo ensureInfoEntry (Map dateMap, Date date, int roomType)    {	Integer roomKey = new Integer (roomType);	if (! dateMap.containsKey (roomKey))	    dateMap.put (roomKey, new CapacityInfo(date, roomType));	return (CapacityInfo) dateMap.get (roomKey);    }    public void addEntry (Date date, int roomType)    {        Map dateMap = ensureDateMap (date);	CapacityInfo cinfo = ensureInfoEntry (dateMap, date, roomType);        cinfo.addReservation ();    }    public void removeEntry (Date date, int roomType)    {        Map dateMap = getDateMap (date);	CapacityInfo cinfo = getInfoEntry (dateMap, date, roomType);        cinfo.removeReservation ();    }    public List getCapacity (Date date)    {	Map dateMap = getDateMap (date);	if (dateMap == null)	    return new ArrayList ();	return HotelDB.toList (dateMap.values());    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?