Class ElsaStack.IdentityArray

  • Enclosing class:
    ElsaStack

    public static final class ElsaStack.IdentityArray
    extends ElsaStack
    uses array with linear identity (==) search. Uses little memory, but performance degrades fast with number of objects on stack
    • Field Detail

      • size

        private int size
      • data

        private java.lang.Object[] data
      • forwardRefs

        public boolean forwardRefs
    • Constructor Detail

      • IdentityArray

        public IdentityArray()
    • Method Detail

      • add

        public void add​(java.lang.Object o)
        Specified by:
        add in class ElsaStack
      • identityIndexOf

        public int identityIndexOf​(java.lang.Object obj)
        This method is reason why ArrayList is not used. Search an item in list and returns its index. It uses identity rather than 'equalsTo' One could argue that TreeMap should be used instead, but we do not expect large object trees. This search is VERY FAST compared to Maps, it does not allocate new instances or uses method calls.
        Specified by:
        identityIndexOf in class ElsaStack
        Parameters:
        obj - to find in list
        Returns:
        index of object in list or -1 if not found
      • getInstance

        public java.lang.Object getInstance​(int i)
        Specified by:
        getInstance in class ElsaStack