View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe 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 MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.datamodel.common;
20  
21  import java.util.stream.Stream;
22  
23  public enum MCRISO8601Format {
24      YEAR("UUUU"),
25      YEAR_MONTH("UUUU-MM"),
26      COMPLETE("UUUU-MM-DD"),
27      COMPLETE_HH_MM(
28          "UUUU-MM-DDThh:mmTZD"),
29      COMPLETE_HH_MM_SS("UUUU-MM-DDThh:mm:ssTZD"),
30      COMPLETE_HH_MM_SS_SSS(
31          "UUUU-MM-DDThh:mm:ss.sTZD"),
32      YEAR_ERA("YYYY"),
33      YEAR_MONTH_ERA("YYYY-MM"),
34      COMPLETE_ERA(
35          "YYYY-MM-DD"),
36      COMPLETE_HH_MM_ERA(
37          "YYYY-MM-DDThh:mmTZD"),
38      COMPLETE_HH_MM_SS_ERA("YYYY-MM-DDThh:mm:ssTZD"),
39      COMPLETE_HH_MM_SS_SSS_ERA(
40          "YYYY-MM-DDThh:mm:ss.sTZD");
41  
42      private String format;
43  
44      MCRISO8601Format(String format) {
45          this.format = format;
46      }
47  
48      @Override
49      public String toString() {
50          return format;
51      }
52  
53      public static MCRISO8601Format getFormat(String format) {
54          return Stream.of(values())
55              .filter(f -> f.format.equals(format))
56              .findAny()
57              .orElse(null);
58      }
59  
60  }