001    /*
002     * @(#)ConcurrentList.java  0.1 03/05/19
003     *
004     * Copyright (c) 2003 Arno Formella and Jose B. Gonzalez Lopez.
005     * All Rights Reserved.
006     *
007     * LGPL
008     * 
009     */
010    
011    /* a possible package location */
012    // package es.uvigo.ei.cd.java.util.concurrent;
013    
014    /**
015       Container class for elements in a concurrent list.
016    
017       Any object even null is allowed to be the content of
018       a ConcurrentItem.
019       Besides the necessary constructors,
020       the only publically available methods can get or set the content of
021       the container.
022    
023       @author  Arno Formella and José B. González López
024       @version 0.1, 05/19/03
025     */
026    public final class ConcurrentItem {
027      /**
028         The content of this item.
029       */
030      Object element=null;
031      /**
032         The link to the subsequent item in the list.
033       */
034      ConcurrentItem next=null;
035      /**
036         The link to the previous item in the list.
037       */
038      ConcurrentItem previous=null;
039      /**
040         The flag which indicates whether this item as been removed already
041         by some thread.
042       */
043      transient boolean deleted = false;
044      /**
045         The counter which counts the number of iterators currently holding this
046         item.
047       */
048      transient int iteratorCounter = 0;
049    
050      /**
051         Constructs an <it>empty</it> ConcurrentItem.
052    
053         Empty means that the content of the item is null.
054       */
055      public ConcurrentItem() {
056      }
057    
058      /**
059         Constructs a ConcurrentItem containing an object.
060    
061         If null is passed, the item will contain null as content.
062    
063         @param element the element to put as content of the item.
064       */
065      public ConcurrentItem(Object element) {
066        this.element=element;
067      }
068    
069      /**
070         Constructs a ConcurrentItem containing an object and two links to
071         the next and previous items in a ConcurrentList.
072    
073         If null is passed, the item will contain null as content.
074         @param element the element to put as content of the item.
075         @param next the item to follow this item in the ConcurrentList.
076         @param previous the item to preceed this item in the ConcurrentList.
077       */
078      ConcurrentItem(Object element, ConcurrentItem next, ConcurrentItem previous) {
079        this.element = element;
080        this.next = next;
081        this.previous = previous;
082      }
083    
084      /**
085         Changes the content of the item.
086    
087         @param element the element to put as content of the item.
088         @return the old content of the item.
089       */
090      public synchronized Object setElement(Object element) {
091        Object oldElement = this.element;
092        this.element = element;
093        return oldElement;
094      }
095    
096      /**
097         Returns the content of the item.
098    
099         @return the content of the item.
100       */
101      public synchronized Object getElement() {
102        return element;
103      }
104    }