001/**
002 * Copyright (c) 2012, 2014, 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.internal;
017
018import org.javamoney.moneta.RoundedMoney;
019import org.javamoney.moneta.spi.AbstractAmountFactory;
020
021import javax.money.CurrencyUnit;
022import javax.money.MonetaryContext;
023import javax.money.MonetaryContextBuilder;
024import javax.money.NumberValue;
025import java.math.RoundingMode;
026
027/**
028 * Implementation of {@link javax.money.MonetaryAmountFactory} creating instances of {@link org.javamoney.moneta
029 * .RoundedMoney}.
030 *
031 * @author Anatole Tresch
032 */
033public class RoundedMoneyAmountFactory extends AbstractAmountFactory<RoundedMoney>{
034
035    static final MonetaryContext DEFAULT_CONTEXT =
036            MonetaryContextBuilder.create(RoundedMoney.class).setPrecision(0).set(RoundingMode.HALF_EVEN)
037                    .build();
038    static final MonetaryContext MAX_CONTEXT =
039            MonetaryContextBuilder.create(RoundedMoney.class).setPrecision(0).set(RoundingMode.HALF_EVEN)
040                    .build();
041
042    /*
043     * (non-Javadoc)
044     * @see org.javamoney.moneta.spi.AbstractAmountFactory#create(javax.money.CurrencyUnit,
045     * java.lang.Number, javax.money.MonetaryContext)
046     */
047    @Override
048    protected RoundedMoney create(Number number, CurrencyUnit currency, MonetaryContext monetaryContext){
049        return RoundedMoney.of(number, currency, monetaryContext);
050    }
051
052    @Override
053    public NumberValue getMaxNumber(){
054        return null;
055    }
056
057    @Override
058    public NumberValue getMinNumber(){
059        return null;
060    }
061
062    /*
063     * (non-Javadoc)
064     * @see javax.money.MonetaryAmountFactory#getAmountType()
065     */
066    @Override
067    public Class<RoundedMoney> getAmountType(){
068        return RoundedMoney.class;
069    }
070
071    /*
072     * (non-Javadoc)
073     * @see org.javamoney.moneta.spi.AbstractAmountFactory#loadDefaultMonetaryContext()
074     */
075    @Override
076    protected MonetaryContext loadDefaultMonetaryContext(){
077        return DEFAULT_CONTEXT;
078    }
079
080    /*
081     * (non-Javadoc)
082     * @see org.javamoney.moneta.spi.AbstractAmountFactory#loadMaxMonetaryContext()
083     */
084    @Override
085    protected MonetaryContext loadMaxMonetaryContext(){
086        return MAX_CONTEXT;
087    }
088
089}