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

📄 typedhashtable.java

📁 定要上载质量高而定要上载质量高而定要上载质量高而定要上载质量高而定要上载质量高而
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Created on Mar 16, 2005
 */
package org.flexdock.util;

import java.util.Hashtable;
import java.util.Map;

/**
 * @author Christopher Butler
 */
public class TypedHashtable extends Hashtable {
	
    /**
     * Constructs a new, empty <code>TypedHashtable</code> with a default initial capacity (11)
     * and load factor of <code>0.75</code>. 
     */
	public TypedHashtable() {
		super();
	}

    /**
     * Constructs a new, empty <code>TypedHashtable</code> with the specified initial capacity
     * and default load factor of <code>0.75</code>.
     *
     * @param     initialCapacity   the initial capacity of the hashtable.
     * @exception IllegalArgumentException if the initial capacity is less
     *              than zero.
     */
	public TypedHashtable(int initialCapacity) {
		super(initialCapacity);
	}

    /**
     * Constructs a new, empty <code>TypedHashtable</code> with the specified initial 
     * capacity and the specified load factor.
     *
     * @param      initialCapacity   the initial capacity of the hashtable.
     * @param      loadFactor        the load factor of the hashtable.
     * @exception  IllegalArgumentException  if the initial capacity is less
     *             than zero, or if the load factor is nonpositive.
     */
	public TypedHashtable(int initialCapacity, float loadFactor) {
		super(initialCapacity, loadFactor);
	}

    /**
     * Constructs a new <code>TypedHashtable</code> with the same mappings as the given 
     * Map.  The hashtable is created with an initial capacity sufficient to
     * hold the mappings in the given Map and a default load factor of <code>0.75</code>.
     *
     * @param t the map whose mappings are to be placed in this map.
     * @throws NullPointerException if the specified map is null.
     */
	public TypedHashtable(Map t) {
		super(t);
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified boolean <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will put either
	 * <code>Boolean.TRUE</code> or <code>Boolean.FALSE</code> in the hashtable.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the boolean value to be mapped to the specified <code>key</code>.
	 * @see Boolean#TRUE
	 * @see Boolean#FALSE
	 * @see #put(Object, Object)
	 */
	public void put(Object key, boolean value) {
		Boolean b = value? Boolean.TRUE: Boolean.FALSE;
		put(key, b);
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified byte <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified byte in a <code>java.lang.Byte</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the byte value to be mapped to the specified <code>key</code>.
	 * @see Byte#Byte(byte)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, byte value) {
		put(key, new Byte(value));	
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified short <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified short in a <code>java.lang.Short</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the short value to be mapped to the specified <code>key</code>.
	 * @see Short#Short(short)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, short value) {
		put(key, new Short(value));
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified int <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified int in a <code>java.lang.Integer</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the int value to be mapped to the specified <code>key</code>.
	 * @see Integer#Integer(int)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, int value) {
		put(key, new Integer(value));
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified long <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified long in a <code>java.lang.Long</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the long value to be mapped to the specified <code>key</code>.
	 * @see Long#Long(long)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, long value) {
		put(key, new Long(value));
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified float <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified float in a <code>java.lang.Float</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the float value to be mapped to the specified <code>key</code>.
	 * @see Float#Float(float)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, float value) {
		put(key, new Float(value));
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified double <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified double in a <code>java.lang.Double</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the double value to be mapped to the specified <code>key</code>.
	 * @see Double#Double(double)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, double value) {
		put(key, new Double(value));
	}
	
	/**
	 * Maps the specified <code>key</code> to the specified char <code>value</code> in this 
	 * hashtable.  Since hashtables require <code>Object</code> values, this method will wrap the 
	 * specified char in a <code>java.lang.Character</code> before inserting.  If <code>key</code> is 
	 * <code>null</code> then this method returns with no action taken.
	 * 
	 * @param key the hashtable key.
	 * @param value the char value to be mapped to the specified <code>key</code>.
	 * @see Character#Character(char)
	 * @see #put(Object, Object)
	 */
	public void put(Object key, char value) {
		put(key, new Character(value));
	}
	
    /**
     * Maps the specified <code>key</code> to the specified 
     * <code>value</code> in this hashtable. If the <code>key</code> is <code>null</code>, then this
     * method returns with no action taken.  If the <code>value</code> is <code>null</code>, then
     * this method removes any existing mapping in the hashtable for the specified <code>key</code>
     * by calling <code>remove(Object key)</code>.
     *
     * The value can be retrieved by calling the <code>get(Object key)</code> method 
     * with a key that is equal to the original key. 
     *
     * @param key the hashtable key.
     * @param value the value.
     * @see Object#equals(Object)
     * @see #get(Object)
     * @see Hashtable#remove(java.lang.Object)
     */
	public Object put(Object key, Object value) {
		if(value==null)
			return super.remove(key);
		else
			return super.put(key, value);
	}
	
	
	
	
	
	/**
	 * Returns the boolean value associated with the specified <code>key</code> in this hashtable.
	 * This method attempts to cast the value in this hashtable for the specified <code>key</code> to
	 * a <code>java.lang.Boolean</code> and invoke its <code>booleanValue()</code> method.
	 * If the key does not exist in the hashtable, or it maps to a non-<code>Boolean</code> value, 
	 * then this method returns the specified <code>defaultValue</code>.
	 * 
	 * @param key the hashtable key
	 * @param defaultValue the value to return if a valid boolean cannot be found for the specified key
	 * @return the boolean value associated with the specified <code>key</code> in this hashtable.
	 * @see #put(Object, boolean)
	 * @see #getBoolean(Object)
	 * @see Boolean#booleanValue()
	 */
	public boolean get(Object key, boolean defaultValue) {
		Object obj = get(key);
		return obj instanceof Boolean? defaultValue: ((Boolean)obj).booleanValue();
	}
	
	/**
	 * Returns the byte value associated with the specified <code>key</code> in this hashtable.
	 * This method attempts to cast the value in this hashtable for the specified <code>key</code> to
	 * a <code>java.lang.Byte</code> and invoke its <code>byteValue()</code> method.
	 * If the key does not exist in the hashtable, or it maps to a non-<code>Byte</code> value, 
	 * then this method returns the specified <code>defaultValue</code>.
	 * 
	 * @param key the hashtable key
	 * @param defaultValue the value to return if a valid byte cannot be found for the specified key
	 * @return the byte value associated with the specified <code>key</code> in this hashtable.
	 * @see #put(Object, byte)
	 * @see #getByte(Object)
	 * @see Byte#byteValue()
	 */
	public byte get(Object key, byte defaultValue) {
		Object obj = get(key);
		return obj instanceof Byte? defaultValue: ((Byte)obj).byteValue();	
	}
	
	/**
	 * Returns the short value associated with the specified <code>key</code> in this hashtable.
	 * This method attempts to cast the value in this hashtable for the specified <code>key</code> to
	 * a <code>java.lang.Short</code> and invoke its <code>shortValue()</code> method.
	 * If the key does not exist in the hashtable, or it maps to a non-<code>Short</code> value, 
	 * then this method returns the specified <code>defaultValue</code>.
	 * 
	 * @param key the hashtable key
	 * @param defaultValue the value to return if a valid short cannot be found for the specified key
	 * @return the short value associated with the specified <code>key</code> in this hashtable.
	 * @see #put(Object, short)
	 * @see #getShort(Object)
	 * @see Short#shortValue()

⌨️ 快捷键说明

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