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
|
private List<TaggedText> taggedText = new ArrayList<>();
|
25
|
|
26
|
public void add(TagEnum type, String text){
|
27
|
taggedText.add(new TaggedText(type, text));
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* @see TagEnum#separator
|
32
|
*/
|
33
|
public void addSeparator(String separator) {
|
34
|
taggedText.add(TaggedText.NewSeparatorInstance(separator));
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* @see TagEnum#postSeparator
|
39
|
*/
|
40
|
public void addPostSeparator(String separator) {
|
41
|
taggedText.add(TaggedText.NewPostSeparatorInstance(separator));
|
42
|
}
|
43
|
|
44
|
public void addWhitespace() {
|
45
|
taggedText.add(TaggedText.NewWhitespaceInstance());
|
46
|
}
|
47
|
|
48
|
|
49
|
public void add(TagEnum type, String text, TypedEntityReference<?> entityReference){
|
50
|
taggedText.add(new TaggedText(type, text, entityReference));
|
51
|
}
|
52
|
|
53
|
public void add(TagEnum type, String text, CdmBase entity){
|
54
|
CdmBase deproxiedEntity = HibernateProxyHelper.deproxy(entity);
|
55
|
taggedText.add(new TaggedText(type, text, new TypedEntityReference<>(deproxiedEntity.getClass(), deproxiedEntity.getUuid())));
|
56
|
}
|
57
|
|
58
|
public void clear() {
|
59
|
taggedText.clear();
|
60
|
}
|
61
|
|
62
|
public void addAll(TaggedTextBuilder ttb) {
|
63
|
taggedText.addAll(ttb.taggedText);
|
64
|
}
|
65
|
|
66
|
public void addAll(List<TaggedText> tags) {
|
67
|
taggedText.addAll(tags);
|
68
|
}
|
69
|
|
70
|
public List<TaggedText> getTaggedText() {
|
71
|
return taggedText;
|
72
|
}
|
73
|
|
74
|
public int size(){
|
75
|
return taggedText.size();
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public String toString(){
|
80
|
return TaggedCacheHelper.createString(taggedText);
|
81
|
}
|
82
|
}
|