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 java.math.RoundingMode;
019
020import javax.money.CurrencyUnit;
021import javax.money.MonetaryContext;
022import javax.money.MonetaryContextBuilder;
023import javax.money.NumberValue;
024import org.javamoney.moneta.FastMoney;
025import org.javamoney.moneta.spi.AbstractAmountBuilder;
026
027/**
028 * Implementation of {@link javax.money.MonetaryAmountFactory} creating instances of {@link FastMoney}.
029 *
030 * @author Anatole Tresch
031 */
032public class FastMoneyAmountBuilder extends AbstractAmountBuilder<FastMoney> {
033
034    static final MonetaryContext DEFAULT_CONTEXT =
035            MonetaryContextBuilder.of(FastMoney.class).setPrecision(19).setMaxScale(5).setFixedScale(true)
036                    .set(RoundingMode.HALF_EVEN).build();
037    static final MonetaryContext MAX_CONTEXT =
038            MonetaryContextBuilder.of(FastMoney.class).setPrecision(19).setMaxScale(5).setFixedScale(true)
039                    .set(RoundingMode.HALF_EVEN).build();
040
041    @Override
042    protected FastMoney create(Number number, CurrencyUnit currency, MonetaryContext monetaryContext) {
043        return FastMoney.of(number, currency);
044    }
045
046    @Override
047    public Class<FastMoney> getAmountType() {
048        return FastMoney.class;
049    }
050
051    @Override
052    public NumberValue getMaxNumber() {
053        return FastMoney.MAX_VALUE.getNumber();
054    }
055
056    @Override
057    public NumberValue getMinNumber() {
058        return FastMoney.MIN_VALUE.getNumber();
059    }
060
061    @Override
062    protected MonetaryContext loadDefaultMonetaryContext() {
063        return DEFAULT_CONTEXT;
064    }
065
066    @Override
067    protected MonetaryContext loadMaxMonetaryContext() {
068        return MAX_CONTEXT;
069    }
070
071}