Project

General

Profile

« Previous | Next » 

Revision b885ae98

Added by Katja Luther almost 3 years ago

add new CharacterLabelBuilder

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/description/CharacterLabelBuilder.java
1
/**
2
* Copyright (C) 2021 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.format.description;
10

  
11
import eu.etaxonomy.cdm.model.common.Language;
12
import eu.etaxonomy.cdm.model.description.Character;
13
import eu.etaxonomy.cdm.model.term.DefinedTerm;
14
import eu.etaxonomy.cdm.model.term.Representation;
15
import eu.etaxonomy.cdm.model.term.TermNode;
16

  
17
/**
18
 * @author k.luther
19
 * @since Apr 20, 2021
20
 */
21
public class CharacterLabelBuilder {
22

  
23
    public static final CharacterLabelBuilder NewDefaultInstance(){
24
        return new CharacterLabelBuilder();
25
    }
26

  
27
    private CharacterLabelBuilder(){}
28

  
29
    public static String buildLabel(Character character, Language lang){
30
        TermNode<DefinedTerm> propertyNode = character.getProperty();
31
        TermNode<DefinedTerm> structureNode = character.getStructure();
32
        TermNode<DefinedTerm> ratioToNode = character.getRatioToStructure();
33
        Representation structureRepresentation = structureNode.getTerm().getRepresentation(lang);
34
        if(structureRepresentation==null){
35
            structureRepresentation = structureNode.getTerm().getRepresentation(Language.DEFAULT());
36
        }
37
        Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(lang);
38
        if(propertyRepresentation==null){
39
            propertyRepresentation = propertyNode.getTerm().getRepresentation(Language.DEFAULT());
40
        }
41
        String label = null;
42

  
43
        if(structureRepresentation!=null && propertyRepresentation!=null){
44
            if(structureRepresentation.getLabel()!=null && propertyRepresentation.getLabel()!=null){
45
                label = structureRepresentation.getLabel()+" "+propertyRepresentation.getLabel();
46
            }
47

  
48
        }
49
        if(label!=null){
50
            //default label
51
            label = structureNode.getTerm().getLabel()+" "+propertyNode.getTerm().getLabel();
52
        }
53
        if (character.getRatioToStructure() != null){
54
            Representation ratioToRepresentation = ratioToNode.getTerm().getRepresentation(lang);
55
            if(ratioToRepresentation==null){
56
                ratioToRepresentation = ratioToNode.getTerm().getRepresentation(Language.DEFAULT());
57
            }
58
            if(structureRepresentation!=null && propertyRepresentation!=null){
59
                if(structureRepresentation.getLabel() != null && propertyRepresentation.getLabel() != null && ratioToRepresentation.getLabel() != null){
60
                    label = propertyRepresentation.getLabel() + " ratio " +structureRepresentation.getLabel()+" to " +ratioToRepresentation.getLabel() ;
61
                }
62

  
63
            }
64
            if(label==null){
65
                //default label
66
                label = propertyNode.getTerm().getLabel()+ " ratio " +structureNode.getTerm().getLabel()+ " to " + ratioToNode.getTerm().getLabel() ;
67
            }
68
        }
69

  
70
        return label;
71
    }
72

  
73

  
74
    public static String buildAbbrevLabel(Character character, Language lang){
75
        TermNode<DefinedTerm> propertyNode = character.getProperty();
76
        TermNode<DefinedTerm> structureNode = character.getStructure();
77
        TermNode<DefinedTerm> ratioToNode = character.getRatioToStructure();
78
        Representation structureRepresentation = structureNode.getTerm().getRepresentation(lang);
79
        if(structureRepresentation==null){
80
            structureRepresentation = structureNode.getTerm().getRepresentation(Language.DEFAULT());
81
        }
82
        Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(lang);
83
        if(propertyRepresentation==null){
84
            propertyRepresentation = propertyNode.getTerm().getRepresentation(Language.DEFAULT());
85
        }
86

  
87
        String abbrevLabel = null;
88
        if(structureRepresentation!=null && propertyRepresentation!=null){
89
            if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null){
90
                abbrevLabel = structureRepresentation.getAbbreviatedLabel()+" "+propertyRepresentation.getAbbreviatedLabel();
91
            }
92
        }
93

  
94
        if (character.getRatioToStructure() != null){
95
            Representation ratioToRepresentation = ratioToNode.getTerm().getRepresentation(lang);
96
            if(ratioToRepresentation==null){
97
                ratioToRepresentation = ratioToNode.getTerm().getRepresentation(Language.DEFAULT());
98
            }
99
            if(structureRepresentation!=null && propertyRepresentation!=null){
100

  
101
                if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null && ratioToRepresentation.getAbbreviatedLabel() != null){
102
                    abbrevLabel = propertyRepresentation.getAbbreviatedLabel() + " ratio " +structureRepresentation.getAbbreviatedLabel()+ " to " + ratioToRepresentation.getAbbreviatedLabel();
103
                }
104
            }
105

  
106
        }
107

  
108
        return abbrevLabel;
109
    }
110

  
111

  
112

  
113

  
114

  
115

  
116

  
117
}

Also available in: Unified diff