001    // Copyright 2007 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.hivemind.util;
016    
017    import java.util.HashMap;
018    
019    import org.apache.hivemind.ApplicationRuntimeException;
020    
021    /**
022     * Specialized map that guarantees uniqueness of key values.
023     * 
024     * @author Achim Huegen
025     */
026    public class UniqueHashMap extends HashMap
027    {
028    
029        private static final long serialVersionUID = -3961343404455706964L;
030    
031        public Object put(Object key, Object value)
032        {
033            if (containsKey(key)) {
034                throw new ApplicationRuntimeException(UtilMessages.duplicateKeyInMap(key));
035            }
036            return super.put(key, value);
037        }
038    
039    }