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.AbstractAmountBuilder;
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 RoundedMoneyAmountBuilder extends AbstractAmountBuilder<RoundedMoney> {
034
035    static final MonetaryContext DEFAULT_CONTEXT =
036            MonetaryContextBuilder.of(RoundedMoney.class).setPrecision(0).set(RoundingMode.HALF_EVEN).build();
037    static final MonetaryContext MAX_CONTEXT =
038            MonetaryContextBuilder.of(RoundedMoney.class).setPrecision(0).set(RoundingMode.HALF_EVEN).build();
039
040    /*
041     * (non-Javadoc)
042     * @see org.javamoney.moneta.spi.AbstractAmountFactory#of(javax.money.CurrencyUnit,
043     * java.lang.Number, javax.money.MonetaryContext)
044     */
045    @Override
046    protected RoundedMoney create(Number number, CurrencyUnit currency, MonetaryContext monetaryContext) {
047        return RoundedMoney.of(number, currency, monetaryContext);
048    }
049
050    @Override
051    public NumberValue getMaxNumber() {
052        return null;
053    }
054
055    @Override
056    public NumberValue getMinNumber() {
057        return null;
058    }
059
060    /*
061     * (non-Javadoc)
062     * @see javax.money.MonetaryAmountFactory#getAmountType()
063     */
064    @Override
065    public Class<RoundedMoney> getAmountType() {
066        return RoundedMoney.class;
067    }
068
069    /*
070     * (non-Javadoc)
071     * @see org.javamoney.moneta.spi.AbstractAmountFactory#loadDefaultMonetaryContext()
072     */
073    @Override
074    protected MonetaryContext loadDefaultMonetaryContext() {
075        return DEFAULT_CONTEXT;
076    }
077
078    /*
079     * (non-Javadoc)
080     * @see org.javamoney.moneta.spi.AbstractAmountFactory#loadMaxMonetaryContext()
081     */
082    @Override
083    protected MonetaryContext loadMaxMonetaryContext() {
084        return MAX_CONTEXT;
085    }
086
087}