class MultiFormatDateParser {

    static public Date parse(String dateString)
    {
        for (Rule candidate : rules)
        {
            if (candidate.pattern.matcher(dateString).matches())
            {
                Date result;
                try {
                    synchronized(candidate.format) {
                        result = candidate.format.parse(dateString);
                    }
                } catch (ParseException ex) {
                    log.info("Date string '{}' matched pattern '{}' but did not parse:  {}",
                            new String[] {dateString, candidate.format.toPattern(), ex.getMessage()});
                    continue;
                }
                return result;
            }
        }

        return null;
    }

}