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