001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.util;
014    
015    /**
016     * Stripped down implementation of HashMap data structure for use
017     * by core parts of the JikesRVM runtime. Consider the use of
018     * {@link ImmutableEntryHashMapRVM} when the use of the HashMap
019     * methods is limited.
020     */
021    public final class HashMapRVM<K, V> extends AbstractHashMapRVM<K, V> {
022    
023      static final class Bucket<K, V> extends AbstractBucket<K,V> {
024        private AbstractBucket<K, V> next;
025        private final K key;
026        private V value;
027    
028        Bucket(K k, V v, AbstractBucket<K, V> n) {
029          key = k;
030          value = v;
031          next = n;
032        }
033    
034        AbstractBucket<K, V> getNext() {
035          return next;
036        }
037    
038        AbstractBucket<K, V> setNext(AbstractBucket<K, V> n) {
039          next = n;
040          return this;
041        }
042    
043        K getKey() {
044          return key;
045        }
046    
047        V getValue() {
048          return value;
049        }
050    
051        void setValue(V v) {
052          value = v;
053        }
054      }
055    
056      @Override
057      AbstractBucket<K,V> createNewBucket(K key, V value, AbstractBucket<K, V> next) {
058        return new Bucket<K,V>(key, value, next);
059      }
060    
061      public HashMapRVM() {
062        super(DEFAULT_SIZE);
063      }
064    
065      public HashMapRVM(int size) {
066        super(size);
067      }
068    
069      @Override
070      protected boolean same(K k1, K k2) {
071        return k1.equals(k2);
072      }
073    
074      @Override
075      protected int hashTheKey(K key) {
076        return key.hashCode();
077      }
078    }