Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2006 Stephen Colebourne
   *
   *  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.joda.time;

Exception thrown when attempting to set a field outside its supported range.

Author(s):
Brian S O'Neill
Since:
1.1
 
 public class IllegalFieldValueException extends IllegalArgumentException {
    
    
Serialization lock.
 
     private static final long serialVersionUID = 6305711765985447737L;

    
Creates a message for the exception.

Parameters:
fieldName the field name
value the value rejected
lowerBound the lower bound allowed
upperBound the uppe bound allowed
explain an explanation
Returns:
the message
 
     private static String createMessage(String fieldNameNumber value,
                                         Number lowerBoundNumber upperBoundString explain) {
         StringBuffer buf = new StringBuffer()
             .append("Value ").append(value).append(" for ").append(fieldName).append(' ');
 
         if (lowerBound == null) {
             if (upperBound == null) {
                 buf.append("is not supported");
             } else {
                 buf.append("must not be larger than ").append(upperBound);
             }
         } else if (upperBound == null) {
             buf.append("must not be smaller than ").append(lowerBound);
         } else {
             buf.append("must be in the range [")
                 .append(lowerBound)
                 .append(',')
                 .append(upperBound)
                 .append(']');
         }
         if (explain != null) {
             buf.append(": ").append(explain);
         }
 
         return buf.toString();
     }

    
Creates a message for the exception.

Parameters:
fieldName the field name
value the value rejected
Returns:
the message
 
     private static String createMessage(String fieldNameString value) {
         StringBuffer buf = new StringBuffer().append("Value ");
 
         if (value == null) {
             buf.append("null");
         } else {
             buf.append('"');
             buf.append(value);
             buf.append('"');
         }
 
         buf.append(" for ").append(fieldName).append(' ').append("is not supported");
         
         return buf.toString();
     }
 
     private final DateTimeFieldType iDateTimeFieldType;
     private final DurationFieldType iDurationFieldType;
     private final String iFieldName;
     private final Number iNumberValue;
     private final String iStringValue;
     private final Number iLowerBound;
     private final Number iUpperBound;
     private String iMessage;

    
Constructor.

Parameters:
fieldType type of field being set
value illegal value being set
lowerBound lower legal field value, or null if not applicable
upperBound upper legal field value, or null if not applicable
                                      Number valueNumber lowerBoundNumber upperBound) {
        super(createMessage(fieldType.getName(), valuelowerBoundupperBoundnull));
         = fieldType;
         = null;
         = fieldType.getName();
         = value;
         = null;
         = lowerBound;
         = upperBound;
         = super.getMessage();
    }

    
Constructor.

Parameters:
fieldType type of field being set
value illegal value being set
explain an explanation
Since:
1.5
                                      Number valueString explain) {
        super(createMessage(fieldType.getName(), valuenullnullexplain));
         = fieldType;
         = null;
         = fieldType.getName();
         = value;
         = null;
         = null;
         = null;
         = super.getMessage();
    }

    
Constructor.

Parameters:
fieldType type of field being set
value illegal value being set
lowerBound lower legal field value, or null if not applicable
upperBound upper legal field value, or null if not applicable
                                      Number valueNumber lowerBoundNumber upperBound) {
        super(createMessage(fieldType.getName(), valuelowerBoundupperBoundnull));
         = null;
         = fieldType;
         = fieldType.getName();
         = value;
         = null;
         = lowerBound;
         = upperBound;
         = super.getMessage();
    }

    
Constructor.

Parameters:
fieldName name of field being set
value illegal value being set
lowerBound lower legal field value, or null if not applicable
upperBound upper legal field value, or null if not applicable
    public IllegalFieldValueException(String fieldName,
                                      Number valueNumber lowerBoundNumber upperBound) {
        super(createMessage(fieldNamevaluelowerBoundupperBoundnull));
         = null;
         = null;
         = fieldName;
         = value;
         = null;
         = lowerBound;
         = upperBound;
         = super.getMessage();
    }

    
Constructor.

Parameters:
fieldType type of field being set
value illegal value being set
    public IllegalFieldValueException(DateTimeFieldType fieldTypeString value) {
        super(createMessage(fieldType.getName(), value));
         = fieldType;
         = null;
         = fieldType.getName();
         = value;
         = null;
         = null;
         = null;
         = super.getMessage();
    }

    
Constructor.

Parameters:
fieldType type of field being set
value illegal value being set
    public IllegalFieldValueException(DurationFieldType fieldTypeString value) {
        super(createMessage(fieldType.getName(), value));
         = null;
         = fieldType;
         = fieldType.getName();
         = value;
         = null;
         = null;
         = null;
         = super.getMessage();
    }

    
Constructor.

Parameters:
fieldName name of field being set
value illegal value being set
    public IllegalFieldValueException(String fieldNameString value) {
        super(createMessage(fieldNamevalue));
         = null;
         = null;
         = fieldName;
         = value;
         = null;
         = null;
         = null;
         = super.getMessage();
    }
    //-----------------------------------------------------------------------
    
Returns the DateTimeFieldType whose value was invalid, or null if not applicable.

Returns:
the datetime field type
        return ;
    }

    
Returns the DurationFieldType whose value was invalid, or null if not applicable.

Returns:
the duration field type
        return ;
    }

    
Returns the name of the field whose value was invalid.

Returns:
the field name
    public String getFieldName() {
        return ;
    }

    
Returns the illegal integer value assigned to the field, or null if not applicable.

Returns:
the value
    public Number getIllegalNumberValue() {
        return ;
    }

    
Returns the illegal string value assigned to the field, or null if not applicable.

Returns:
the value
    public String getIllegalStringValue() {
        return ;
    }

    
Returns the illegal value assigned to the field as a non-null string.

Returns:
the value
    public String getIllegalValueAsString() {
        String value = ;
        if (value == null) {
            value = String.valueOf();
        }
        return value;
    }

    
Returns the lower bound of the legal value range, or null if not applicable.

Returns:
the lower bound
    public Number getLowerBound() {
        return ;
    }

    
Returns the upper bound of the legal value range, or null if not applicable.

Returns:
the upper bound
    public Number getUpperBound() {
        return ;
    }
    public String getMessage() {
        return ;
    }

    
Provide additional detail by prepending a message to the existing message. A colon is separator is automatically inserted between the messages.

Since:
1.3
    public void prependMessage(String message) {
        if ( == null) {
             = message;
        } else if (message != null) {
             = message + ": " + ;
        }
    }
New to GrepCode? Check out our FAQ X