⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortedmap.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
字号:
//$Id: SortedMap.java,v 1.10.2.5 2003/11/06 13:49:11 oneovthafew Exp $package net.sf.hibernate.collection;import java.io.Serializable;import java.util.Iterator;import java.util.TreeMap;import java.util.Comparator;import java.util.Collection;import net.sf.hibernate.HibernateException;import net.sf.hibernate.engine.SessionImplementor;/** * A persistent wrapper for a <tt>java.util.SortedMap</tt>. Underlying * collection is a <tt>TreeMap</tt>. *  * @see java.util.TreeMap * @author <a href="mailto:doug.currie@alum.mit.edu">e</a> */public class SortedMap extends Map implements java.util.SortedMap {		private Comparator comparator;		public Serializable snapshot(BasicCollectionPersister persister) throws HibernateException {		TreeMap clonedMap = new TreeMap(comparator);		Iterator iter = map.entrySet().iterator();		while ( iter.hasNext() ) {			java.util.Map.Entry e = (java.util.Map.Entry) iter.next();			clonedMap.put( e.getKey(), persister.getElementType().deepCopy( e.getValue() ) );		}		return clonedMap;	}			public SortedMap(SessionImplementor session) {		super(session);	}		public SortedMap(SessionImplementor session, CollectionPersister persister, Comparator comparator, Serializable disassembled, Object owner)	throws HibernateException {		super(session);		this.comparator=comparator;		beforeInitialize(persister);		Serializable[] array = (Serializable[]) disassembled;		for (int i=0; i<array.length; i+=2 ) map.put(			persister.getIndexType().assemble( array[i], session, owner ),			persister.getElementType().assemble( array[i+1], session, owner )		);		setInitialized(true);	}		public void beforeInitialize(CollectionPersister persister) {		this.map = new TreeMap(comparator);	}		public void setComparator(Comparator comparator) {		this.comparator = comparator;	}		//need to distinguish between the different 2-argument constructors	/*public SortedMap(SessionImplementor session, Comparator comp) {		super(session);		this.map = new TreeMap(comp);	}*/		public SortedMap(SessionImplementor session, java.util.SortedMap map) {		super(session, map);		comparator = map.comparator();	}		public SortedMap() {} //needed for SOAP libraries, etc	/**	 * @see SortedMap#comparator()	 */	public Comparator comparator() {		return ( (java.util.SortedMap) map ).comparator();	}		/**	 * @see SortedMap#subMap(Object, Object)	 */	public java.util.SortedMap subMap(Object fromKey, Object toKey) {		read();		java.util.SortedMap m = ( (java.util.SortedMap) map ).subMap(fromKey, toKey);		return new SortedSubMap(m);	}		/**	 * @see SortedMap#headMap(Object)	 */	public java.util.SortedMap headMap(Object toKey) {		read();		java.util.SortedMap m;		m = ( (java.util.SortedMap) map ).headMap(toKey);		return new SortedSubMap(m);	}		/**	 * @see SortedMap#tailMap(Object)	 */	public java.util.SortedMap tailMap(Object fromKey) {		read();		java.util.SortedMap m;		m = ( (java.util.SortedMap) map ).tailMap(fromKey);		return new SortedSubMap(m);	}		/**	 * @see SortedMap#firstKey()	 */	public Object firstKey() {		read();		return ( (java.util.SortedMap) map ).firstKey();	}		/**	 * @see SortedMap#lastKey()	 */	public Object lastKey() {		read();		return ( (java.util.SortedMap) map ).lastKey();	}		class SortedSubMap implements java.util.SortedMap {				java.util.SortedMap map;				SortedSubMap(java.util.SortedMap m) {			this.map = m;		}		// from Map		public int size() {			return map.size();		}		public boolean isEmpty() {			return map.isEmpty();		}		public boolean containsKey(Object arg0) {			return map.containsKey(arg0);		}		public boolean containsValue(Object arg0) {			return map.containsValue(arg0) ;		}		public Object get(Object arg0) {			return map.get(arg0);		}		public Object put(Object arg0, Object arg1) {			write();			return map.put( arg0,  arg1);		}		public Object remove(Object arg0) {			write();			return map.remove( arg0);		}		public void putAll(java.util.Map arg0) {			write();			map.putAll(arg0);		}		public void clear() {			write();			map.clear();		}		public java.util.Set keySet() {			return new SetProxy( map.keySet() );		}		public Collection values() {			return new SetProxy( map.values() );		}		public java.util.Set entrySet() {			return new EntrySetProxy( map.entrySet() );		}		// from SortedMap		public Comparator comparator() {			return map.comparator();		}		public java.util.SortedMap subMap(Object fromKey, Object toKey) {			java.util.SortedMap m;			m = map.subMap(fromKey, toKey);			return new SortedSubMap( m );		}		public java.util.SortedMap headMap(Object toKey) {			java.util.SortedMap m;			m = map.headMap(toKey);			return new SortedSubMap(m);		}		public java.util.SortedMap tailMap(Object fromKey) {			java.util.SortedMap m;			m = map.tailMap(fromKey);			return new SortedSubMap(m);		}		public Object firstKey() {			return  map.firstKey();		}		public Object lastKey() {			return map.lastKey();		}			}}

⌨️ 快捷键说明

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