Class CharVector


  • public class CharVector
    extends java.lang.Object
    This class implements a simple char vector with access to the underlying array.

    This work was authored by Carlos Villegas (cav@uniscope.co.jp).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private char[] array
      The encapsulated array
      private int blockSize  
      private static int DEFAULT_BLOCK_SIZE
      Capacity increment size
      private int n
      Points to next free item
    • Constructor Summary

      Constructors 
      Constructor Description
      CharVector()
      Construct char vector instance with default block size.
      CharVector​(char[] a)
      Construct char vector instance.
      CharVector​(char[] a, int capacity)
      Construct char vector instance.
      CharVector​(int capacity)
      Construct char vector instance.
      CharVector​(CharVector cv)
      Copy constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int alloc​(int size)
      This is to implement memory allocation in the array.
      int capacity()
      Obtain capacity of array.
      void clear()
      Reset length of vector, but don't clear contents.
      char get​(int index)
      Get char at index.
      char[] getArray()
      Obtain char vector array.
      int length()
      Obtain number of items in array.
      void put​(int index, char val)
      Pet char at index.
      void trimToSize()
      Trim char vector to current length.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_BLOCK_SIZE

        private static final int DEFAULT_BLOCK_SIZE
        Capacity increment size
        See Also:
        Constant Field Values
      • blockSize

        private int blockSize
      • array

        private char[] array
        The encapsulated array
      • n

        private int n
        Points to next free item
    • Constructor Detail

      • CharVector

        public CharVector()
        Construct char vector instance with default block size.
      • CharVector

        public CharVector​(int capacity)
        Construct char vector instance.
        Parameters:
        capacity - initial block size
      • CharVector

        public CharVector​(char[] a)
        Construct char vector instance.
        Parameters:
        a - char array to use
      • CharVector

        public CharVector​(char[] a,
                          int capacity)
        Construct char vector instance.
        Parameters:
        a - char array to use
        capacity - initial block size
      • CharVector

        public CharVector​(CharVector cv)
        Copy constructor
        Parameters:
        cv - the CharVector that should be cloned
    • Method Detail

      • clear

        public void clear()
        Reset length of vector, but don't clear contents.
      • getArray

        public char[] getArray()
        Obtain char vector array.
        Returns:
        char array
      • length

        public int length()
        Obtain number of items in array.
        Returns:
        number of items
      • capacity

        public int capacity()
        Obtain capacity of array.
        Returns:
        current capacity of array
      • put

        public void put​(int index,
                        char val)
        Pet char at index.
        Parameters:
        index - the index
        val - a char
      • get

        public char get​(int index)
        Get char at index.
        Parameters:
        index - the index
        Returns:
        a char
      • alloc

        public int alloc​(int size)
        This is to implement memory allocation in the array. Like malloc().
        Parameters:
        size - to allocate
        Returns:
        previous length
      • trimToSize

        public void trimToSize()
        Trim char vector to current length.