From: Florian L. <fle...@us...> - 2005-11-07 15:22:41
|
Update of /cvsroot/magicmap/magicmapserver/src/net/sf/magicmap/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4072/src/net/sf/magicmap/server/cache Modified Files: PositionCache.java Log Message: update Index: PositionCache.java =================================================================== RCS file: /cvsroot/magicmap/magicmapserver/src/net/sf/magicmap/server/cache/PositionCache.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PositionCache.java 7 Nov 2005 12:46:04 -0000 1.2 --- PositionCache.java 7 Nov 2005 15:22:33 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.Collection; + import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; *************** *** 14,20 **** public class PositionCache extends Hashtable<Map,PositionCacheEntry>{ - private static SortedMap timeMap; - private static HashSet idHash; - // Sigleton Hashtable private static PositionCache single_positionCache = null; --- 15,18 ---- *************** *** 63,66 **** --- 61,83 ---- } + + public void movePosition (Map map, Long id, int x, int y, boolean fixed){ + if(existsMapHashtable(map)){ + getMapHashtable(map).movePosition(id, x, y, fixed); + } + } + + public void deletePosition (Map map, Long id){ + if(existsMapHashtable(map)){ + getMapHashtable(map).removePosition(id); + } + } + + public void deletePosition (Map map, String name){ + if(existsMapHashtable(map)){ + getMapHashtable(map).removePosition(name); + } + } + } *************** *** 68,94 **** private Hashtable<String,PositionDTO> positionHash; private TreeMap<Long ,String> timeMap; protected PositionCacheEntry (){ ! positionHash = new Hashtable<String,PositionDTO>(40); timeMap = new TreeMap<Long ,String>(); } protected void addPosition(PositionDTO position){ ! positionHash.put(position.getName(),position); timeMap.put(position.getLastModified(),position.getName()); } protected boolean existsPosition(String name){ return positionHash.containsKey(name); } protected PositionDTO getPosition(String name){ return positionHash.get(name); } protected void removePosition(String name){ timeMap.remove(positionHash.get(name).getLastModified()); positionHash.remove(name); } protected PositionDTO[] getPositionsSince(Long time){ Collection<String> newPositions = timeMap.tailMap(time).values(); --- 85,160 ---- private Hashtable<String,PositionDTO> positionHash; private TreeMap<Long ,String> timeMap; + private Hashtable<Long, String> idHash; protected PositionCacheEntry (){ ! positionHash = new Hashtable<String,PositionDTO>(60); timeMap = new TreeMap<Long ,String>(); + idHash = new Hashtable<Long, String>(60); } protected void addPosition(PositionDTO position){ ! Long id = getFirstFreeID(); ! position.setId(id); ! while(timeMap.containsKey(position.getLastModified())){ ! position.setLastModified(position.getLastModified() + 1); ! } timeMap.put(position.getLastModified(),position.getName()); + idHash.put(id,position.getName()); + positionHash.put(position.getName(),position); + + } + + protected void movePosition(Long id, int x, int y, boolean fixed){ + if(!idHash.containsKey(id)){ + return; + } + PositionDTO pos = getPosition(id); + pos.setPosX(x); + pos.setPosY(y); + pos.setFixed(fixed); + Long time = System.currentTimeMillis(); + while(timeMap.containsKey(time)){ + ++time; + } + updateTime(pos.getLastModified(), time); + pos.setLastModified(time); } + private void updateTime(Long oldTime, Long time){ + timeMap.put(time, timeMap.get(oldTime)); + timeMap.remove(oldTime); + } + + private Long getFirstFreeID() { + Long id = new Long(1); + while(idHash.containsKey(id)) + ++id; + return id; + } + protected boolean existsPosition(String name){ return positionHash.containsKey(name); } + protected PositionDTO getPosition(String name){ return positionHash.get(name); } + protected PositionDTO getPosition(Long id){ + return positionHash.get(idHash.get(id)); + } + protected void removePosition(String name){ timeMap.remove(positionHash.get(name).getLastModified()); + idHash.remove(positionHash.get(name).getId()); positionHash.remove(name); } + protected void removePosition(Long id){ + timeMap.remove(idHash.get(id)); + positionHash.remove(idHash.get(id)); + idHash.remove(id); + } + protected PositionDTO[] getPositionsSince(Long time){ Collection<String> newPositions = timeMap.tailMap(time).values(); |