1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package com.rapiddweller.benerator.dataset;
28
29 import com.rapiddweller.common.Named;
30
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Set;
35
36
37
38
39
40
41
42
43 public class Dataset implements Named {
44
45
46
47 private final String id;
48 private final String type;
49 private final String name;
50 private final Set<Dataset> parents;
51 private final List<Dataset> subSets;
52
53
54
55
56
57
58
59
60
61 Dataset(String type, String name) {
62 if (type == null) {
63 throw new IllegalArgumentException("type is null");
64 }
65 if (name == null) {
66 throw new IllegalArgumentException("name is null");
67 }
68 this.id = type + ':' + name;
69 this.type = type;
70 this.name = name;
71 this.parents = new HashSet<>();
72 this.subSets = new ArrayList<>();
73 }
74
75
76
77
78
79
80
81
82 public String getType() {
83 return type;
84 }
85
86 @Override
87 public String getName() {
88 return name;
89 }
90
91
92
93
94
95
96 public void addParent(Dataset parent) {
97 this.parents.add(parent);
98 }
99
100
101
102
103
104
105 public Set<Dataset> getParents() {
106 return parents;
107 }
108
109
110
111
112
113
114 public void addSubSet(Dataset subSet) {
115 subSets.add(subSet);
116 subSet.addParent(this);
117 }
118
119
120
121
122
123
124 public List<Dataset> getSubSets() {
125 return subSets;
126 }
127
128
129
130
131
132
133 public boolean isAtomic() {
134 return subSets.isEmpty();
135 }
136
137
138
139
140
141
142 public List<Dataset> allAtomicSubSets() {
143 List<Dataset> atomicSubSets = new ArrayList<>();
144 for (Dataset subSet : subSets) {
145 if (subSet.getSubSets().size() == 0) {
146 atomicSubSets.add(subSet);
147 } else {
148 atomicSubSets.addAll(subSet.allAtomicSubSets());
149 }
150 }
151 return atomicSubSets;
152 }
153
154
155
156
157
158
159
160 public boolean contains(String searchedChildName) {
161 for (Dataset subSet : subSets) {
162 if (searchedChildName.equals(subSet.getName())) {
163 return true;
164 }
165 return subSet.contains(searchedChildName);
166 }
167 return false;
168 }
169
170
171
172
173 @Override
174 public String toString() {
175 return name;
176 }
177
178 @Override
179 public int hashCode() {
180 return id.hashCode();
181 }
182
183 @Override
184 public boolean equals(Object other) {
185 if (this == other) {
186 return true;
187 }
188 if (other == null || getClass() != other.getClass()) {
189 return false;
190 }
191 final Dataset"../../../../com/rapiddweller/benerator/dataset/Dataset.html#Dataset">Dataset that = (Dataset) other;
192 return this.id.equals(that.id);
193 }
194
195 }