Revision 7c5f89b4
Added by Katja Luther over 3 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermCollectionDto.java | ||
---|---|---|
28 | 28 |
private Set<TermDto> terms; |
29 | 29 |
|
30 | 30 |
private boolean isAllowDuplicate; |
31 |
private boolean containsDuplicates = false; |
|
31 | 32 |
private boolean isOrderRelevant; |
32 | 33 |
private boolean isFlat; |
33 | 34 |
|
... | ... | |
48 | 49 |
} |
49 | 50 |
|
50 | 51 |
public void addTerm(TermDto term){ |
52 |
if (terms == null){ |
|
53 |
terms = new HashSet<>(); |
|
54 |
} |
|
55 |
if (terms.contains(term)){ |
|
56 |
containsDuplicates = true; |
|
57 |
} |
|
51 | 58 |
terms.add(term); |
52 | 59 |
} |
53 | 60 |
|
61 |
public void removeTerm(TermDto term){ |
|
62 |
terms.remove(term); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
|
|
54 | 67 |
/** |
55 | 68 |
* @return the isAllowDuplicate |
56 | 69 |
*/ |
... | ... | |
65 | 78 |
this.isAllowDuplicate = isAllowDuplicate; |
66 | 79 |
} |
67 | 80 |
|
81 |
public boolean isContainsDuplicates() { |
|
82 |
return containsDuplicates; |
|
83 |
} |
|
84 |
|
|
85 |
public void setContainsDuplicates(boolean containsDuplicates) { |
|
86 |
this.containsDuplicates = containsDuplicates; |
|
87 |
} |
|
88 |
|
|
68 | 89 |
/** |
69 | 90 |
* @return the isOrderRelevant |
70 | 91 |
*/ |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermNodeDto.java | ||
---|---|---|
204 | 204 |
public int getIndex(TermNodeDto nodeDto) { |
205 | 205 |
int index = 0; |
206 | 206 |
for (TermNodeDto child: children){ |
207 |
if (child.getUuid().equals(nodeDto.getUuid())){ |
|
208 |
return index; |
|
207 |
if (child != null){ |
|
208 |
if (child.getUuid().equals(nodeDto.getUuid())){ |
|
209 |
return index; |
|
210 |
} |
|
209 | 211 |
} |
210 | 212 |
index++; |
211 | 213 |
} |
... | ... | |
228 | 230 |
} |
229 | 231 |
|
230 | 232 |
|
231 |
public boolean removeChild(TermNodeDto nodeDto){ |
|
233 |
public boolean removeChild(TermNodeDto nodeDto, boolean doRecursive){
|
|
232 | 234 |
int index = this.getIndex(nodeDto); |
233 | 235 |
if (index > -1){ |
234 | 236 |
this.getChildren().remove(index); |
235 | 237 |
return true; |
236 |
}else if (this.getChildren() != null && !this.getChildren().isEmpty()){ |
|
238 |
}else if (doRecursive && this.getChildren() != null && !this.getChildren().isEmpty()){
|
|
237 | 239 |
for (TermNodeDto child: children){ |
238 |
boolean result = child.removeChild(nodeDto); |
|
240 |
boolean result = child.removeChild(nodeDto, doRecursive);
|
|
239 | 241 |
if (result){ |
240 | 242 |
return true; |
241 | 243 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermTreeDto.java | ||
---|---|---|
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
public boolean removeChild(TermNodeDto nodeDto){ |
58 |
return this.root.removeChild(nodeDto); |
|
58 |
return this.root.removeChild(nodeDto, true);
|
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
public static String getTermTreeDtoSelect(){ |
Also available in: Unified diff
ref #8774: avoid NPE in termNodeDto