Project

General

Profile

Revision 8b98d482

ID8b98d482e3a0ea051b8d1505614cebbb9961ffb4
Parent 8a17aa3e
Child 576743e2

Added by Andreas Müller over 2 years ago

ref #6682 use TaggedTextBuilder

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/taxon/TaxonRelationshipFormatter.java
28 28
import eu.etaxonomy.cdm.ref.TypedEntityReference;
29 29
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
30 30
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
31
import eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder;
31 32
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
32 33

  
33 34
/**
......
69 70
        }
70 71
        TaxonName name = relatedTaxon.getName();
71 72

  
72
        List<TaggedText> tags = new ArrayList<>();
73
//        List<TaggedText> tags = new ArrayList<>();
74
        TaggedTextBuilder builder = new TaggedTextBuilder();
73 75

  
74 76
        //rel symbol
75 77
        String symbol = getSymbol(type, reverse, languages);
76
        tags.add(TaggedText.NewInstance(TagEnum.symbol, symbol));
78
        builder.add(TagEnum.symbol, symbol);
77 79

  
78 80
        //name
79 81
        if (isMisapplied){
80 82
            //starting quote
81 83
            String startQuote = QUOTE_START;
82
            tags.add(TaggedText.NewSeparatorInstance(startQuote));
84
            builder.addSeparator(startQuote);// .add(TaggedText.NewSeparatorInstance(startQuote));
83 85

  
84 86
            //name cache
85 87
            List<TaggedText> nameCacheTags = getNameCacheTags(name);
86
            tags.addAll(nameCacheTags);
88
            builder.addAll(nameCacheTags);
87 89

  
88 90
            //end quote
89 91
            String endQuote = QUOTE_END;
90
            tags.add(TaggedText.NewInstance(TagEnum.postSeparator, endQuote));
92
            builder.add(TagEnum.postSeparator, endQuote);
91 93
        }else{
92
            tags.add(TaggedText.NewWhitespaceInstance());
94
            builder.addWhitespace();
93 95
            //name full title cache
94 96
            List<TaggedText> nameCacheTags = getNameTitleCacheTags(name);
95
            tags.addAll(nameCacheTags);
97
            builder.addAll(nameCacheTags);
96 98
        }
97 99

  
98 100

  
99 101
        //sensu (+ Separatoren?)
100 102
        if (isNotBlank(relatedTaxon.getAppendedPhrase())){
101
            tags.add(TaggedText.NewWhitespaceInstance());
102
            tags.add(TaggedText.NewInstance(TagEnum.appendedPhrase, relatedTaxon.getAppendedPhrase()));
103
            builder.addWhitespace();
104
            builder.add(TagEnum.appendedPhrase, relatedTaxon.getAppendedPhrase());
103 105
        }
104 106
        List<TaggedText> secTags = getSensuTags(relatedTaxon.getSec(), relatedTaxon.getSecMicroReference(),
105 107
               /* isMisapplied,*/ false);
106 108
        if (!secTags.isEmpty()) {
107
            tags.add(TaggedText.NewSeparatorInstance(isMisapplied? SENSU_SEPARATOR : SEC_SEPARATOR));
108
            tags.addAll(secTags);
109
            builder.addSeparator(isMisapplied? SENSU_SEPARATOR : SEC_SEPARATOR);
110
            builder.addAll(secTags);
109 111
        }else if (isBlank(relatedTaxon.getAppendedPhrase())) {
110 112
            if (isMisapplied){
111
                tags.add(TaggedText.NewWhitespaceInstance());
113
                builder.addWhitespace();
112 114
                //TODO type unclear sensuReference(?)
113
                tags.add(TaggedText.NewInstance(TagEnum.appendedPhrase, AUCT));
115
                builder.add(TagEnum.appendedPhrase, AUCT);
114 116
            }else{
115
                tags.add(TaggedText.NewSeparatorInstance(SEC_SEPARATOR + UNKNOWN_SEC));
117
                builder.addSeparator(SEC_SEPARATOR + UNKNOWN_SEC);
116 118
            }
117 119
        }
118 120

  
119 121
//        //, non author
120 122
        if (isMisapplied && name != null){
121 123
            if (name.getCombinationAuthorship() != null && isNotBlank(name.getCombinationAuthorship().getNomenclaturalTitle())){
122
                tags.add(TaggedText.NewSeparatorInstance(NON_SEPARATOR));
123
                tags.add(TaggedText.NewInstance(TagEnum.authors, name.getCombinationAuthorship().getNomenclaturalTitle()));
124
                builder.addSeparator(NON_SEPARATOR);
125
                builder.add(TagEnum.authors, name.getCombinationAuthorship().getNomenclaturalTitle());
124 126
            }else if (isNotBlank(name.getAuthorshipCache())){
125
                tags.add(TaggedText.NewSeparatorInstance(NON_SEPARATOR));
126
                tags.add(TaggedText.NewInstance(TagEnum.authors, name.getAuthorshipCache().trim()));
127
                builder.addSeparator(NON_SEPARATOR);
128
                builder.add(TagEnum.authors, name.getAuthorshipCache().trim());
127 129
            }
128 130
        }
129 131

  
130 132
        List<TaggedText> relSecTags = getSensuTags(taxonRelationship.getCitation(),
131 133
                taxonRelationship.getCitationMicroReference(),true);
132 134
        if (!relSecTags.isEmpty()){
133
            TaggedText relSecSeparatorToag = TaggedText.NewSeparatorInstance(isSynonym ? SYN_SEC : isMisapplied ? ERR_SEC : REL_SEC);
134
            tags.add(relSecSeparatorToag);
135
            tags.addAll(relSecTags);
135
            builder.addSeparator(isSynonym ? SYN_SEC : isMisapplied ? ERR_SEC : REL_SEC);
136
            builder.addAll(relSecTags);
136 137
        }
137 138

  
138
        return tags;
139
        return builder.getTaggedText();
139 140
    }
140 141

  
141 142
    private List<TaggedText> getSensuTags(Reference ref, String detail, /*boolean isSensu,*/ boolean isRelation) {
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/TaggedTextBuilder.java
28 28
        taggedText.add(new TaggedText(type, text));
29 29
    }
30 30

  
31
    public void addSeparator(String separator) {
32
        taggedText.add(TaggedText.NewSeparatorInstance(separator));
33
    }
34

  
35
    public void addWhitespace() {
36
        taggedText.add(TaggedText.NewWhitespaceInstance());
37
    }
38

  
39

  
31 40
    public void add(TagEnum type, String text, TypedEntityReference<?> entityReference){
32 41
        taggedText.add(new TaggedText(type, text, entityReference));
33 42
    }
......
41 50
        taggedText.clear();
42 51
    }
43 52

  
44
    @Override
45
    public String toString(){
46
        return TaggedCacheHelper.createString(taggedText);
47
    }
48

  
49 53
    /**
50 54
     * @param workingsetBuilder
51 55
     */
52 56
    public void addAll(TaggedTextBuilder ttb) {
53 57
        taggedText.addAll(ttb.taggedText);
58
    }
54 59

  
60
    public void addAll(List<TaggedText> tags) {
61
        taggedText.addAll(tags);
55 62
    }
56 63

  
57
    /**
58
     * @return
59
     */
60 64
    public List<TaggedText> getTaggedText() {
61 65
        return taggedText;
62 66
    }
63 67

  
68

  
69
    @Override
70
    public String toString(){
71
        return TaggedCacheHelper.createString(taggedText);
72
    }
73

  
74

  
64 75
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)