我有一个里面有图表的课程.我迭代图形并创建一个构建图形的字符串,然后我将该字符串写入Java文件.有没有更好的方法,我读到JDT和CodeModel,但我真的需要一些如何使用它的提示.
编辑
我正在做一个正则表达式代码生成器,到目前为止,我已将正则表达式转换为有向图中表示的DFA(使用grail库).当我有DFA时,下一步是生成一个有三个方法的类,第一个构建相同的图形(DFA),第二个方法从一个节点移动到另一个节点,第三个方法匹配输入字符串是否被接受.只有第一种方法根据regularrexpression输入而改变,另外两种方法是静态的,并且对于每个生成的java类都是相同的.
我基于字符串的方法如下:
import grail.interfaces.DirectedEdgeInterface;
import grail.interfaces.DirectedGraphInterface;
import grail.interfaces.DirectedNodeInterface;
import grail.interfaces.EdgeInterface;
import grail.iterators.EdgeIterator;
import grail.iterators.NodeIterator;
import grail.properties.GraphProperties;
import grail.setbased.SetBasedDirectedGraph;
public class ClassName {
private SetBasedDirectedGraph graph = new SetBasedDirectedGraph();
private static DirectedNodeInterface state;
private static DirectedNodeInterface currentState;
protected DirectedEdgeInterface edge;
public ClassName() {
buildGraph();
}
protected void buildGraph() {
// Creating Graph Nodes (Automaton States)
state = graph.createNode(3);
state.setProperty(GraphProperties.LABEL, "3");
state.setProperty(GraphProperties.DESCRIPTION, "null");
graph.addNode(state);
state = graph.createNode(2);
state.setProperty(GraphProperties.LABEL, "2");
state.setProperty(GraphProperties.DESCRIPTION, "null");
graph.addNode(state);
state = graph.createNode(1);
state.setProperty(GraphProperties.LABEL, "1");
state.setProperty(GraphProperties.DESCRIPTION, "Accepted");
graph.addNode(state); …Run Code Online (Sandbox Code Playgroud) 我有这样一个数组:
$my = array('hello'=>'hi', 'goodbye'=>'bye');
Run Code Online (Sandbox Code Playgroud)
如何在此数组中添加其他元素?
我试过了:
array_push($my, array('submit'=>'send'));
Run Code Online (Sandbox Code Playgroud)
如何将值添加到HashMap中?