Java String Format isDurationFormatPattern(String formatPattern)

Here you can find the source of isDurationFormatPattern(String formatPattern)

Description

Determine if the duration format pattern is valid.

License

Open Source License

Parameter

Parameter Description
formatPattern pattern

Return

true --> valid, otherwise false

Declaration

public static boolean isDurationFormatPattern(String formatPattern) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.List;

public class Main {
    /**//  w w  w.j  a  va2  s .com
     * Characters accepted in duration format pattern.
     */
    public static final List<String> ACCEPTED_CHAR_DURATION_PATTERN = Arrays.asList("dd", "hh", "mm", "ss");

    /**
     * Determine if the duration format pattern is valid.
     * 
     * @param formatPattern
     *          pattern
     * @return true --> valid, otherwise false
     */
    public static boolean isDurationFormatPattern(String formatPattern) {
        if (formatPattern == null) {
            return false;
        }

        final int length = formatPattern.length();
        if (length < 2) {
            return false;
        }

        formatPattern = formatPattern.toLowerCase();
        final String first = formatPattern.substring(0, 2);
        final String last = formatPattern.substring(length - 2);
        if (ACCEPTED_CHAR_DURATION_PATTERN.contains(first) && ACCEPTED_CHAR_DURATION_PATTERN.contains(last)) {
            return true;
        }
        return false;
    }
}

Related

  1. getImageWriter(String formatName)
  2. getRequriedArgumentCount(MessageFormat msgFormat)
  3. getStylingHyphenFormat(String cssProperties)
  4. getTextAsFormattedLines(String text, int lineLength)
  5. getWriterByFormat(final String format)
  6. isQueryInFormat(String in)
  7. str(final String messageFormat, final Object... args)
  8. StrFormat(String pattern, Object... arguments)
  9. stringFormat(String pattern, Object[] arguments)