1 29 package net.sourceforge.groboutils.mbtf.v1.engine; 30 31 32 import net.sourceforge.groboutils.mbtf.v1.IPath; 33 import net.sourceforge.groboutils.mbtf.v1.IState; 34 import net.sourceforge.groboutils.mbtf.v1.ITransition; 35 import net.sourceforge.groboutils.mbtf.v1.IPathIterator; 36 37 import org.apache.log4j.Logger; 38 39 40 47 public class PathImpl implements IPath 48 { 49 private static final Logger LOG = Logger.getLogger( PathImpl.class ); 50 51 private ITransition[] trans; 52 private IState start; 53 54 55 public PathImpl( IState startState, ITransition[] trans ) 56 { 57 if (startState == null) 58 { 59 throw new IllegalArgumentException ("no null args"); 60 } 61 62 LOG.debug("Path starting at "+startState); 63 if (trans == null) 64 { 65 LOG.debug("-- Path has no transitions"); 66 this.trans = new ITransition[0]; 67 } 68 else 69 { 70 int len = trans.length; 71 ITransition[] t = new ITransition[ len ]; 72 for (int i = 0; i < len; ++i) 73 { 74 if (trans[i] == null) 75 { 76 throw new IllegalArgumentException ( 77 "no nulls allowed in ITransition array"); 78 } 79 LOG.debug("-- transition "+i+"="+trans[i]); 81 t[i] = trans[i]; 82 } 83 this.trans = t; 84 } 85 86 this.start = startState; 87 } 88 89 90 96 public IPathIterator iterator() 97 { 98 return new PathIteratorImpl( this.trans ); 99 } 100 101 102 107 public IState getStartState() 108 { 109 return this.start; 110 } 111 112 113 120 public int size() 121 { 122 return this.trans.length; 123 } 124 125 126 134 public int getDepth() 135 { 136 int size = size(); 137 int depth; 138 if (size == 0) 139 { 140 depth = 1; 141 } 142 else 143 { 144 depth = size + 2; 145 } 146 return depth; 147 } 148 } 149 150 | Popular Tags |