001 /*
002 * Copyright 2009-2013 Stephen Colebourne
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.joda.money;
017
018 /**
019 * Provides a uniform interface to obtain a {@code BigMoney}.
020 * <p>
021 * When designing APIs, it is recommended to use {@code BigMoneyProvider}
022 * in method signatures where possible to allow the widest possible use of the method.
023 * Within Joda-Money, both {@code BigMoney} and {@code Money} implement
024 * the provider interface.
025 * <p>
026 * Implementations of {@code BigMoneyProvider} may be mutable.
027 * To minimise the risk of the value of the provider changing while processing,
028 * any method that takes a {@code BigMoneyProvider} as a parameter should convert
029 * it to a {@code BigMoney} immediately and use that directly from then on.
030 * The method {@link BigMoney#of(BigMoneyProvider)} performs the conversion
031 * safely with null checks and is recommended for this purpose.
032 * <p>
033 * This interface makes no guarantees about the immutability or
034 * thread-safety of implementations.
035 */
036 public interface BigMoneyProvider {
037
038 /**
039 * Returns a {@code BigMoney} instance equivalent to the value of this object.
040 * <p>
041 * It is recommended that {@link BigMoney#of(BigMoneyProvider)} is used in
042 * preference to calling this method directly. It is also recommended that the
043 * converted {@code BigMoney} is cached in a local variable instead of
044 * performing the conversion multiple times.
045 *
046 * @return the converted money instance, never null
047 * @throws RuntimeException if conversion is not possible
048 */
049 BigMoney toBigMoney();
050
051 }