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;
17
18 /**
19 * Provides a uniform interface to obtain a {@code BigMoney}.
20 * <p>
21 * When designing APIs, it is recommended to use {@code BigMoneyProvider}
22 * in method signatures where possible to allow the widest possible use of the method.
23 * Within Joda-Money, both {@code BigMoney} and {@code Money} implement
24 * the provider interface.
25 * <p>
26 * Implementations of {@code BigMoneyProvider} may be mutable.
27 * To minimise the risk of the value of the provider changing while processing,
28 * any method that takes a {@code BigMoneyProvider} as a parameter should convert
29 * it to a {@code BigMoney} immediately and use that directly from then on.
30 * The method {@link BigMoney#of(BigMoneyProvider)} performs the conversion
31 * safely with null checks and is recommended for this purpose.
32 * <p>
33 * This interface makes no guarantees about the immutability or
34 * thread-safety of implementations.
35 */
36 public interface BigMoneyProvider {
37
38 /**
39 * Returns a {@code BigMoney} instance equivalent to the value of this object.
40 * <p>
41 * It is recommended that {@link BigMoney#of(BigMoneyProvider)} is used in
42 * preference to calling this method directly. It is also recommended that the
43 * converted {@code BigMoney} is cached in a local variable instead of
44 * performing the conversion multiple times.
45 *
46 * @return the converted money instance, never null
47 * @throws RuntimeException if conversion is not possible
48 */
49 BigMoney toBigMoney();
50
51 }