gt:             newValue = ( _values[index] = put_amount );
context: ///////////////////////////////////////////////////////////////////////////////
  // Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
  // Copyright (c) 2009, Rob Eden All Rights Reserved.
  // Copyright (c) 2009, Jeff Randall All Rights Reserved.
  //
  // This library is free software; you can redistribute it and/or
  // modify it under the terms of the GNU Lesser General Public
  // License as published by the Free Software Foundation; either
  // version 2.1 of the License, or (at your option) any later version.
  //
  // This library is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU Lesser General Public
  // License along with this program; if not, write to the Free Software
  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  ///////////////////////////////////////////////////////////////////////////////
  
  package main.java.gnu.trove.map.hash;
  
  
  //////////////////////////////////////////////////
  // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
  //////////////////////////////////////////////////
  
  
  import java.io.*;
  import java.util.*;
  
  import main.java.gnu.trove.*;
  import main.java.gnu.trove.function.TShortFunction;
  import main.java.gnu.trove.impl.HashFunctions;
  import main.java.gnu.trove.impl.hash.*;
  import main.java.gnu.trove.iterator.*;
  import main.java.gnu.trove.iterator.hash.*;
  import main.java.gnu.trove.map.TCharShortMap;
  import main.java.gnu.trove.procedure.*;
  import main.java.gnu.trove.set.*;
  
  /**
   * An open addressed Map implementation for char keys and short values.
   *
   * @author Eric D. Friedman
   * @author Rob Eden
   * @author Jeff Randall
   * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden Exp $
   */
  public class TCharShortHashMap extends TCharShortHash implements TCharShortMap, Externalizable {
      static final long serialVersionUID = 1L;
  
      /** the values of the map */
      protected transient short[] _values;
  
  
      /**
       * Creates a new <code>TCharShortHashMap</code> instance with the default
       * capacity and load factor.
       */
      public TCharShortHashMap() {
          super();
      }
  
  
      /**
       * Creates a new <code>TCharShortHashMap</code> instance with a prime
       * capacity equal to or greater than <tt>initialCapacity</tt> and
       * with the default load factor.
       *
       * @param initialCapacity an <code>int</code> value
       */
      public TCharShortHashMap( int initialCapacity ) {
          super( initialCapacity );
      }
  
  
      /**
       * Creates a new <code>TCharShortHashMap</code> instance with a prime
       * capacity equal to or greater than <tt>initialCapacity</tt> and
       * with the specified load factor.
       *
       * @param initialCapacity an <code>int</code> value
       * @param loadFactor a <code>float</code> value
       */
      public TCharShortHashMap( int initialCapacity, float loadFactor ) {
          super( initialCapacity, loadFactor );
      }
  
  
      /**
       * Creates a new <code>TCharShortHashMap</code> instance with a prime
       * capacity equal to or greater than <tt>initialCapacity</tt> and
       * with the specified load factor.
       *
       * @param initialCapacity an <code>int</code> value
       * @param loadFactor a <code>float</code> value
       * @param noEntryKey a <code>char</code> value that represents
       *                   <tt>null</tt> for the Key set.
       * @param noEntryValue a <code>short</code> value that represents
       *                   <tt>null</tt> for the Value set.
       */
      public TCharShortHashMap( int initialCapacity, float loadFactor,
          char noEntryKey, short noEntryValue ) {
          super( initialCapacity, loadFactor, noEntryKey, noEntryValue );
      }
  
  
      /**
       * Creates a new <code>TCharShortHashMap</code> instance containing
       * all of the entries in the map passed in.
       *
       * @param keys a <tt>char</tt> array containing the keys for the matching values.
       * @param values a <tt>short</tt> array containing the values.
       */
      public TCharShortHashMap( char[] keys, short[] values ) {
          super( Math.max( keys.length, values.length ) );
  
          int size = Math.min( keys.length, values.length );
          for ( int i = 0; i < size; i++ ) {
              this.put( keys[i], values[i] );
          }
      }
  
  
      /**
       * Creates a new <code>TCharShortHashMap</code> instance containing
       * all of the entries in the map passed in.
       *
       * @param map a <tt>TCharShortMap</tt> that will be duplicated.
       */
      public TCharShortHashMap( TCharShortMap map ) {
          super( map.size() );
          if ( map instanceof TCharShortHashMap ) {
              TCharShortHashMap hashmap = ( TCharShortHashMap ) map;
              this._loadFactor = hashmap._loadFactor;
              this.no_entry_key = hashmap.no_entry_key;
              this.no_entry_value = hashmap.no_entry_value;
              //noinspection RedundantCast
              if ( this.no_entry_key != ( char ) 0 ) {
                  Arrays.fill( _set, this.no_entry_key );
              }
              //noinspection RedundantCast
              if ( this.no_entry_value != ( short ) 0 ) {
                  Arrays.fill( _values, this.no_entry_value );
              }
              setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
          }
          putAll( map );
      }
  
  
      /**
       * initializes the hashtable to a prime capacity which is at least
       * <tt>initialCapacity + 1</tt>.
       *
       * @param initialCapacity an <code>int</code> value
       * @return the actual capacity chosen
       */
      protected int setUp( int initialCapacity ) {
          int capacity;
  
          capacity = super.setUp( initialCapacity );
          _values = new short[capacity];
          return capacity;
      }
  
  
      /**
       * rehashes the map to the new capacity.
       *
       * @param newCapacity an <code>int</code> value
       */
       /** {@inheritDoc} */
      protected void rehash( int newCapacity ) {
          int oldCapacity = _set.length;
          
          char oldKeys[] = _set;
          short oldVals[] = _values;
          byte oldStates[] = _states;
  
          _set = new char[newCapacity];
          _values = new short[newCapacity];
          _states = new byte[newCapacity];
  
          for ( int i = oldCapacity; i-- > 0; ) {
              if( oldStates[i] == FULL ) {
                  char o = oldKeys[i];
                  int index = insertKey( o );
                  _values[index] = oldVals[i];
              }
          }
      }
  
  
      /** {@inheritDoc} */
      public short put( char key, short value ) {
          int index = insertKey( key );
          return doPut( key, value, index );
      }
  
  
      /** {@inheritDoc} */
      public short putIfAbsent( char key, short value ) {
          int index = insertKey( key );
          if (index < 0)
              return _values[-index - 1];
          return doPut( key, value, index );
      }
  
  
      private short doPut( char key, short value, int index ) {
          short previous = no_entry_value;
          boolean isNewMapping = true;
          if ( index < 0 ) {
              index = -index -1;
              previous = _values[index];
              isNewMapping = false;
          }
          _values[index] = value;
  
          if (isNewMapping) {
              postInsertHook( consumeFreeSlot );
          }
  
          return previous;
      }
  
  
      /** {@inheritDoc} */
      public void putAll( Map<? extends Character, ? extends Short> map ) {
          ensureCapacity( map.size() );
          // could optimize this for cases when map instanceof THashMap
          for ( Map.Entry<? extends Character, ? extends Short> entry : map.entrySet() ) {
              this.put( entry.getKey().charValue(), entry.getValue().shortValue() );
          }
      }
      
  
      /** {@inheritDoc} */
      public void putAll( TCharShortMap map ) {
          ensureCapacity( map.size() );
          TCharShortIterator iter = map.iterator();
          while ( iter.hasNext() ) {
              iter.advance();
              this.put( iter.key(), iter.value() );
          }
      }
  
  
      /** {@inheritDoc} */
      public short get( char key ) {
          int index = index( key );
          return index < 0 ? no_entry_value : _values[index];
      }
  
  
      /** {@inheritDoc} */
      public void clear() {
          super.clear();
          Arrays.fill( _set, 0, _set.length, no_entry_key );
          Arrays.fill( _values, 0, _values.length, no_entry_value );
          Arrays.fill( _states, 0, _states.length, FREE );
      }
  
  
      /** {@inheritDoc} */
      public boolean isEmpty() {
          return 0 == _size;
      }
  
  
      /** {@inheritDoc} */
      public short remove( char key ) {
          short prev = no_entry_value;
          int index = index( key );
          if ( index >= 0 ) {
              prev = _values[index];
              removeAt( index );    // clear key,state; adjust size
          }
          return prev;
      }
  
  
      /** {@inheritDoc} */
      protected void removeAt( int index ) {
          _values[index] = no_entry_value;
          super.removeAt( index );  // clear key, state; adjust size
      }
  
  
      /** {@inheritDoc} */
      public TCharSet keySet() {
          return new TKeyView();
      }
  
  
      /** {@inheritDoc} */
      public char[] keys() {
          char[] keys = new char[size()];
          if ( keys.length == 0 ) {
              return keys;        // nothing to copy
          }
          char[] k = _set;
          byte[] states = _states;
  
          for ( int i = k.length, j = 0; i-- > 0; ) {
            if ( states[i] == FULL ) {
              keys[j++] = k[i];
            }
          }
          return keys;
      }
  
  
      /** {@inheritDoc} */
      public char[] keys( char[] array ) {
          int size = size();
          if ( size == 0 ) {
              return array;       // nothing to copy
          }
          if ( array.length < size ) {
              array = new char[size];
          }
  
          char[] keys = _set;
          byte[] states = _states;
  
          for ( int i = keys.length, j = 0; i-- > 0; ) {
            if ( states[i] == FULL ) {
              array[j++] = keys[i];
            }
          }
          return array;
      }
  
  
      /** {@inheritDoc} */
      public TShortCollection valueCollection() {
          return new TValueView();
      }
  
  
      /** {@inheritDoc} */
      public short[] values() {
          short[] vals = new short[size()];
          if ( vals.length == 0 ) {
              return vals;        // nothing to copy
          }
          short[] v = _values;
          byte[] states = _states;
  
          for ( int i = v.length, j = 0; i-- > 0; ) {
            if ( states[i] == FULL ) {
              vals[j++] = v[i];
            }
          }
          return vals;
      }
  
  
      /** {@inheritDoc} */
      public short[] values( short[] array ) {
          int size = size();
          if ( size == 0 ) {
              return array;       // nothing to copy
          }
          if ( array.length < size ) {
              array = new short[size];
          }
  
          short[] v = _values;
          byte[] states = _states;
  
          for ( int i = v.length, j = 0; i-- > 0; ) {
            if ( states[i] == FULL ) {
              array[j++] = v[i];
            }
          }
          return array;
      }
  
  
      /** {@inheritDoc} */
      public boolean containsValue( short val ) {
          byte[] states = _states;
          short[] vals = _values;
  
          for ( int i = vals.length; i-- > 0; ) {
              if ( states[i] == FULL && val == vals[i] ) {
                  return true;
              }
          }
          return false;
      }
  
  
      /** {@inheritDoc} */
      public boolean containsKey( char key ) {
          return contains( key );
      }
  
  
      /** {@inheritDoc} */
      public TCharShortIterator iterator() {
          return new TCharShortHashIterator( this );
      }
  
  
      /** {@inheritDoc} */
      public boolean forEachKey( TCharProcedure procedure ) {
          return forEach( procedure );
      }
  
  
      /** {@inheritDoc} */
      public boolean forEachValue( TShortProcedure procedure ) {
          byte[] states = _states;
          short[] values = _values;
          for ( int i = values.length; i-- > 0; ) {
              if ( states[i] == FULL && ! procedure.execute( values[i] ) ) {
                  return false;
              }
          }
          return true;
      }
  
  
      /** {@inheritDoc} */
      public boolean forEachEntry( TCharShortProcedure procedure ) {
          byte[] states = _states;
          char[] keys = _set;
          short[] values = _values;
          for ( int i = keys.length; i-- > 0; ) {
              if ( states[i] == FULL && ! procedure.execute( keys[i], values[i] ) ) {
                  return false;
              }
          }
          return true;
      }
  
  
      /** {@inheritDoc} */
      public void transformValues( TShortFunction function ) {
          byte[] states = _states;
          short[] values = _values;
          for ( int i = values.length; i-- > 0; ) {
              if ( states[i] == FULL ) {
                  values[i] = function.execute( values[i] );
              }
          }
      }
  
  
      /** {@inheritDoc} */
      public boolean retainEntries( TCharShortProcedure procedure ) {
          boolean modified = false;
          byte[] states = _states;
          char[] keys = _set;
          short[] values = _values;
  
  
          // Temporarily disable compaction. This is a fix for bug #1738760
          tempDisableAutoCompaction();
          try {
              for ( int i = keys.length; i-- > 0; ) {
                  if ( states[i] == FULL && ! procedure.execute( keys[i], values[i] ) ) {
                      removeAt( i );
                      modified = true;
                  }
              }
          }
          finally {
              reenableAutoCompaction( true );
          }
  
          return modified;
      }
  
  
      /** {@inheritDoc} */
      public boolean increment( char key ) {
          return adjustValue( key, ( short ) 1 );
      }
  
  
      /** {@inheritDoc} */
      public boolean adjustValue( char key, short amount ) {
          int index = index( key );
          if (index < 0) {
              return false;
          } else {
              _values[index] += amount;
              return true;
          }
      }
  
  
      /** {@inheritDoc} */
      public short adjustOrPutValue( char key, short adjust_amount, short put_amount ) {
          int index = insertKey( key );
          final boolean isNewMapping;
          final short newValue;
          if ( index < 0 ) {
              index = -index -1;
              newValue = ( _values[index] += adjust_amount );
              isNewMapping = false;
          } else {
  