001/** 002 * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * 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, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016package org.javamoney.moneta; 017 018import org.javamoney.moneta.function.DefaultMonetaryRoundedFactory; 019import org.javamoney.moneta.function.PrecisionContextRoundedOperator; 020import org.javamoney.moneta.function.PrecisionScaleRoundedOperator; 021import org.javamoney.moneta.function.ScaleRoundedOperator; 022 023import javax.money.CurrencyUnit; 024import javax.money.MonetaryAmount; 025import javax.money.MonetaryOperator; 026import java.math.MathContext; 027import java.math.RoundingMode; 028 029import static java.util.Objects.requireNonNull; 030 031/** 032 * this interface is used to create {@link RoundedMoney} using the {@link MonetaryOperator} as rounding. 033 * @see {@link MonetaryRoundedFactory#of(MathContext)} 034 * @see {@link MonetaryRoundedFactory#of(MonetaryOperator)} 035 * @see {@link MonetaryRoundedFactory#withRoundingMode(RoundingMode)} 036 * @author Otavio Santana 037 * @since 1.0.1 038 * @deprecated Moved to function package. 039 */ 040@Deprecated 041public interface MonetaryRoundedFactory { 042 043 /** 044 * return the {@link MonetaryOperator} as rounding operator 045 * @return the rounding operator 046 */ 047 MonetaryOperator getRoundingOperator(); 048 049 /** 050 * Create a {@link MonetaryAmount} with {@link Number}, {@link CurrencyUnit} and 051 * the {@link MonetaryOperator} as rounding operator given in this factory with the 052 * {@link MonetaryRoundedFactory#getRoundingOperator()}. The implementation will {@link RoundedMoney} 053 * @param number 054 * @param currencyUnit 055 * @return the {@link MonetaryAmount} from number and {@link CurrencyUnit} 056 */ 057 MonetaryAmount create(Number number, CurrencyUnit currencyUnit); 058 059 /** 060 * Create a factory to {@link org.javamoney.moneta.function.MonetaryRoundedFactoryBuilder} with this factory is possible make 061 * a custom {@link MonetaryOperator} as rounding operator, setting the precision, scale or both. 062 * @param roundingMode 063 * @see {@link ScaleRoundedOperator} 064 * @see {@link PrecisionContextRoundedOperator} 065 * @see {@link PrecisionScaleRoundedOperator} 066 * @see {@link RoundingMode} 067 * @return the builder to set scale, precision or both 068 * @throws NullPointerException if roundingMode is null 069 */ 070 static MonetaryRoundedFactoryBuilder withRoundingMode(RoundingMode roundingMode) { 071 return new MonetaryRoundedFactoryBuilder(requireNonNull(roundingMode)); 072 } 073 074 /** 075 * Create the {@link MonetaryRoundedFactory} using the {@link PrecisionContextRoundedOperator} as rounding operator. 076 * @param mathContext the mathContext that will be used to create the {@link PrecisionContextRoundedOperator} 077 * @see {@link PrecisionContextRoundedOperator#of(MathContext)} 078 * @see {@link PrecisionContextRoundedOperator} 079 * @return the factory using the MathContextRoundedOperator 080 * @throws NullPointerException if mathContext is null 081 */ 082 static MonetaryRoundedFactory of(MathContext mathContext) { 083 return new DefaultMonetaryRoundedFactory(PrecisionContextRoundedOperator.of(requireNonNull(mathContext))); 084 } 085 086 /** 087 * Create the {@link MonetaryRoundedFactory} using a custom {@link MonetaryOperator} as rounding operator. 088 * @param roundingOperator a custom {@link MonetaryOperator} that will be used in this factory 089 * @return the factory using the MathContextRoundedOperator 090 * @throws NullPointerException if roundingOperator is null 091 */ 092 static MonetaryRoundedFactory of(MonetaryOperator roundingOperator) { 093 return new DefaultMonetaryRoundedFactory(requireNonNull(roundingOperator)); 094 } 095}