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

📄 bookmarksmap.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.tasks.navigation.bookmark;

import java.util.LinkedHashMap;
import java.util.Map;

import com.esri.adf.web.data.tasks.ADFTaskException;

/**
 * A Map<String,Bookmark> implementation, suitable for storing Bookmark
 * instances in a Map keyed by an arbitrary string key. Enforces certain
 * business logic so that the task cannot be misconfigured (that is the whole
 * motive for creating this class).<p/>
 * These are the business rules, the invariant, of an instance of this class:<p/>
 * <ul>
 * <li/>no null keys nor values
 * <li/>all bookmark values MUST have a spatial reference
 * </ul><p/>
 * Note: JSF refuses to call this class
 * directly, and I have NO IDEA why; specifying this class as the
 * managed-property class-type does NOT result in a CTOR of this class getting
 * called.
 */
public class BookmarksMap extends LinkedHashMap<String, Bookmark> implements
		Map<String, Bookmark> {
	private static final long serialVersionUID = 1135229122540483051L;

	/**
	 * Standard CTOR
	 */
	public BookmarksMap() {
		super();
	}

	/**
	 * Standard CTOR
	 * @param initialCapacity
	 * @param loadFactor
	 */
	public BookmarksMap(int initialCapacity, float loadFactor) {
		super(initialCapacity, loadFactor);
	}

	/**
	 * Standard CTOR
	 * @param initialCapacity
	 */
	public BookmarksMap(int initialCapacity) {
		super(initialCapacity);
	}

	/**
	 * Standard CTOR, but makes sure to enforce this class's business logic.
	 * @param m
	 */
	public BookmarksMap(Map<? extends String, ? extends Bookmark> m) {
		super();
		putAll(m); // enforces business rules
	}

	@Override
	/**
	 * Enforces some business logic: no null keys or values, all bookmarks must
	 * have spatial references
	 * 
	 * @param key
	 *            must not be null
	 * @param value
	 *            must not be null, must have a spatial reference
	 */
	public Bookmark put(String key, Bookmark value) {
		// enforce certain business rules
		if (key == null) {
			throw new ADFTaskException("null bookmark key not allowed");
		}
		if (value == null) {
			throw new ADFTaskException("null bookmark not allowed");
		}
		if (value.getSpatialReference() == null) {
			throw new ADFTaskException(
					"bookmark must have a spatial reference specified");
		}
		return super.put(key, value);
	}

	@Override
	/**
	 * Enforces business logic
	 * 
	 * @see put(String key, Bookmark value)
	 */
	public void putAll(Map<? extends String, ? extends Bookmark> m) {
		if (m == null || m.size() == 0) {
			return; // nothing to do
		}
		// we implement out own version so that we are certain that our business
		// rules can be defined in one location
		Bookmark value;
		for (String key : m.keySet()) {
			value = m.get(key);
			put(key, value);
		}
	}

}

⌨️ 快捷键说明

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