Example #1
0
        public override E Put(E element)
        {
            //validate element
            if (element == null)
            {
                throw new ArgumentNullException("Null element is not supported.");
            }
            if (!(element is LightWeightGSet.LinkedElement))
            {
                throw new HadoopIllegalArgumentException("!(element instanceof LinkedElement), element.getClass()="
                                                         + element.GetType());
            }
            LightWeightGSet.LinkedElement e = (LightWeightGSet.LinkedElement)element;
            //find index
            int index = GetIndex(element);
            //remove if it already exists
            E existing = Remove(index, element);

            //insert the element to the head of the linked list
            modification++;
            size++;
            e.SetNext(entries[index]);
            entries[index] = e;
            return(existing);
        }
Example #2
0
 public override void Remove()
 {
     this.EnsureNext();
     if (this.cur == null)
     {
         throw new InvalidOperationException("There is no current element " + "to remove");
     }
     this._enclosing._enclosing.Remove((K)this.cur);
     this.iterModification++;
     this.cur = null;
 }
Example #3
0
 public override E Next()
 {
     this.EnsureNext();
     if (this.next == null)
     {
         throw new InvalidOperationException("There are no more elements");
     }
     this.cur  = this.next;
     this.next = null;
     return(this._enclosing.Convert(this.cur));
 }
Example #4
0
 /// <summary>Print detailed information of this object.</summary>
 public virtual void PrintDetails(TextWriter @out)
 {
     @out.Write(this + ", entries = [");
     for (int i = 0; i < entries.Length; i++)
     {
         if (entries[i] != null)
         {
             LightWeightGSet.LinkedElement e = entries[i];
             @out.Write("\n  " + i + ": " + e);
             for (e = e.GetNext(); e != null; e = e.GetNext())
             {
                 @out.Write(" -> " + e);
             }
         }
     }
     @out.WriteLine("\n]");
 }
Example #5
0
 /// <summary>
 /// Remove the element corresponding to the key,
 /// given key.hashCode() == index.
 /// </summary>
 /// <returns>
 /// If such element exists, return it.
 /// Otherwise, return null.
 /// </returns>
 private E Remove(int index, K key)
 {
     if (entries[index] == null)
     {
         return(null);
     }
     else
     {
         if (entries[index].Equals(key))
         {
             //remove the head of the linked list
             modification++;
             size--;
             LightWeightGSet.LinkedElement e = entries[index];
             entries[index] = e.GetNext();
             e.SetNext(null);
             return(Convert(e));
         }
         else
         {
             //head != null and key is not equal to head
             //search the element
             LightWeightGSet.LinkedElement prev = entries[index];
             for (LightWeightGSet.LinkedElement curr = prev.GetNext(); curr != null;)
             {
                 if (curr.Equals(key))
                 {
                     //found the element, remove it
                     modification++;
                     size--;
                     prev.SetNext(curr.GetNext());
                     curr.SetNext(null);
                     return(Convert(curr));
                 }
                 else
                 {
                     prev = curr;
                     curr = curr.GetNext();
                 }
             }
             //element not found
             return(null);
         }
     }
 }
Example #6
0
        public override E Get(K key)
        {
            //validate key
            if (key == null)
            {
                throw new ArgumentNullException("key == null");
            }
            //find element
            int index = GetIndex(key);

            for (LightWeightGSet.LinkedElement e = entries[index]; e != null; e = e.GetNext())
            {
                if (e.Equals(key))
                {
                    return(Convert(e));
                }
            }
            //element not found
            return(null);
        }
Example #7
0
 private void EnsureNext()
 {
     if (this.trackModification && this._enclosing.modification != this.iterModification)
     {
         throw new ConcurrentModificationException("modification=" + this._enclosing.modification
                                                   + " != iterModification = " + this.iterModification);
     }
     if (this.next != null)
     {
         return;
     }
     if (this.cur == null)
     {
         return;
     }
     this.next = this.cur.GetNext();
     if (this.next == null)
     {
         this.next = this.NextNonemptyEntry();
     }
 }
 public virtual void SetNext(LightWeightGSet.LinkedElement next)
 {
     this.nextLinkedElement = next;
 }
Example #9
0
 public virtual void SetNext(LightWeightGSet.LinkedElement e)
 {
     next = e;
 }
Example #10
0
 internal TestElement(int val)
 {
     this.val  = val;
     this.next = null;
 }
Example #11
0
        private E Convert(LightWeightGSet.LinkedElement e)
        {
            E r = (E)e;

            return(r);
        }
Example #12
0
 public void SetNext(LightWeightGSet.LinkedElement next)
 {
     // LightWeightGSet.LinkedElement
     this.nextElement = next;
 }