📄 capacitymap.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -