| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DataTypeManager |
|
| 1.0;1 |
| 1 | package org.jtheque.primary.utils; | |
| 2 | ||
| 3 | /* | |
| 4 | * This file is part of JTheque. | |
| 5 | * | |
| 6 | * JTheque is free software: you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation, either version 3 of the License. | |
| 9 | * | |
| 10 | * JTheque is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | import org.jtheque.core.managers.Managers; | |
| 20 | import org.jtheque.core.managers.language.ILanguageManager; | |
| 21 | ||
| 22 | import java.util.HashMap; | |
| 23 | import java.util.Map; | |
| 24 | ||
| 25 | /** | |
| 26 | * A manager for the data type. This manager enable to to bind data type to internationalization key. | |
| 27 | * | |
| 28 | * @author Baptiste Wicht | |
| 29 | */ | |
| 30 | public final class DataTypeManager { | |
| 31 | 0 | private static final Map<String, String> DATA_TYPES = new HashMap<String, String>(12); |
| 32 | ||
| 33 | /** | |
| 34 | * Construct a new DataTypeManager. | |
| 35 | */ | |
| 36 | private DataTypeManager(){ | |
| 37 | 0 | super(); |
| 38 | 0 | } |
| 39 | ||
| 40 | /** | |
| 41 | * Bind a data type to a key. | |
| 42 | * | |
| 43 | * @param dataType The data type. | |
| 44 | * @param key The internationalization key. | |
| 45 | */ | |
| 46 | public static void bindDataTypeToKey(String dataType, String key){ | |
| 47 | 0 | DATA_TYPES.put(dataType, key); |
| 48 | 0 | } |
| 49 | ||
| 50 | /** | |
| 51 | * Unbind a data type. | |
| 52 | * | |
| 53 | * @param dataType The data type to remove from binding. | |
| 54 | */ | |
| 55 | public static void unbindDataType(String dataType){ | |
| 56 | 0 | DATA_TYPES.remove(dataType); |
| 57 | 0 | } |
| 58 | ||
| 59 | /** | |
| 60 | * Return the internationalization key for a data type. | |
| 61 | * | |
| 62 | * @param dataType The data type. | |
| 63 | * | |
| 64 | * @return The internationalization for the data type. | |
| 65 | */ | |
| 66 | private static String getKeyForDataType(String dataType){ | |
| 67 | 0 | return DATA_TYPES.get(dataType); |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Return the text for a data type. | |
| 72 | * | |
| 73 | * @param dataType The data type. | |
| 74 | * | |
| 75 | * @return The internationalized text for the data type. | |
| 76 | */ | |
| 77 | public static String getTextForDataType(String dataType){ | |
| 78 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(getKeyForDataType(dataType)); |
| 79 | } | |
| 80 | } |