EMMA Coverage Report (generated Mon Aug 23 17:21:34 CEST 2010)
[all classes][dmg.cells.nucleus]

COVERAGE SUMMARY FOR SOURCE FILE [CellPath.java]

nameclass, %method, %block, %line, %
CellPath.java100% (1/1)52%  (16/31)37%  (247/662)38%  (45.2/118)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CellPath100% (1/1)52%  (16/31)37%  (247/662)38%  (45.2/118)
CellPath (CellPath): void 0%   (0/1)0%   (0/31)0%   (0/9)
add (CellPath): void 0%   (0/1)0%   (0/7)0%   (0/2)
add (String, String): void 0%   (0/1)0%   (0/8)0%   (0/2)
equals (Object): boolean 0%   (0/1)0%   (0/58)0%   (0/10)
getCellDomainName (): String 0%   (0/1)0%   (0/10)0%   (0/2)
hashCode (): int 0%   (0/1)0%   (0/21)0%   (0/4)
insert (CellAddressCore): void 0%   (0/1)0%   (0/15)0%   (0/3)
insert (String): void 0%   (0/1)0%   (0/18)0%   (0/4)
insert (String, String): void 0%   (0/1)0%   (0/8)0%   (0/2)
main (String []): void 0%   (0/1)0%   (0/34)0%   (0/7)
mark (): void 0%   (0/1)0%   (0/12)0%   (0/3)
next (): boolean 0%   (0/1)0%   (0/18)0%   (0/3)
replaceCurrent (CellAddressCore): void 0%   (0/1)0%   (0/22)0%   (0/4)
reset (): void 0%   (0/1)0%   (0/19)0%   (0/6)
toSmallString (): String 0%   (0/1)0%   (0/110)0%   (0/11)
toFullString (): String 100% (1/1)79%  (60/76)85%  (10.2/12)
getCellName (): String 100% (1/1)80%  (8/10)90%  (1.8/2)
toFirstDestination (): void 100% (1/1)80%  (8/10)90%  (1.8/2)
isFirstDestination (): boolean 100% (1/1)86%  (6/7)85%  (0.8/1)
getCurrent (): CellAddressCore 100% (1/1)91%  (20/22)67%  (2/3)
isFinalDestination (): boolean 100% (1/1)92%  (11/12)91%  (0.9/1)
CellPath (): void 100% (1/1)100% (17/17)100% (5/5)
CellPath (String): void 100% (1/1)100% (20/20)100% (7/7)
CellPath (String, String): void 100% (1/1)100% (24/24)100% (7/7)
add (CellAddressCore): void 100% (1/1)100% (12/12)100% (3/3)
add (String): void 100% (1/1)100% (18/18)100% (4/4)
clone (): Object 100% (1/1)100% (20/20)100% (5/5)
getDestinationAddress (): CellAddressCore 100% (1/1)100% (10/10)100% (1/1)
hops (): int 100% (1/1)100% (4/4)100% (1/1)
revert (): void 100% (1/1)100% (6/6)100% (3/3)
toString (): String 100% (1/1)100% (3/3)100% (1/1)

