Changeset 30


Ignore:
Timestamp:
04/14/11 16:09:27 (13 years ago)
Author:
sherbold
Message:

+ added Dot output to de.ugoe.cs.eventbench.models.Trie and accessor for the Dot representation of the trie to de.ugoe.cs.eventbench.models.TrieBasedModel?

Location:
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/Trie.java

    r23 r30  
    66import java.util.Set; 
    77 
     8import de.ugoe.cs.util.StringTools; 
     9 
    810import edu.uci.ics.jung.graph.DelegateTree; 
    911import edu.uci.ics.jung.graph.Tree; 
    1012 
    11 public class Trie<T> { 
     13public class Trie<T> implements IDotCompatible { 
    1214         
    1315        private Set<T> knownSymbols; 
     
    148150        } 
    149151         
     152        public String getDotRepresentation() { 
     153                StringBuilder stringBuilder = new StringBuilder(); 
     154                stringBuilder.append("digraph model {" + StringTools.ENDLINE); 
     155                rootNode.appendDotRepresentation(stringBuilder); 
     156                stringBuilder.append('}' + StringTools.ENDLINE); 
     157                return stringBuilder.toString(); 
     158        } 
     159         
    150160        @Override 
    151161        public String toString() { 
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieBasedModel.java

    r23 r30  
    7373        } 
    7474         
     75        public String getTrieDotRepresentation() { 
     76                return trie.getDotRepresentation(); 
     77        } 
     78         
    7579        public Tree<TrieVertex, Edge> getTrieGraph() { 
    7680                return trie.getGraph(); 
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieNode.java

    r13 r30  
    2626        public TrieNode(T symbol) { 
    2727                if( symbol==null ) { 
    28                         throw new InvalidParameterException("symbol must not be null."); 
     28                        throw new InvalidParameterException("symbol must not be null. null is reserved for root node!"); 
    2929                } 
    3030                this.symbol = symbol; 
     
    120120                }                
    121121        } 
    122  
     122         
     123        void appendDotRepresentation(StringBuilder stringBuilder) { 
     124                String thisSaneId; 
     125                if( symbol==null ) { 
     126                        thisSaneId = "root"; 
     127                } else { 
     128                        thisSaneId = symbol.toString().replace("\"", "\\\"").replaceAll("[\r\n]","")+"#"+count; 
     129                } 
     130                stringBuilder.append(" " + hashCode() + " [label=\""+thisSaneId+"\"];" + StringTools.ENDLINE); 
     131                for( TrieNode<T> childNode : children ) { 
     132                        stringBuilder.append(" "+hashCode()+" -> " + childNode.hashCode() + ";" + StringTools.ENDLINE); 
     133                } 
     134                for( TrieNode<T> childNode : children ) { 
     135                        childNode.appendDotRepresentation(stringBuilder); 
     136                } 
     137        } 
    123138} 
Note: See TracChangeset for help on using the changeset viewer.