001/* 002 * Copyright (C) 2014 konik.io 003 * 004 * This file is part of Konik library. 005 * 006 * Konik library is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Konik library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with Konik library. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package io.konik.zugferd.unqualified; 020 021import java.math.BigDecimal; 022 023import javax.validation.constraints.NotNull; 024import javax.xml.bind.annotation.XmlAccessType; 025import javax.xml.bind.annotation.XmlAccessorType; 026import javax.xml.bind.annotation.XmlAttribute; 027import javax.xml.bind.annotation.XmlType; 028import javax.xml.bind.annotation.XmlValue; 029 030import com.neovisionaries.i18n.CurrencyCode; 031 032/** 033 * = The Monetary Amount. 034 * 035 * A number of monetary units specified by a currency where the currency is explicit or implied. 036 */ 037@XmlAccessorType(XmlAccessType.FIELD) 038@XmlType(name = "AmountType", propOrder = { "value" }) 039public class Amount { 040 041 @NotNull 042 @XmlValue 043 private BigDecimal value; 044 045 @NotNull 046 @XmlAttribute(name = "currencyID") 047 private CurrencyCode currency; 048 049 Amount() { 050 } 051 052 /** 053 * Instantiates a new amount. 054 * 055 * @param value the monetary value as a long 056 * @param currency the currency code 057 * 058 */ 059 public Amount(long value, CurrencyCode currency) { 060 super(); 061 this.value = BigDecimal.valueOf(value); 062 this.currency = currency; 063 } 064 065 /** 066 * Instantiates a new amount. 067 * 068 * @param value the monetary value as a string 069 * @param currency the currency code 070 * @throws NumberFormatException if +value+ is not a valid representation of a +BigDecimal+. 071 */ 072 public Amount(String value, CurrencyCode currency) { 073 super(); 074 this.value = new BigDecimal(value); 075 this.currency = currency; 076 } 077 078 /** 079 * Instantiates a new amount. 080 * 081 * @param value the value 082 * @param currency the currency code 083 */ 084 public Amount(BigDecimal value, CurrencyCode currency) { 085 super(); 086 this.value = value; 087 this.currency = currency; 088 } 089 090 /** 091 * Gets the amount value. 092 * 093 * @return the value 094 */ 095 public BigDecimal getValue() { 096 return value; 097 } 098 099 /** 100 * Sets the amount value. 101 * 102 * @param value the new value 103 * @return the amount 104 */ 105 public Amount setValue(BigDecimal value) { 106 this.value = value; 107 return this; 108 } 109 110 /** 111 * Gets the currency code. 112 * 113 * @return the +ISO 4217 3A+ currency code 114 */ 115 public CurrencyCode getCurrency() { 116 return currency; 117 } 118 119 /** 120 * Sets the currency code. 121 * 122 * @param currency the new +ISO 4217 3A+ currency code 123 * @return the amount 124 */ 125 public Amount setCurrency(CurrencyCode currency) { 126 this.currency = currency; 127 return this; 128 } 129 130}