Example usage for java.text DateFormat toString

List of usage examples for java.text DateFormat toString

Introduction

In this page you can find the example usage for java.text DateFormat toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.microsoft.tfs.util.datetime.LenientDateTimeParserExpander.java

/**
 * Sorts the items in this expander's set and returns a flattened array.
 *
 * @return the expanded items in the order they were added.
 *//*from   w w w .j av  a 2 s.  co  m*/
public LenientDateTimeFormat[] getSortedResults() {
    /*
     * Flatten the set into an array.
     */
    final LenientDateTimeFormat[] flat = (LenientDateTimeFormat[]) lenientDateTimeParserFormats
            .toArray(new LenientDateTimeFormat[lenientDateTimeParserFormats.size()]);

    /*
     * Sort the formats in a way that preserved the original order of their
     * definition before expansion.
     */
    Arrays.sort(flat, new LenientDateTimeFormatComparator());

    if (log.isTraceEnabled()) {
        for (int i = 0; i < flat.length; i++) {
            final DateFormat format = flat[i].getDateFormat();

            if (format instanceof SimpleDateFormat) {
                final String pattern = ((SimpleDateFormat) format).toPattern();
                final String messageFormat = "expanded format {0}: {1}"; //$NON-NLS-1$
                final String message = MessageFormat.format(messageFormat, i, pattern);
                log.trace(message);
            } else {
                final String messageFormat = "expanded format {0}: {1}"; //$NON-NLS-1$
                final String message = MessageFormat.format(messageFormat, i, format.toString());
                log.trace(message);
            }
        }
    }

    return flat;
}