]>
git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.app.jcr/src/org/argeo/app/jcr/terms/SuiteTypology.java
1 package org
.argeo
.app
.jcr
.terms
;
3 import java
.util
.ArrayList
;
8 import org
.argeo
.app
.api
.Term
;
9 import org
.argeo
.app
.api
.Typology
;
10 import org
.argeo
.jcr
.Jcr
;
12 /** A typology. Helper to optimise {@link SuiteTermsManager} implementation. */
13 class SuiteTypology
implements Typology
{
14 private final String name
;
15 private final Node node
;
16 private boolean isFlat
= true;
18 private final List
<SuiteTerm
> subTerms
= new ArrayList
<>();
20 public SuiteTypology(Node node
) {
22 this.name
= Jcr
.getName(this.node
);
26 public String
getId() {
30 public String
getName() {
34 public Node
getNode() {
44 public boolean isFlat() {
49 public List
<SuiteTerm
> getSubTerms() {
53 public List
<SuiteTerm
> getAllTerms() {
57 List
<SuiteTerm
> terms
= new ArrayList
<>();
58 for (SuiteTerm subTerm
: subTerms
) {
60 collectSubTerms(terms
, subTerm
);
66 public Term
findTermByName(String name
) {
67 List
<SuiteTerm
> collected
= new ArrayList
<>();
68 for (SuiteTerm subTerm
: subTerms
) {
69 collectTermsByName(subTerm
, name
, collected
);
71 if (collected
.isEmpty())
73 if (collected
.size() == 1)
74 return collected
.get(0);
75 throw new IllegalArgumentException(
76 "There are " + collected
.size() + " terms with name " + name
+ " in typology " + getId());
79 private void collectTermsByName(SuiteTerm term
, String name
, List
<SuiteTerm
> collected
) {
80 if (term
.getName().equals(name
)) {
83 for (SuiteTerm subTerm
: term
.getSubTerms()) {
84 collectTermsByName(subTerm
, name
, collected
);
88 private void collectSubTerms(List
<SuiteTerm
> terms
, SuiteTerm term
) {
89 for (SuiteTerm subTerm
: term
.getSubTerms()) {
91 collectSubTerms(terms
, subTerm
);