001/* 002 * CREDIT SUISSE IS WILLING TO LICENSE THIS SPECIFICATION TO YOU ONLY UPON THE CONDITION THAT YOU 003 * ACCEPT ALL OF THE TERMS CONTAINED IN THIS AGREEMENT. PLEASE READ THE TERMS AND CONDITIONS OF THIS 004 * AGREEMENT CAREFULLY. BY DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF 005 * THE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE" BUTTON AT THE 006 * BOTTOM OF THIS PAGE. Specification: JSR-354 Money and Currency API ("Specification") Copyright 007 * (c) 2012-2013, Credit Suisse All rights reserved. 008 */ 009package org.javamoney.moneta.spi.base; 010 011import javax.money.MonetaryAmount; 012import javax.money.MonetaryAmountFactory; 013import javax.money.spi.MonetaryAmountsSingletonSpi; 014import java.util.ArrayList; 015import java.util.Collection; 016import java.util.List; 017 018/** 019 * SPI (core) for the backing implementation of the {@link javax.money.Monetary} singleton. It 020 * should load and manage (including contextual behavior), if needed) the different registered 021 * {@link javax.money.MonetaryAmountFactory} instances. 022 * 023 * @author Anatole Tresch 024 */ 025public abstract class BaseMonetaryAmountsSingletonSpi implements MonetaryAmountsSingletonSpi{ 026 027 /** 028 * Access the default {@link javax.money.MonetaryAmountFactory}. 029 * 030 * @return a the default {@link javax.money.MonetaryAmount} type corresponding, never {@code null}. 031 * @throws javax.money.MonetaryException if no {@link javax.money.spi.MonetaryAmountFactoryProviderSpi} is available, or no 032 * {@link javax.money.spi.MonetaryAmountFactoryProviderSpi} targeting the configured default 033 * {@link javax.money.MonetaryAmount} type. 034 * @see javax.money.Monetary#getDefaultAmountType() 035 */ 036 public MonetaryAmountFactory<?> getDefaultAmountFactory(){ 037 return getAmountFactory(getDefaultAmountType()); 038 } 039 040 /** 041 * Get the currently registered {@link javax.money.MonetaryAmount} implementation classes. 042 * 043 * @return the {@link java.util.Set} if registered {@link javax.money.MonetaryAmount} implementations, never 044 * {@code null}. 045 */ 046 public Collection<MonetaryAmountFactory<?>> getAmountFactories(){ 047 List<MonetaryAmountFactory<?>> factories = new ArrayList<>(); 048 for(Class<? extends MonetaryAmount> type : getAmountTypes()){ 049 factories.add(getAmountFactory(type)); 050 } 051 return factories; 052 } 053 054}