View Javadoc

1   /*
2    *  Copyright 2009-2013 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.money.format;
17  
18  /**
19   * Parses part of a textual input string of monetary information.
20   * <p>
21   * The parser is expected to start parsing at the specified text position
22   * and match against whatever it represents.
23   * The parsed result must be stored in the context.
24   * The context also provides the current parse position which must be updated.
25   * <p>
26   * This interface must be implemented with care to ensure other classes operate correctly.
27   * All instantiable implementations must be thread-safe, and should generally
28   * be final and immutable.
29   */
30  public interface MoneyParser {
31  
32      /**
33       * Parses monetary information using a textual representation.
34       * <p>
35       * The text and parse index are stored in the context.
36       * The parsed data and updated index is also stored in the context.
37       * <p>
38       * Implementations should avoid throwing exceptions and use the error index
39       * in the context instead to record the problem.
40       * The context can be assumed to not be in error on entry to this method.
41       * <p>
42       * The context is not a thread-safe object and a new instance will be created
43       * for each parse. The context must not be stored in an instance variable
44       * or shared with any other threads.
45       * 
46       * @param context  the context to use and parse into, not null
47       */
48      void parse(MoneyParseContext context);
49  
50  }