Class LimitedCapacityStack


  • public class LimitedCapacityStack
    extends java.lang.Object
    Stack with ability to keep only limited number of objects. Object is stored only if there is another object with smaller key or some capacity left.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int capacity
      Maximum number of objects that stack can keep.
      (package private) java.util.Vector keys
      Vector of keys stored in stack.
      (package private) java.util.Vector objects
      Vector of objects stored in stack.
    • Constructor Summary

      Constructors 
      Constructor Description
      LimitedCapacityStack​(int capacity)
      Creates new instance of stack with given capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Vector getKeys()
      Returns set of stored keys.
      java.util.Vector getObjects()
      Returns set of stored objects.
      void put​(java.lang.Comparable key, java.lang.Object object)
      Tries to store given object using provided key.
      • Methods inherited from class java.lang.Object

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

      • capacity

        int capacity
        Maximum number of objects that stack can keep.
      • keys

        java.util.Vector keys
        Vector of keys stored in stack.
      • objects

        java.util.Vector objects
        Vector of objects stored in stack.
    • Constructor Detail

      • LimitedCapacityStack

        public LimitedCapacityStack​(int capacity)
        Creates new instance of stack with given capacity.
        Parameters:
        capacity - Maximum number of objects to be stored in stack.
    • Method Detail

      • put

        public void put​(java.lang.Comparable key,
                        java.lang.Object object)
        Tries to store given object using provided key. If stack is not full or given key is greater than some other key, both object and key are stored in the stack. The smaller key and object are gone.
        Parameters:
        key - Key to be compared with the stored keys.
        object - Object that wants to be stored in the stack.
      • getKeys

        public java.util.Vector getKeys()
        Returns set of stored keys.
        Returns:
        All keys stored in the stack.
      • getObjects

        public java.util.Vector getObjects()
        Returns set of stored objects.
        Returns:
        All objects stored in the stack.