File tree Expand file tree Collapse file tree 10 files changed +186
-0
lines changed
src/main/java/io/github/timemachinelab/core Expand file tree Collapse file tree 10 files changed +186
-0
lines changed Original file line number Diff line number Diff line change 123123 <artifactId >fastjson</artifactId >
124124 <version >2.0.57</version >
125125 </dependency >
126+ <dependency >
127+ <groupId >org.projectlombok</groupId >
128+ <artifactId >lombok</artifactId >
129+ <version >1.18.30</version >
130+ <scope >provided</scope >
131+ </dependency >
126132
127133 <dependency >
128134 <groupId >com.github.ulisesbocchio</groupId >
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ import lombok .Data ;
4+
5+ @ Data
6+ public class CommonQA extends QA {
7+
8+ public CommonQA () {
9+ super (QAType .QA );
10+ }
11+
12+ private String question ;
13+
14+ private String answer ;
15+
16+
17+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ import lombok .Data ;
4+
5+ import java .util .HashMap ;
6+ import java .util .Map ;
7+
8+ @ Data
9+ public class FormQA extends QA {
10+
11+ private String question ;
12+
13+ private Map <String , String > answerMap ;
14+
15+ public FormQA () {
16+ super (QAType .FORM );
17+ answerMap = new HashMap <>();
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ public abstract class QA {
4+
5+ protected final QAType type ;
6+
7+ protected long createTime ;
8+
9+ protected long updateTime ;
10+
11+ public QA (QAType type ) {
12+ this .type = type ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ public enum QAType {
4+
5+ QA ("QA" ),
6+ SELECTION ("Selection" ),
7+ FORM ("Form" );
8+
9+ private String name ;
10+
11+ QAType (String name ) {
12+ this .name = name ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ import lombok .Data ;
4+ import lombok .Getter ;
5+
6+ import java .util .HashMap ;
7+ import java .util .Map ;
8+
9+ public class QaTree {
10+
11+ @ Getter
12+ private QaTreeNode root ;
13+
14+ private Map <String , QaTreeNode > nodeMap = new HashMap <>();
15+
16+ public QaTree (QaTreeNode root ) {
17+ this .root = root ;
18+ nodeMap .put (root .getId (), root );
19+ }
20+
21+ public void addNode (String parentId , QaTreeNode node ) {
22+ QaTreeNode parent = nodeMap .get (parentId );
23+ if (parent == null ) {
24+ return ;
25+ }
26+ parent .append (node );
27+ nodeMap .put (node .getId (), node );
28+ }
29+
30+ public QaTreeNode getNodeById (String id ) {
31+ return nodeMap .get (id );
32+ }
33+
34+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ @ Component
6+ public class QaTreeDomain {
7+
8+ public QaTree createTree (String userStartQuestion ) {
9+ CommonQA startQA = new CommonQA ();
10+ startQA .setQuestion (userStartQuestion );
11+ QaTreeNode startNode = new QaTreeNode (startQA );
12+
13+ return new QaTree (startNode );
14+ }
15+
16+ public QaTree appendNode (QaTree tree , String parentId , QaTreeNode node ) {
17+ tree .addNode (parentId , node );
18+ return tree ;
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ import lombok .Data ;
4+ import java .util .HashMap ;
5+ import java .util .Map ;
6+ import java .util .UUID ;
7+
8+ @ Data
9+ public class QaTreeNode {
10+
11+ private final String id ;
12+
13+ private Map <String , QaTreeNode > children ;
14+
15+ private QA qa ;
16+
17+ public QaTreeNode (QA qa ) {
18+ this .id = UUID .randomUUID ().toString ();
19+ this .children = new HashMap <>();
20+ this .qa = qa ;
21+ }
22+
23+ public void append (QA qa ) {
24+ QaTreeNode node = new QaTreeNode (qa );
25+ this .append (node );
26+ }
27+
28+ public void append (QaTreeNode node ) {
29+ children .put (node .getId (), node );
30+ }
31+
32+ public QaTreeNode getChild (String id ) {
33+ return children .get (id );
34+ }
35+
36+ public boolean hasChild (String id ) {
37+ return children .containsKey (id );
38+ }
39+
40+ public void removeChild (String id ) {
41+ children .remove (id );
42+ }
43+
44+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .qatree ;
2+
3+ public class SelectionQA extends QA {
4+
5+ public SelectionQA () {
6+ super (QAType .SELECTION );
7+ }
8+
9+ private String question ;
10+
11+ private String [] options ;
12+
13+ private Integer selectedOption ;
14+ }
Original file line number Diff line number Diff line change 1+ package io .github .timemachinelab .core .session ;
2+
3+ public class Session {
4+ }
You can’t perform that action at this time.
0 commit comments