Example #1
0
        public override bool ContainsValue(V val)
        {
            LinkedHashMapEntry entry = head;

            if (null == val)
            {
                while (null != entry)
                {
                    if (null == entry.Value)
                    {
                        return(true);
                    }
                    entry = entry.chainForward;
                }
            }
            else
            {
                while (null != entry)
                {
                    if (val.Equals(entry.Value))
                    {
                        return(true);
                    }
                    entry = entry.chainForward;
                }
            }
            return(false);
        }
Example #2
0
        public override V Remove(K key)
        {
            LinkedHashMapEntry entry = (LinkedHashMapEntry)RemoveEntry(key);

            if (entry == null)
            {
                return(null);
            }

            LinkedHashMapEntry p = entry.chainBackward;
            LinkedHashMapEntry n = entry.chainForward;

            if (p != null)
            {
                p.chainForward = n;
            }
            else
            {
                head = n;
            }

            if (n != null)
            {
                n.chainBackward = p;
            }
            else
            {
                tail = p;
            }

            return(entry.Value);
        }
Example #3
0
        /// <summary>
        /// Creates a new LinkedHashMap instance that contians all the mappings of the given map.
        /// </summary>
        public LinkedHashMap(Map <K, V> otherMap) : base()
        {
            this.accessOrder = false;
            this.head        = null;
            this.tail        = null;

            PutAll(otherMap);
        }
Example #4
0
        protected override Entry <K, V> CreateHashedEntry(K key, int index, int hash)
        {
            LinkedHashMapEntry m = new LinkedHashMapEntry(key, hash);

            m.next             = elementData[index];
            elementData[index] = m;
            LinkEntry(m);
            return(m);
        }
Example #5
0
 public void MakeNext()
 {
     CheckConcurrentMod();
     if (!HasNext)
     {
         throw new NoSuchElementException();
     }
     currentEntry = futureEntry;
     futureEntry  = futureEntry.chainForward;
 }
Example #6
0
        protected override V PutImpl(K key, V val)
        {
            LinkedHashMapEntry entry;

            if (elementCount == 0)
            {
                head = tail = null;
            }

            if (key == null)
            {
                entry = (LinkedHashMapEntry)FindNullKeyEntry();
                if (entry == null)
                {
                    modCount++;
                    // Check if we need to remove the oldest entry. The check
                    // includes accessOrder since an accessOrder LinkedHashMap does
                    // not record the oldest member in 'head'.
                    if (++elementCount > threshold)
                    {
                        Rehash();
                    }
                    entry = (LinkedHashMapEntry)CreateHashedEntry(null, 0, 0);
                }
                else
                {
                    LinkEntry(entry);
                }
            }
            else
            {
                int hash  = key.GetHashCode();
                int index = (hash & 0x7FFFFFFF) % elementData.Length;
                entry = (LinkedHashMapEntry)FindNonNullKeyEntry(key, index, hash);
                if (entry == null)
                {
                    modCount++;
                    if (++elementCount > threshold)
                    {
                        Rehash();
                        index = (hash & 0x7FFFFFFF) % elementData.Length;
                    }
                    entry = (LinkedHashMapEntry)CreateHashedEntry(key, index, hash);
                }
                else
                {
                    LinkEntry(entry);
                }
            }

            V result = entry.Value;

            entry.Value = val;
            return(result);
        }
Example #7
0
            public override Object Clone()
            {
                LinkedHashMapEntry entry = (LinkedHashMapEntry)base.Clone();

                entry.chainBackward = chainBackward;
                entry.chainForward  = chainForward;
                LinkedHashMapEntry lnext = (LinkedHashMapEntry)entry.next;

                if (lnext != null)
                {
                    entry.next = (LinkedHashMapEntry)lnext.Clone();
                }
                return(entry);
            }
Example #8
0
        public override V Get(K key)
        {
            LinkedHashMapEntry m;

            if (key == null)
            {
                m = (LinkedHashMapEntry)FindNullKeyEntry();
            }
            else
            {
                int hash  = key.GetHashCode();
                int index = (hash & 0x7FFFFFFF) % elementData.Length;
                m = (LinkedHashMapEntry)FindNonNullKeyEntry(key, index, hash);
            }

            if (m == null)
            {
                return(null);
            }

            if (accessOrder && tail != m)
            {
                LinkedHashMapEntry p = m.chainBackward;
                LinkedHashMapEntry n = m.chainForward;
                n.chainBackward = p;
                if (p != null)
                {
                    p.chainForward = n;
                }
                else
                {
                    head = n;
                }
                m.chainForward    = null;
                m.chainBackward   = tail;
                tail.chainForward = m;
                tail = m;
            }

            return(m.Value);
        }
