BUG-4688: eliminate SimpleDateFormatUtil.DEFAULT_DATE_REV
[yangtools.git] / yang / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / SimpleDateFormatUtil.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.yangtools.yang.common;
10
11 import java.text.SimpleDateFormat;
12
13 public final class SimpleDateFormatUtil {
14
15     /**
16      * revision format according to Yang spec.
17      */
18     private static final String REVISION_SIMPLE_DATE = "yyyy-MM-dd";
19
20     private SimpleDateFormatUtil() {
21         throw new UnsupportedOperationException("Utility class should not be instantiated");
22     }
23
24     private static final ThreadLocal<SimpleDateFormat> REVISION_FORMAT = new ThreadLocal<SimpleDateFormat>() {
25
26         @Override
27         protected SimpleDateFormat initialValue() {
28             final SimpleDateFormat fmt = new SimpleDateFormat(REVISION_SIMPLE_DATE);
29             fmt.setLenient(false);
30             return fmt;
31         }
32
33         @Override
34         public void set(final SimpleDateFormat value) {
35             throw new UnsupportedOperationException();
36         }
37
38     };
39
40     public static SimpleDateFormat getRevisionFormat() {
41         return REVISION_FORMAT.get();
42     }
43 }