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.function; 017 018import javax.money.CurrencyUnit; 019import javax.money.MonetaryAmount; 020 021/** 022 * A state object for collecting statistics such as count, min, max, sum, and 023 * average. 024 * @author otaviojava 025 * @author Anatole Tresch 026 */ 027public interface MonetarySummaryStatistics { 028 029 /** 030 * Records another value into the summary information. 031 * @param amount 032 * the input amount value to be added, not null. 033 */ 034 void accept(MonetaryAmount amount); 035 036 /** 037 * Combines the state of another {@code MonetarySummaryStatistics} into this 038 * one. 039 * @param summaryStatistics 040 * another {@code MonetarySummaryStatistics}, not null. 041 */ 042 MonetarySummaryStatistics combine( 043 MonetarySummaryStatistics summaryStatistics); 044 045 /** 046 * Get the number of items added to this summary instance. 047 * @return the number of summarized items, >= 0. 048 */ 049 long getCount(); 050 051 /** 052 * Get the minimal amount found within this summary. 053 * @return the minimal amount, or null if no amount was added to this summary instance. 054 */ 055 MonetaryAmount getMin(); 056 057 /** 058 * Get the maximal amount found within this summary. 059 * @return the minimal amount, or null if no amount was added to this summary instance. 060 */ 061 MonetaryAmount getMax(); 062 063 /** 064 * Get the sum of all amounts within this summary. 065 * @return the total amount, or null if no amount was added to this summary instance. 066 */ 067 MonetaryAmount getSum(); 068 069 /** 070 * Get the mean average of all amounts added. 071 * @return the mean average amount, or null if no amount was added to this summary instance. 072 */ 073 MonetaryAmount getAverage(); 074 075 /** 076 * the currency unit used in summary 077 * @return the currency unit 078 */ 079 CurrencyUnit getCurrencyUnit(); 080 081 /** 082 * return if is possible do exchange rate or not with the MonetarySummary 083 * @return false; 084 */ 085 boolean isExchangeable(); 086 087 /** 088 * created the MonetarySummaryStatistics converted to {@link CurrencyUnit} 089 * @param unit 090 * to be converted 091 * @return MonetarySummaryStatistics converted 092 * @throws UnsupportedOperationException 093 * if {@link MonetarySummaryStatistics#isExchangeable()} was 094 * false 095 * @throws NullPointerException 096 * if unit was null 097 */ 098 MonetarySummaryStatistics to(CurrencyUnit unit); 099 100}