BUG-4688: remove SimpleDateFormatUtil 10/64710/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 25 Oct 2017 11:50:59 +0000 (13:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 25 Oct 2017 16:53:21 +0000 (18:53 +0200)
Convert FilesystemSchemaSourceCache to use Revision and remove
SimpleDateFormatUtil as it is not used anywhere anymore.

Change-Id: Ie59921866bf84fbbe75a07cdcf3cc44f8bdafcd2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/SimpleDateFormatUtil.java [deleted file]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java

diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/SimpleDateFormatUtil.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/SimpleDateFormatUtil.java
deleted file mode 100644 (file)
index 2d8df75..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.yangtools.yang.common;
-
-import java.text.SimpleDateFormat;
-
-public final class SimpleDateFormatUtil {
-
-    /**
-     * revision format according to Yang spec.
-     */
-    private static final String REVISION_SIMPLE_DATE = "yyyy-MM-dd";
-
-    private SimpleDateFormatUtil() {
-        throw new UnsupportedOperationException("Utility class should not be instantiated");
-    }
-
-    private static final ThreadLocal<SimpleDateFormat> REVISION_FORMAT = new ThreadLocal<SimpleDateFormat>() {
-
-        @Override
-        protected SimpleDateFormat initialValue() {
-            final SimpleDateFormat fmt = new SimpleDateFormat(REVISION_SIMPLE_DATE);
-            fmt.setLenient(false);
-            return fmt;
-        }
-
-        @Override
-        public void set(final SimpleDateFormat value) {
-            throw new UnsupportedOperationException();
-        }
-
-    };
-
-    public static SimpleDateFormat getRevisionFormat() {
-        return REVISION_FORMAT.get();
-    }
-}
index 62b4b459e4db0454d5ebeebc3d9dd072853158b4..cf77c34c216bb7b32eb0272d158e817ff4ec2b43 100644 (file)
@@ -25,10 +25,7 @@ import java.nio.file.Path;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.StandardCopyOption;
 import java.nio.file.attribute.BasicFileAttributes;
-import java.text.DateFormat;
-import java.text.ParseException;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -36,7 +33,6 @@ import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
@@ -178,28 +174,24 @@ public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentat
         }
 
         File file = null;
-        TreeMap<Date, File> map = new TreeMap<>();
+        TreeMap<Optional<Revision>, File> map = new TreeMap<>(Revision::compare);
         for (File sorted : files) {
             String fileName = sorted.getName();
             Matcher match = Revision.STRING_FORMAT_PATTERN.matcher(fileName);
             if (match.find()) {
                 String revStr = match.group();
-                /*
-                 * FIXME: Consider using string for comparison.
-                 * String is comparable, pattern check tested format
-                 * so comparing as ASCII string should be sufficient
-                 */
-                DateFormat df = SimpleDateFormatUtil.getRevisionFormat();
+                Revision rev;
                 try {
-                    Date date = df.parse(revStr);
-                    map.put(date, sorted);
-                } catch (final ParseException e) {
-                    LOG.info("Unable to parse date from yang file name {}", fileName);
-                    map.put(new Date(0L), sorted);
+                    rev = Revision.valueOf(revStr);
+                } catch (final IllegalArgumentException e) {
+                    LOG.info("Unable to parse date from yang file name {}, falling back to not-present", fileName, e);
+                    rev = null;
                 }
 
+                map.put(Optional.ofNullable(rev), sorted);
+
             } else {
-                map.put(new Date(0L), sorted);
+                map.put(Optional.empty(), sorted);
             }
         }
         file = map.lastEntry().getValue();