View Javadoc

1   /*
2    *  Copyright 2001-2005 Stephen Colebourne
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.joda.time.format;
17  
18  /**
19   * Internal interface for parsing textual representations of datetimes.
20   * <p>
21   * Application users will rarely use this class directly. Instead, you
22   * will use one of the factory classes to create a {@link DateTimeFormatter}.
23   * <p>
24   * The factory classes are:<br />
25   * - {@link DateTimeFormatterBuilder}<br />
26   * - {@link DateTimeFormat}<br />
27   * - {@link ISODateTimeFormat}<br />
28   *
29   * @author Brian S O'Neill
30   * @see DateTimeFormatter
31   * @see DateTimeFormatterBuilder
32   * @see DateTimeFormat
33   * @since 1.0
34   */
35  public interface DateTimeParser {
36  
37      /**
38       * Returns the expected maximum number of characters consumed.
39       * The actual amount should rarely exceed this estimate.
40       * 
41       * @return the estimated length
42       */
43      int estimateParsedLength();
44  
45      /**
46       * Parse an element from the given text, saving any fields into the given
47       * DateTimeParserBucket. If the parse succeeds, the return value is the new
48       * text position. Note that the parse may succeed without fully reading the
49       * text.
50       * <p>
51       * If it fails, the return value is negative. To determine the position
52       * where the parse failed, apply the one's complement operator (~) on the
53       * return value.
54       *
55       * @param bucket  field are saved into this, not null
56       * @param text  the text to parse, not null
57       * @param position  position to start parsing from
58       * @return new position, negative value means parse failed -
59       *  apply complement operator (~) to get position of failure
60       * @throws IllegalArgumentException if any field is out of range
61       */
62      int parseInto(DateTimeParserBucket bucket, String text, int position);
63  
64  }