omgraphichash.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 388 行 · 第 1/2 页
JAVA
388 行
// This requires walkin the keySet. ArrayList keysToRemove = new ArrayList(); for (Iterator it = graphicHash.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); if (entry.getValue().equals(graphic)) { keysToRemove.add(entry.getKey()); } } for (Iterator it = keysToRemove.iterator(); it.hasNext();) { graphicHash.remove(it.next()); } super.remove((OMGraphic) graphic); } if (graphicHash.containsKey(key)) { super.remove((OMGraphic) graphic); } OMGraphic previous = (OMGraphic) graphicHash.put(key, graphic); super.add((OMGraphic) graphic); return previous; } /** * Copies all of the mappings from the specified map to this map (optional * operation). The effect of this call is equivalent to that of calling * {@link #put(Object,Object) put(k, v)} on this map once for each mapping * from key <tt>k</tt> to value <tt>v</tt> in the specified map. The * behavior of this operation is unspecified if the specified map is * modified while the operation is in progress. * * @param t Mappings to be stored in this map. * * @throws UnsupportedOperationException if the <tt>putAll</tt> method is * not supported by this map. * * @throws ClassCastException if the class of a key or value in the * specified map prevents it from being stored in this map. * * @throws IllegalArgumentException some aspect of a key or value in the * specified map prevents it from being stored in this map. * @throws NullPointerException if the specified map is <tt>null</tt>, or * if this map does not permit <tt>null</tt> keys or values, and * the specified map contains <tt>null</tt> keys or values. */ public void putAll(Map map) { graphicHash.putAll(map); } /** * Removes the mapping for this key from this map if it is present (optional * operation). More formally, if this map contains a mapping from key * <tt>k</tt> to value <tt>v</tt> such that * <code>(key==null ? k==null : key.equals(k))</code>, that mapping is * removed. (The map can contain at most one such mapping.) * * <p> * Returns the value to which the map previously associated the key, or * <tt>null</tt> if the map contained no mapping for this key. (A * <tt>null</tt> return can also indicate that the map previously * associated <tt>null</tt> with the specified key if the implementation * supports <tt>null</tt> values.) The map will not contain a mapping for * the specified key once the call returns. * * @param key key whose mapping is to be removed from the map. * @return previous value associated with specified key, or <tt>null</tt> * if there was no mapping for key. * * @throws ClassCastException if the key is of an inappropriate type for * this map (optional). * @throws NullPointerException if the key is <tt>null</tt> and this map * does not permit <tt>null</tt> keys (optional). * @throws UnsupportedOperationException if the <tt>remove</tt> method is * not supported by this map. */ public Object remove(Object obj) { OMGraphic graphic = (OMGraphic) graphicHash.get(obj); super.remove(graphic); return graphicHash.remove(obj); } /** * Returns a collection view of the values contained in this map. The * collection is backed by the map, so changes to the map are reflected in * the collection, and vice-versa. If the map is modified while an iteration * over the collection is in progress (except through the iterator's own * <tt>remove</tt> operation), the results of the iteration are undefined. * The collection supports element removal, which removes the corresponding * mapping from the map, via the <tt>Iterator.remove</tt>, * <tt>Collection.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> * and <tt>clear</tt> operations. It does not support the add or * <tt>addAll</tt> operations. * * @return a collection view of the values contained in this map. */ public java.util.Collection values() { return graphicHash.values(); } /** used to displable the IllegalArgumentException during cloning */ private boolean cloningInProgress; /** * @return a duplicate list full of shallow copies of each of the OMGraphics * contained on the list. */ public synchronized Object clone() { cloningInProgress = true; OMGraphicHash omgl = (OMGraphicHash) super.clone(); omgl.graphicHash = (HashMap) graphicHash.clone(); cloningInProgress = false; return omgl; } /** * Add an OMGraphic to the GraphicList. The OMGraphic must not be null. * <p> * For OMGraphicHash this method will throw an * <code>IllegalArgumentException</code> because adding a graphic must be * done through <code>put(key,value)</code>. * <p> * * @param g the non-null OMGraphic to add * @exception IllegalArgumentException if OMGraphic is null */ public void addOMGraphic(OMGraphic g) { // Prevent adding a graphic using the OMGraphic List. // OMGraphicHash entry must be added through the Map interface. if (cloningInProgress) { super.addOMGraphic(g); return; } throw new RuntimeException("addOMGraphic() not permitted for OMGraphicHash(). Use put(key, OMGraphic) instead."); } /** * Add an OMGraphic to the list. * <p> * For OMGraphicHash this method will throw an * <code>IllegalArgumentException</code> because adding a graphic must be * done through <code>put(key,value)</code>. */ public void add(OMGraphic g) { // Prevent adding a graphic using the OMGraphic List. // OMGraphicHash entry must be added through the Map interface. if (cloningInProgress) { super.add(g); return; } throw new RuntimeException("addOMGraphic() not permitted for OMGraphicHash(). Use put(key, OMGraphic) instead."); } /** * Remove the graphic at the location number. * * <p> * For OMGraphicHash this method will throw an * <code>IllegalArgumentException</code> because removing a graphic must * be done through <code>remove(key)</code>. * * @param location the location of the OMGraphic to remove. */ public void removeOMGraphicAt(int location) { // Prevent removing a specific graphic using the OMGraphic List. // OMGraphicHash entry must be remove using remove(Object). throw new RuntimeException("removeOMGraphicAt() not permitted for OMGraphicHash(). Use remove(key) instead."); } /** * Remove the graphic. * * <p> * For OMGraphicHash this method will throw an * <code>IllegalArgumentException</code> because removing a graphic must * be done through <code>remove(key)</code>. * * @param graphic the OMGraphic object to remove. * @return true if graphic was on the list, false if otherwise. */ public boolean remove(OMGraphic graphic) { // Prevent removing a specific graphic using the OMGraphic List. // OMGraphicHash entry must be remove using remove(Object). throw new RuntimeException("remove(OMGRaphic) not permitted for OMGraphicHash(). Use remove(key) instead."); } /** * Remove all elements from the graphic list. */ public void clear() { super.clear(); graphicHash.clear(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?