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.format; 017 018import java.math.BigDecimal; 019import java.math.RoundingMode; 020import java.text.DecimalFormat; 021import java.util.Objects; 022 023/** 024 * @deprecated 025 */ 026@Deprecated 027public final class MonetaryAmountNumericInformation { 028 029 private final DecimalFormat format; 030 031 MonetaryAmountNumericInformation(DecimalFormat format) { 032 this.format = format; 033 } 034 035 /** 036 * Gets the maximum number of digits allowed in the fraction portion of a number. 037 */ 038 public int getMaximumFractionDigits(){ 039 return format.getMaximumFractionDigits(); 040 } 041 /** 042 * Gets the maximum number of digits allowed in the integer portion of a number. For formatting numbers other than BigInteger and BigDecimal objects, 043 * the lower of the return value and 309 is used. 044 */ 045 public int getMaximumIntegerDigits(){ 046 return format.getMaximumIntegerDigits(); 047 } 048 /** 049 * Gets the minimum number of digits allowed in the fraction portion of a number. 050 * For formatting numbers other than BigInteger and BigDecimal objects, the lower of the return value 051 * and 340 is used. 052 */ 053 public int getMinimumFractionDigits(){ 054 return format.getMinimumFractionDigits(); 055 } 056 /** 057 * Gets the minimum number of digits allowed in the integer portion of a number. 058 * For formatting numbers other than BigInteger and BigDecimal objects, 059 * the lower of the return value and 309 is used. 060 */ 061 public int getMinimumIntegerDigits(){ 062 return format.getMinimumIntegerDigits(); 063 } 064 /** 065 * Allows you to get the behavior of the decimal separator with integers. 066 */ 067 public boolean isDecimalSeparatorAlwaysShown(){ 068 return format.isDecimalSeparatorAlwaysShown(); 069 } 070 /** 071 * Returns true if grouping is used in this format. 072 */ 073 public boolean isGroupingUsed(){ 074 return format.isGroupingUsed(); 075 } 076 /** 077 * Return the grouping size. Grouping size is the number of digits between grouping separators in the integer portion of a number. For example, in the number "123,456.78", the grouping size is 3. 078 */ 079 public int getGroupingSize(){ 080 return format.getGroupingSize(); 081 } 082 /** 083 * Gets the multiplier for use in percent, per mille, and similar formats. 084 */ 085 public int getMultiplier(){ 086 return format.getMultiplier(); 087 } 088 /** 089 *Returns true if this format will parse, the value part, as {@link BigDecimal} only. 090 */ 091 public boolean isParseBigDecimal(){ 092 return format.isParseBigDecimal(); 093 } 094 /** 095 *Returns true if this format will parse, the value part, as integers only. 096 */ 097 public boolean isParseIntegerOnly(){ 098 return format.isParseIntegerOnly(); 099 } 100 /** 101 * Gets the RoundingMode used in this DecimalFormat. 102 */ 103 public RoundingMode getRoundingMode(){ 104 return format.getRoundingMode(); 105 } 106 107 /** 108 * Sets the maximum number of digits allowed in the fraction portion of a number. 109 */ 110 public void setMaximumFractionDigits(int maximumFractionDigitis){ 111 format.setMaximumFractionDigits(maximumFractionDigitis); 112 } 113 /** 114 * Sets the maximum number of digits allowed in the integer portion of a number. 115 * For formatting numbers other than BigInteger and BigDecimal objects, the lower 116 * of newValue and 309 is used. Negative input values are replaced with 0. 117 */ 118 public void setMaximumIntegerDigits(int maximumIntegerDigits){ 119 format.setMaximumIntegerDigits(maximumIntegerDigits); 120 } 121 122 /** 123 * Sets the minimum number of digits allowed in the fraction portion of a number. For formatting numbers other than BigInteger and BigDecimal objects, 124 * the lower of newValue and 340 is used. 125 * Negative input values are replaced with 0. 126 */ 127 public void setMinimumFractionDigits(int minimumFractionDigits){ 128 format.setMinimumFractionDigits(minimumFractionDigits); 129 } 130 131 /** 132 * Sets the minimum number of digits allowed in the integer portion of a number. For formatting numbers other than BigInteger and BigDecimal objects, 133 * the lower of newValue and 309 is used. 134 * Negative input values are replaced with 0. 135 */ 136 public void setMinimumIntegerDigits(int minimumIntegerDigits){ 137 format.setMinimumIntegerDigits(minimumIntegerDigits); 138 } 139 140 /** 141 * Allows you to get the behavior of the decimal separator with integers. 142 */ 143 public void setDecimalSeparatorAlwaysShown(boolean decimalSeparatorAlwaysShown){ 144 format.setDecimalSeparatorAlwaysShown(decimalSeparatorAlwaysShown); 145 } 146 147 /** 148 * Set whether or not grouping will be used in this format. 149 */ 150 public void setGroupingUsed(boolean groupingUsed){ 151 format.setGroupingUsed(groupingUsed); 152 } 153 154 /** 155 * Set the grouping size. Grouping size is the number of digits between grouping separators 156 * in the integer portion of a number. 157 */ 158 public void setGroupingSize(int groupingSize){ 159 format.setGroupingSize(groupingSize); 160 } 161 162 /** 163 * Sets the multiplier for use in percent, per mille, and similar formats. 164 */ 165 public void setMultiplier(int multiplier){ 166 format.setMultiplier(multiplier); 167 } 168 /** 169 * Sets the RoundingMode used in this DecimalFormat. 170 */ 171 public void setRoundingMode(RoundingMode roundingMode){ 172 format.setRoundingMode(roundingMode); 173 } 174 175 /** 176 *Sets if this format will parse, the value part, as integers only. 177 */ 178 public void setParseIntegerOnly(boolean intergerOnley){ 179 format.setParseIntegerOnly(intergerOnley); 180 } 181 182 /** 183 *Sets if this format will parse, the value part, as {@link BigDecimal} only. 184 */ 185 public void setParseBigDecimal(boolean parseBigDecimal){ 186 format.setParseBigDecimal(parseBigDecimal); 187 } 188 189 @Override 190 public int hashCode() { 191 return Objects.hashCode(format); 192 } 193 194 @Override 195 public boolean equals(Object obj) { 196 if(obj == this) { 197 return true; 198 } 199 if (MonetaryAmountNumericInformation.class.isInstance(obj)) { 200 MonetaryAmountNumericInformation other = MonetaryAmountNumericInformation.class.cast(obj); 201 return Objects.equals(other.format, format); 202 } 203 return false; 204 } 205 206 @Override 207 public String toString() { 208 StringBuilder sb = new StringBuilder(); 209 sb.append(MonetaryAmountNumericInformation.class.getName()).append('{') 210 .append(" maximumFractionDigits: ").append(getMaximumFractionDigits()).append(',') 211 .append(" maximumIntegerDigits: ").append(getMaximumIntegerDigits()).append(',') 212 .append(" minimumFractionDigits: ").append(getMinimumFractionDigits()).append(',') 213 .append(" minimumIntegerDigits: ").append(getMinimumIntegerDigits()).append(',') 214 .append(" decimalSeparatorAlwaysShown: ").append(isDecimalSeparatorAlwaysShown()).append(',') 215 .append(" groupingUsed: ").append(isGroupingUsed()).append(',') 216 .append(" groupingSize: ").append(getGroupingSize()).append(',') 217 .append(" multiplier: ").append(getMultiplier()).append(',') 218 .append(" parseBigDecimal: ").append(isParseBigDecimal()).append(',') 219 .append(" parseIntegerOnly: ").append(isParseIntegerOnly()).append(',') 220 .append(" roundingMode: ").append(getRoundingMode()).append('}'); 221 return sb.toString(); 222 } 223}