+++ /dev/null
-/*
- * 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();
- }
-}
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;
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;
}
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();