Project

General

Profile

Download (2.21 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.strategy.cache;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13

    
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.ref.TypedEntityReference;
17

    
18
/**
19
 * @author a.kohlbecker
20
 * @since Jul 12, 2018
21
 */
22
public class TaggedTextBuilder {
23

    
24
    public static TaggedTextBuilder NewInstance(){
25
        return new TaggedTextBuilder();
26
    }
27

    
28
    private List<TaggedText> taggedText = new ArrayList<>();
29

    
30
    public void add(TagEnum type, String text){
31
        taggedText.add(new TaggedText(type, text));
32
    }
33

    
34
    /**
35
     * @see TagEnum#separator
36
     */
37
    public void addSeparator(String separator) {
38
        taggedText.add(TaggedText.NewSeparatorInstance(separator));
39
    }
40

    
41
    /**
42
     * @see TagEnum#postSeparator
43
     */
44
    public void addPostSeparator(String separator) {
45
        taggedText.add(TaggedText.NewPostSeparatorInstance(separator));
46
    }
47

    
48
    public void addWhitespace() {
49
        taggedText.add(TaggedText.NewWhitespaceInstance());
50
    }
51

    
52

    
53
    public void add(TagEnum type, String text, TypedEntityReference<?> entityReference){
54
        taggedText.add(new TaggedText(type, text, entityReference));
55
    }
56

    
57
    public void add(TagEnum type, String text, CdmBase entity){
58
        CdmBase deproxiedEntity = HibernateProxyHelper.deproxy(entity);
59
        taggedText.add(new TaggedText(type, text, new TypedEntityReference<>(deproxiedEntity.getClass(), deproxiedEntity.getUuid())));
60
    }
61

    
62
    public void  clear() {
63
        taggedText.clear();
64
    }
65

    
66
    public void addAll(TaggedTextBuilder ttb) {
67
        taggedText.addAll(ttb.taggedText);
68
    }
69

    
70
    public void addAll(List<TaggedText> tags) {
71
        taggedText.addAll(tags);
72
    }
73

    
74
    public List<TaggedText> getTaggedText() {
75
        return taggedText;
76
    }
77

    
78
    public int size(){
79
        return taggedText.size();
80
    }
81

    
82
    @Override
83
    public String toString(){
84
        return TaggedCacheHelper.createString(taggedText);
85
    }
86
}
(5-5/5)