Class ServersHT


  • public class ServersHT
    extends Object
    This class implements a ServerDesc hashtable, which uses sid as keys.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int count
      The total number of entries in the hash table.
      private static int initialCapacity
      The default initial capacity for the hashtable: 13.
      private static int KEYS  
      private static float loadFactor
      The default load factor for the hashtable: 0.75f.
      private ServersHT.ServerDescEntry[] table
      The hash table data.
      private int threshold
      The table is rehashed each time its size exceeds this threshold.
      private static int VALUES  
    • Constructor Summary

      Constructors 
      Constructor Description
      ServersHT()
      Constructs a new, empty hashtable with the default initial capacity and load factor.
    • Field Detail

      • count

        private transient int count
        The total number of entries in the hash table.
      • initialCapacity

        private static final int initialCapacity
        The default initial capacity for the hashtable: 13.
        See Also:
        Constant Field Values
      • loadFactor

        private static final float loadFactor
        The default load factor for the hashtable: 0.75f.
        See Also:
        Constant Field Values
      • threshold

        private int threshold
        The table is rehashed each time its size exceeds this threshold.
    • Constructor Detail

      • ServersHT

        public ServersHT()
        Constructs a new, empty hashtable with the default initial capacity and load factor.
    • Method Detail

      • size

        public int size()
        Returns the number of entries in this hashtable.
        Returns:
        the number of entries in this hashtable.
      • keys

        public Enumeration<Short> keys()
        Returns an enumeration of the keys (server id.) in this hashtable.
        Returns:
        an enumeration of the keys in this hashtable.
        See Also:
        Enumeration
      • elements

        public Enumeration<ServerDesc> elements()
        Returns an enumeration of the server descriptors in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.
        Returns:
        an enumeration of the values in this hashtable.
        See Also:
        Enumeration
      • get

        public ServerDesc get​(short sid)
        Returns the descriptor of the corresponding server.
        Parameters:
        sid - The server unique identification.
        Returns:
        the descriptor of the corresponding server.
      • rehash

        protected void rehash()
        Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
      • put

        public ServerDesc put​(ServerDesc desc)
        Maps the specified desc in this hashtable. The descriptor can be retrieved by calling the get method with a key that is equal to the server id.
        Parameters:
        desc - the descriptor.
        Returns:
        the previous value of the descriptor, or null if it did not have one.
        Throws:
        NullPointerException - if the descriptor is null.
      • remove

        public ServerDesc remove​(short sid)
        Removes the descriptor from this hashtable. This method does nothing if the key is not in the hashtable.
        Parameters:
        sid - the id of server that needs to be removed.
        Returns:
        the descriptor of the server or null if it is not defined.
      • clear

        public void clear()
        Clears this hashtable so that it contains no descriptors.
      • toString

        public String toString()
        Returns a string representation of this Hashtable object.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this hashtable.