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