Example #9
0
            public void Remove()
            {
                CheckConcurrentMod();
                if (currentEntry == null)
                {
                    throw new IllegalStateException();
                }
                associatedMap.RemoveEntry(currentEntry);
                LinkedHashMapEntry   lhme = currentEntry;
                LinkedHashMapEntry   p    = lhme.chainBackward;
                LinkedHashMapEntry   n    = lhme.chainForward;
                LinkedHashMap <K, V> lhm  = associatedMap;

                if (p != null)
                {
                    p.chainForward = n;
                    if (n != null)
                    {
                        n.chainBackward = p;
                    }
                    else
                    {
                        lhm.tail = p;
                    }
                }
                else
                {
                    lhm.head = n;
                    if (n != null)
                    {
                        n.chainBackward = null;
                    }
                    else
                    {
                        lhm.tail = null;
                    }
                }
                currentEntry = null;
                expectedModCount++;
            }
Example #10
0
 public LinkedHashMapEntry(K theKey, int hash) : base(theKey, hash)
 {
     chainForward  = null;
     chainBackward = null;
 }
Example #11
0
 /// <summary>
 /// Creates a new LinkedHashMap with the given initial capacity and default load factor.
 /// </summary>
 public LinkedHashMap(int capacity) : base(capacity)
 {
     this.accessOrder = false;
     this.head        = null;
 }
Example #12
0
 public AbstractMapIterator(LinkedHashMap <K, V> parent)
 {
     this.expectedModCount = parent.modCount;
     this.futureEntry      = parent.head;
     this.associatedMap    = parent;
 }
Example #13
0
 /// <summary>
 /// Create a new empty LinkedHashMap instance.
 /// </summary>
 public LinkedHashMap() : base()
 {
     this.accessOrder = false;
     this.head        = null;
 }
Example #14
0
        protected void LinkEntry(LinkedHashMapEntry entry)
        {
            if (ReferenceEquals(tail, entry))
            {
                return;
            }

            if (head == null)
            {
                // Check if the map is empty
                head = tail = entry;
                return;
            }

            // we need to link the new entry into either the head or tail
            // of the chain depending on if the LinkedHashMap is accessOrder or not
            LinkedHashMapEntry p = entry.chainBackward;
            LinkedHashMapEntry n = entry.chainForward;

            if (p == null)
            {
                if (n != null)
                {
                    // The entry must be the head but not the tail
                    if (accessOrder)
                    {
                        head                = n;
                        n.chainBackward     = null;
                        entry.chainBackward = tail;
                        entry.chainForward  = null;
                        tail.chainForward   = entry;
                        tail                = entry;
                    }
                }
                else
                {
                    // This is a new entry
                    entry.chainBackward = tail;
                    entry.chainForward  = null;
                    tail.chainForward   = entry;
                    tail = entry;
                }
                return;
            }

            if (n == null)
            {
                // The entry must be the tail so we can't get here
                return;
            }

            // The entry is neither the head nor tail
            if (accessOrder)
            {
                p.chainForward      = n;
                n.chainBackward     = p;
                entry.chainForward  = null;
                entry.chainBackward = tail;
                tail.chainForward   = entry;
                tail = entry;
            }
        }
Example #15
0
 public override void Clear()
 {
     base.Clear();
     head = tail = null;
 }
Example #16
0
 /// <summary>
 /// Creates a new LinkedHashMap with the given initial capacity, load factor and iteration order.
 /// If order is true then the map is ordered based on the last access, and if false the map is
 /// ordered based on the order that entries are inserted.
 /// </summary>
 public LinkedHashMap(int capacity, float loadFactor, bool order) : base(capacity, loadFactor)
 {
     this.accessOrder = order;
     this.head        = null;
     this.tail        = null;
 }
Example #17
0
 public LinkedHashMapEntry(K theKey, V theValue) : base(theKey, theValue)
 {
     chainForward  = null;
     chainBackward = null;
 }