Project

General

Profile

Download (4.27 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.model.description;
11

    
12

    
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.UUID;
16

    
17
import javax.persistence.Entity;
18
import javax.xml.bind.annotation.XmlAccessType;
19
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlRootElement;
21
import javax.xml.bind.annotation.XmlType;
22

    
23
import org.apache.log4j.Logger;
24
import org.hibernate.envers.Audited;
25

    
26
import eu.etaxonomy.cdm.model.common.Language;
27
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.term.TermType;
29
import eu.etaxonomy.cdm.model.term.TermVocabulary;
30

    
31
/**
32
 * This class represents measurement units such as "centimeter" or "degree
33
 * celsius".
34
 *
35
 * @author m.doering
36
 * @since 08-Nov-2007 13:06:34
37
 */
38
@XmlAccessorType(XmlAccessType.FIELD)
39
@XmlType(name = "MeasurementUnit")
40
@XmlRootElement(name = "MeasurementUnit")
41
@Entity
42
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
43
//@Indexed(index = "eu.etaxonomy.cdm.model.term.DefinedTermBase")
44
@Audited
45
public class MeasurementUnit
46
        extends DefinedTermBase<MeasurementUnit> {
47

    
48
    private static final long serialVersionUID = 4904519152652248312L;
49
	@SuppressWarnings("unused")
50
	private static final Logger logger = Logger.getLogger(MeasurementUnit.class);
51

    
52
	public static final UUID uuidMeter = UUID.fromString("8bef5055-789c-41e5-bea2-8dc2ea8ecdf6");
53
	private static final UUID uuidSecond = UUID.fromString("7cb20e73-d3c3-4290-bb55-98f7d1e76670");
54
	private static final UUID uuidMillimeter = UUID.fromString("62b0c1fd-a502-4fba-a2c7-8df004fd2b66");
55
	private static final UUID uuidMicrometer = UUID.fromString("128a5a38-6b92-45d2-8866-0d3c12a4915c");
56
	private static final UUID uuidCentimeter = UUID.fromString("950c5919-53e4-47ab-9efd-0ea86daa98ca");
57
	private static final UUID uuidPerSquareMillimeter = UUID.fromString("22e70b61-6474-4061-b0c9-49f86ef6b8ff");
58

    
59
	protected static Map<UUID, MeasurementUnit> termMap = null;
60

    
61
//********************************** Constructor *******************************************************************/
62

    
63
	//for hibernate use only
64
	@Deprecated
65
	protected MeasurementUnit(){
66
		super(TermType.MeasurementUnit);
67
	}
68

    
69
	/**
70
	 * Creates a new measurement unit with a description
71
	 * (in the {@link Language#DEFAULT() default language}), a label and a label abbreviation.
72
	 *
73
	 * @param	term  		 the string (in the default language) describing the
74
	 * 						 new measurement unit to be created
75
	 * @param	label  		 the string identifying the new measurement unit
76
	 * 						 to be created
77
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
78
	 * 						 new measurement unit to be created
79
	 * @see 				 #NewInstance()
80
	 */
81
	private MeasurementUnit(String term, String label, String labelAbbrev) {
82
		super(TermType.MeasurementUnit, term, label, labelAbbrev);
83
	}
84

    
85

    
86
	/**
87
	 * Creates a new empty measurement unit instance.
88
	 *
89
	 * @see #MeasurementUnit(String, String, String)
90
	 */
91
	public static MeasurementUnit NewInstance(){
92
		return new MeasurementUnit();
93
	}
94

    
95
	/**
96
	 * Creates a new empty measurement unit instance.
97
	 *
98
	 * @see #MeasurementUnit(String, String, String)
99
	 */
100
	public static MeasurementUnit NewInstance(String term, String label, String labelAbbrev){
101
		return new MeasurementUnit(term, label, labelAbbrev);
102
	}
103

    
104
	@Override
105
	public void resetTerms(){
106
		termMap = null;
107
	}
108

    
109
	@Override
110
	protected void setDefaultTerms(TermVocabulary<MeasurementUnit> termVocabulary) {
111
		termMap = new HashMap<>();
112
		for (MeasurementUnit term : termVocabulary.getTerms()) {
113
			termMap.put(term.getUuid(), term);
114
		}
115
	}
116

    
117
	//******************************* STATIC METHODS *****************************************
118

    
119
    protected static MeasurementUnit getTermByUuid(UUID uuid){
120
        if (termMap == null || termMap.isEmpty()){
121
            return getTermByClassAndUUID(MeasurementUnit.class, uuid);
122
        } else {
123
            return termMap.get(uuid);
124
        }
125
    }
126

    
127
    /**
128
     * Returns the "meter" unit.
129
     */
130
    public static final MeasurementUnit METER(){
131
        return getTermByUuid(uuidMeter);
132
    }
133
}
(18-18/38)