1package dmg.cells.nucleus ;
2import  java.util.* ;
3import  java.io.* ;
4/**
5  *  
6  *  The CellPath is an abstraction of the path a CellMessage is
7  *  assumed to travel. The path consists of a defined sequence of
8  *  cell hops and a current position. The last hop which might
9  *  as well be the only one, is called the FinalDestination.
10  *  At any point a new Cell Hop can be added in two ways :
11  *  <ul>
12  *  <li>At the end of the sequence. The added Cell becomes the
13  *      new FinalDestination.
14  *  <li>Insert the new Cell behind the current position. The new
15  *      Hop becomes the next hop.
16  *  </ul>
17  *  The string representation of a cell path can have the format:
18  *  <pre>
19  *    path :  &lt;addr1&gt;[:&lt;&lt;addr2&gt;[...]]
20  *    addr :  &lt;cellName&gt; | &lt;cellName@domainName&gt; | &lt;cellName@local&gt;
21  *  </pre>
22  *
23  * @author Patrick Fuhrmann
24  * @version 0.1, 15 Feb 1998
25  */
26  /*
27  */
28public class CellPath  implements Cloneable , Serializable {
29   private static final long serialVersionUID =  -4922955783102747577L;
30 
31   private List<CellAddressCore> _list     = new ArrayList<CellAddressCore>() ;
32   private List<CellAddressCore> _mark     = null ;
33   private int    _position = -1 ;
34   private int    _storage  = -1 ;
35 
36   protected CellPath(){ /* only subclasses allowed to created 'empty' paths*/}
37   protected CellPath( CellPath addr ){
38      //
39      // this only works because _list contains 
40      // immutable objects
41      //
42      _list.addAll(addr._list);
43      _position = addr._position ;
44      _storage  = addr._storage ;
45   }
46   /**
47     *  Creates a CellAddress with an initial path of &lt;path&gt;
48     *
49     *  @param path The initial cell travel path.
50     */
51   public CellPath( String path ){
52      add( path ) ;
53   }
54   public CellPath( String cellName , String domainName ){
55       add( new CellAddressCore( cellName , domainName ) ) ; ;
56   }
57   public int hops(){ return _list.size() ; }
58   synchronized void add( CellAddressCore core ){ 
59      _list.add( core ) ;
60      if( _position < 0 )_position = 0 ;
61   }
62   public synchronized void add( CellPath addr ){ 
63         _list.addAll( addr._list ) ;
64   }
65   public void add( String cell , String domain ){
66       add( new CellAddressCore( cell , domain ) ) ;
67   }
68   /**
69     *  Adds a cell path &lt;path&gt; to the end of the current path.
70     *
71     *  @param path The added cell travel path.
72     */
73   public synchronized void add( String path ){
74        StringTokenizer st = new StringTokenizer( path ,":" ) ;
75        for( ; st.hasMoreTokens() ; ){     
76           add( new CellAddressCore( st.nextToken() ) ) ;
77        }
78   }
79   /**
80     *  Creates a CellAddress with a single cell as initial destination.
81     *  The cell is represented by its name and the name of its domain.
82     *
83     *  @param cellName The name of the initial destination cell.
84     *  @param domainName The name of the initial destination cells domain.
85     */
86   public Object clone(){
87       CellPath addr = new CellPath() ;
88       addr._list.addAll(_list);
89       addr._position = _position ;
90       addr._storage  = _storage ;
91       return addr ; 
92   }
93   /**
94     *  Adds a cell path &lt;path&gt; to the end of the current path.
95     *
96     *  @param path The added cell travel path.
97     */
98   synchronized void insert( CellAddressCore core ){ 
99      _list.add(_position + 1, core) ;
100      if( _position < 0 )_position = 0 ;
101   }
102   public synchronized void insert( String path ){
103      StringTokenizer st = new StringTokenizer( path ,":" ) ;
104      for( ; st.hasMoreTokens() ; ){     
105         insert( new CellAddressCore( st.nextToken() ) ) ;
106      }
107   }
108   public void mark(){
109      _mark    = new ArrayList<CellAddressCore>(_list) ;
110      _storage = _position ;
111   }
112   public void reset(){
113      if( _mark == null )return ;
114      _list     = _mark ;
115      _position = _storage ;
116      
117      _storage = -1;
118      _mark = null;
119   }
120   public void insert( String cell , String domain ){
121       add( new CellAddressCore( cell , domain ) ) ;
122   }
123   /**
124     * Increment the current cell position by one.
125     *
126     *  @return true if the cell hops could be shifted, false if
127     *          current cell was the final destination.
128     */
129   public synchronized boolean next(){
130      if( _position >= ( _list.size() - 1 ) )return false ;
131      _position++ ;
132      return true;
133   }
134   public synchronized void toFirstDestination(){
135      _position = _list.size() == 0 ? -1 : 0 ;
136   }
137   public synchronized void revert(){
138 
139         Collections.reverse(_list);
140     toFirstDestination() ;
141   }
142   public synchronized boolean isFinalDestination(){
143      return _position >= ( _list.size() - 1 ) ;
144   }
145   public synchronized boolean isFirstDestination(){
146      return _position == 0 ;
147   }
148   CellAddressCore getCurrent(){
149     if( ( _list.size() == 0            ) ||
150         ( _position    <  0            ) || 
151          ( _position    >=_list.size()  )     )return null ; 
152     return _list.get( _position ) ;
153   }
154   public CellAddressCore getDestinationAddress(){ 
155      return _list.get(_list.size()-1);
156   }
157   void replaceCurrent( CellAddressCore core ){
158     if( ( _list.size() == 0            ) ||
159         ( _position    <  0            ) || 
160         ( _position    >=_list.size()  )     )return  ; 
161     _list.set(_position,  core ) ;
162   }
163   public String getCellName(){ 
164     CellAddressCore core = getCurrent() ;
165     return core == null ? null : core.getCellName() ; 
166   }
167   public String getCellDomainName(){ 
168     CellAddressCore core = getCurrent() ;
169     return core == null ? null : core.getCellDomainName() ; 
170   }
171   /*
172   public void wasStored(){ 
173       _storage = _list.size()-1 ; 
174   }
175   public synchronized CellAddress getPreviousStorageAddress(){
176     if( _storage < 0 )return null ;
177     CellAddress addr = new CellAddress();
178     for( int i = _list.size() -1 ; i >= _storage ; i -- )
179        addr.add( (CellAddressCore)_list.elementAt(i) ) ;
180     return addr ;
181   }
182   */
183   public String toSmallString(){
184      int size = _list.size() ;
185      if( size == 0 )return "[empty]" ;
186      if( ( _position >= size ) || ( _position < 0 ) )return "[INVALID]" ;
187      
188      CellAddressCore core = _list.get(_position) ;
189      
190      if( size == 1 ){
191         return  "["+core.toString()+"]" ;
192      }
193      
194      if( _position == 0 )
195         return  "["+core.toString()+":...("+(size-1)+")...]" ;
196      if( _position == (size-1) )
197         return  "[...("+(size-1)+")...:"+core.toString()+"]" ;
198            
199      return  "[...("+_position+")...:"+
200              core.toString()+
201              "...("+(size-_position-1)+")...]" ;
202         
203      
204   }
205   public String toString(){ return toFullString() ; }
206   public String toFullString(){
207      int size = _list.size() ;
208      if( size == 0 )return "[empty]" ;
209      if( ( _position >= size ) || ( _position < 0 ) )return "[INVALID]" ;
210      
211      StringBuilder sb = new StringBuilder() ;
212      
213      sb.append("[") ;
214      for( int i = 0 ; i < _list.size() ; i ++ ){
215         if( i > 0 )sb.append(":") ;
216         if( i == _position )sb.append(">") ;
217         if( ( _storage > -1 ) && ( i == _storage ) )sb.append("*") ;
218         sb.append(_list.get(i).toString());
219      }
220      sb.append("]") ;
221      return sb.toString();
222   }
223   public synchronized boolean equals( Object obj ){
224      if( ! ( obj instanceof CellPath ) )return false ;
225      
226      CellPath other = (CellPath)obj ;
227      synchronized( other ){ // not deadlock free
228          int s = 0 ;
229          if( ( s = _list.size() ) != other._list.size() )return false ;
230       
231          for( int i = 0 ; i < s ; i++ )
232             if( 
233               ! _list.get(i).equals(other._list.get(i)) 
234             )return false;  
235             
236          return true ;  
237      }
238   }
239   public synchronized int hashCode(){ 
240      int sum = 0 ;
241      for( CellAddressCore addr: _list ) {
242        sum += addr.hashCode() ;
243      }
244      return sum ;
245   }
246   
247   public static void main( String [] args ){
248      CellPath addr = new CellPath() ;
249      for( int i = 0 ; i < args.length ; i ++ ){
250         addr.add( args[i] ) ;
251      
252      }
253      System.out.println( addr.toFullString() ) ;
254      System.out.println( addr.toString() ) ;
255      while( addr.next() )System.out.println( addr.toString() ) ;
256   }
257 
258 
259}

[all classes][dmg.cells.nucleus]
EMMA 2.0.5312 (C) Vladimir Roubtsov