001/*
002 * Copyright (C) 2014 konik.io
003 *
004 * This file is part of Konik library.
005 *
006 * Konik library is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Konik library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with Konik library.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package io.konik.zugferd.unece.codes;
020
021/**
022 * = The Unit Of Measurement Enumeration
023 * 
024 * Based on Recommendation N°. 20 - Codes for Units of Measure Used in International Trade
025 * 
026 * @see http://www.unece.org/trade/untdid/d13b/tred/tred6411.htm[UN/EDIFACT 6411 Measurement unit code^]
027 * 
028 */
029public enum UnitOfMeasurement {
030
031   /** A unit of count defining the number of articles (items). */
032   ARTICLE("NAR", "A unit of count defining the number of articles (items)"),
033
034   /** A unit of count defining the number of pieces */
035   UNIT("C62", "A unit of count defining the number of pieces"),
036
037   /** A number of objects grouped together to a set */
038   SET("SET", "a number of objects grouped together"),
039
040   /** The number of pairs. */
041   PAIR("NPR", "number of pairs"),
042
043   /** The Hectare (ha). */
044   HECTARE("HAR", "Hectare (ha)"),
045
046   /** The Hour (h). */
047   HOUR("HUR", "Hour (h)"),
048
049   /** The Kilogram (kg). */
050   KILOGRAM("KGM", "Kilogram (kg)"),
051
052   /** The Kilometer (km). */
053   KILOMETER("KMT", "Kilometer (km)"),
054
055   /** The Kilowatt hour (kWh). */
056   KILOWATT_HOUR("KWH", "Kilowatt hour (kWh)"),
057
058   /** The lump sum. */
059   LUMP_SUM("LS", "lump sum"),
060
061   /** The Liter (l). */
062   LITRE("LTR", "Liter (l)"),
063
064   /** The Minute (min). */
065   MINUTE("MIN", "Minute (min)"),
066
067   /** The square millimeter (mm2). */
068   MILLIMETER_SQUARE("MMK", "square millimeter (mm2)"),
069
070   /** The Millimeter (mm). */
071   MILLIMETER("MMT", "Millimeter (mm)"),
072
073   /** The square meter (m2). */
074   METER_SQUARE("MTK", "square meter  (m2)"),
075
076   /** The cubic meter (m3). */
077   METER_CUBIC("MTQ", "cubic meter (m3)"),
078
079   /** The Meter (m). */
080   METER("MTR", "Meter (m)"),
081
082   /** The Second (s). */
083   SECOND("SEC", "Second (s)"),
084
085   /** The Percent (%). */
086   PERCENT("P1", "Percent (%)"),
087
088   /** The metric ton (t). */
089   TON_METRIC("TNE", "Metric ton (t)"),
090
091   /** The day count */
092   DAY("DAY", "days count"),
093
094   /** The week. */
095   WEEK("WEE", "Week"),
096
097   /** The Month. */
098   MONTH("MON", "Month"),
099
100   /** The Mile. 1609,344 m */
101   MILE("SMI", "International Mile");
102   
103   private final String description;
104   private final String code;
105
106   /**
107    * Instantiates a new unit types.
108    *
109    * @param code the code
110    * @param description the description
111    */
112   UnitOfMeasurement(String code, String description) {
113      this.code = code;
114      this.description = description;
115   }
116
117   /**
118    * Gets the code.
119    *
120    * @return the code
121    */
122   public String getCode() {
123      return code;
124   }
125
126   /**
127    * Gets the description.
128    *
129    * @return the description
130    */
131   public String getDescription() {
132      return description;
133   }
134
135   /**
136    * Gets the type by code.
137    *
138    * @param code the code
139    * @return the type by code
140    */
141   public static UnitOfMeasurement getByCode(String code) {
142      if (code != null) {
143         for (UnitOfMeasurement v : values()) {
144            if (v.getCode().intern() == code.intern()) { return v; }
145         }
146      }
147      return null;
148   }
149
150   @Override
151   public String toString() {
152      return new StringBuilder().append("[").append(getCode()).append("] ").append(description).toString();
153   }
154}