| 1 | package ch.poole.openinghoursparser; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import static ch.poole.openinghoursparser.I18n.tr; |
| 7 | |
| 8 | /** |
| 9 | * Container for objects from the opening_hours specification |
| 10 | * |
| 11 | * @author Simon Poole |
| 12 | * |
| 13 | * Copyright (c) 2015 Simon Poole |
| 14 | * |
| 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 16 | * documentation files (the "Software"), to deal in the Software without restriction, including without |
| 17 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 18 | * Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 19 | * conditions: |
| 20 | * |
| 21 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 22 | * of the Software. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 25 | * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 26 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 27 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE " OR THE USE OR OTHER |
| 28 | * DEALINGS IN THE SOFTWARE. |
| 29 | */ |
| 30 | public enum VarDate { |
| 31 | EASTER("easter"); |
| 32 | |
| 33 | private final String name; |
| 34 | |
| 35 | /** |
| 36 | * Construct a new member of the enum |
| 37 | * |
| 38 | * @param name the name as a String |
| 39 | */ |
| 40 | VarDate(String name) { |
| 41 | this.name = name; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public String toString() { |
| 46 | return name; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get the VarDate value for a String |
| 51 | * |
| 52 | * @param varDate the VarDate as a String |
| 53 | * @return a VarDate or null |
| 54 | */ |
| 55 | public static VarDate getValue(String varDate) { |
| 56 | for (VarDate v : VarDate.values()) { |
| 57 | if (v.toString().equals(varDate)) { |
| 58 | return v; |
| 59 | } |
| 60 | } |
| 61 | throw new IllegalArgumentException(tr("invalid_variable_date", varDate)); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get list of all values as Strings |
| 66 | * |
| 67 | * @return a List with all values |
| 68 | */ |
| 69 | public static List<String> nameValues() { |
| 70 | List<String> result = new ArrayList<>(); |
| 71 | for (VarDate v : values()) { |
| 72 | result.add(v.toString()); |
| 73 | } |
| 74 | return result; |
| 75 | } |
| 76 | } |