Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (C) 2012 FoxLabs
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.foxlabs.validation.converter;
 
 
 
This class provides NumberConverter implementation for the java.math.BigDecimal type.

 
 public final class BigDecimalConverter extends NumberConverter.DecimalType<BigDecimal> {
    
    
BigDecimalConverter default instance.
 
     public static final BigDecimalConverter DEFAULT = new BigDecimalConverter((Stringnull);
    
    
Constructs a new BigDecimalConverter with the specified pattern.

Parameters:
pattern java.text.DecimalFormat pattern or null if context pattern should be used.
Throws:
java.lang.IllegalArgumentException if the specified pattern is invalid.
 
     BigDecimalConverter(String pattern) {
         super(pattern);
     }
    
    
Constructs a new BigDecimalConverter from the specified annotation.

Parameters:
annotation Converter annotation.
Throws:
java.lang.IllegalArgumentException if the specified annotation defines invalid pattern.
 
     BigDecimalConverter(NumberPattern annotation) {
         this(annotation.value());
     }
    
    
Returns java.math.BigDecimal type.

Returns:
java.math.BigDecimal type.
 
     @Override
     public Class<BigDecimalgetType() {
         return BigDecimal.class;
     }
    
    
Converts default string representation of decimal value into java.math.BigDecimal object.

Parameters:
value Default string representation of decimal value.
Returns:
Decoded java.math.BigDecimal object.
Throws:
java.lang.NumberFormatException if the specified string could not be parsed as a decimal.
 
     @Override
     protected BigDecimal doDecodeDefault(String value) {
         return new BigDecimal(value);
     }
    
    
Returns decimal number format for the specified context and this converter configuration.

Parameters:
context Validation context.
Returns:
Decimal number format for the specified context and this converter configuration.
 
     @Override
     protected NumberFormat getFormat(ValidationContext<?> context) {
         NumberFormat format = super.getFormat(context);
        if (format instanceof DecimalFormat) {
            if ( == null)
                format = (DecimalFormatformat.clone();
            ((DecimalFormatformat).setParseBigDecimal(true);
        }
        return format;
    }
    
New to GrepCode? Check out our FAQ X