📄 hashsetmap.java
字号:
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept. This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit). http://www.cs.umass.edu/~mccallum/mallet This software is provided under the terms of the Common Public License, version 1.0, as published by http://www.opensource.org. For further information, see the file `LICENSE' included with this distribution. *//** HashMap that is a Set in that it only stores one copy of each value in the Map. * @author Aron Culotta <A HREF="mailto:culotta@cs.umass.edu">culotta@cs.umass.edu</A>*/package edu.umass.cs.mallet.projects.dex.types;import java.util.*;import java.io.*;public class HashSetMap implements Serializable{ TreeSet values; HashMap map; public HashSetMap (int size) { map = new HashMap (size); values = new TreeSet (); } public HashSetMap () { this (10); } public Object put (Object key, Object value) { Object ret = map.put (key, value); values.add (value); return ret; } public void putAll (Map m) { map.putAll (m); Iterator iter = m.values().iterator(); while (iter.hasNext()) values.add (iter.next()); } public Collection values () { return values; } public Object remove (Object key) { Object v = map.remove (key); values.remove (v); return v; } public void clear () { map.clear (); values = new TreeSet (); } public boolean containsKey (Object k) { return map.containsKey (k); } public boolean containsValue (Object v) { return map.containsValue (v); } public Set entrySet () {return map.entrySet();} public Object get (Object k) {return map.get(k);} public boolean isEmpty () {return map.isEmpty();} public Set keySet () {return map.keySet();} public int size () {return map.size();} public boolean equals (Object o) {return map.equals(o);} public int hashCode () {return map.hashCode();} public String toString() {return map.toString();} public Object clone () { HashSetMap ret = new HashSetMap (); Iterator iter = keySet().iterator(); while (iter.hasNext()) { Object k = iter.next(); ret.put (k, get(k)); } return ret; } // Serialization private static final long serialVersionUID = 1; private static final int CURRENT_SERIAL_VERSION = 1; private void writeObject (ObjectOutputStream out) throws IOException { out.writeInt (CURRENT_SERIAL_VERSION); out.writeObject (map); out.writeObject (values); } private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException { int version = in.readInt (); this.map = (HashMap) in.readObject(); this.values = (TreeSet) in.readObject(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -