<commit_before>/*
 * $Id$
 */
package org.xins.util.collections;

import org.xins.util.MandatoryArgumentChecker;
import org.xins.util.text.FastStringBuffer;

/**
 * Exception thrown to indicate the property of a value is invalid. This
 * exception applies to both bootstrapping
 * ({@link Manageable#bootstrap(PropertyReader)}) and initialization
 * ({@link Manageable#init(PropertyReader)}).
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 */
public final class InvalidPropertyValueException
extends Exception {

   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   /**
    * Creates message based on the specified constructor arguments.
    *
    * @param propertyName
    *    the name of the property, cannot be <code>null</code>.
    *
    * @param propertyValue
    *    the (invalid) value set for the property, cannot be
    *    <code>null</code>.
    *
    * @return
    *    the message, never <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>propertyName == null || propertyValue == null</code>.
    */
   private static final String createMessage(String propertyName, String propertyValue)
   throws IllegalArgumentException {

      // Check preconditions
      MandatoryArgumentChecker.check("propertyName",  propertyName,
                                     "propertyValue", propertyValue);

      // Construct the message
      FastStringBuffer buffer = new FastStringBuffer(150);
      buffer.append("The value \"");
      buffer.append(propertyValue);
      buffer.append("\" is invalid for property \"");
      buffer.append(propertyName);
      buffer.append("\".");

      return buffer.toString();
   }


   //-------------------------------------------------------------------------
   // Class functions
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Constructors
   //-------------------------------------------------------------------------

   /**
    * Constructs a new <code>InvalidPropertyValueException</code>.
    *
    * @param propertyName
    *    the name of the property, cannot be <code>null</code>.
    *
    * @param propertyValue
    *    the (invalid) value set for the property, cannot be
    *    <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>propertyName == null || propertyValue == null</code>.
    */
   public InvalidPropertyValueException(String propertyName, String propertyValue)
   throws IllegalArgumentException {

      // Construct message and call superclass constructor
      super(createMessage(propertyName, propertyValue));

      // Store data
      _propertyName  = propertyName;
      _propertyValue = propertyValue;
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   /**
    * The name of the property.
    */
   private final String _propertyName;

   /**
    * The (invalid) value of the property.
    */
   private final String _propertyValue;


   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Returns the name of the property.
    *
    * @return
    *    the name of the property, never <code>null</code>.
    */
   public String getPropertyName() {
      return _propertyName;
   }

   /**
    * Returns the (invalid) value of the property.
    *
    * @return
    *    the value of the property, never <code>null</code>.
    */
   public String getPropertyValue() {
      return _propertyValue;
   }
}<commit_msg>Added support for 'reason' property.<commit_after>/*
 * $Id$
 */
package org.xins.util.collections;

import org.xins.util.MandatoryArgumentChecker;
import org.xins.util.text.FastStringBuffer;

/**
 * Exception thrown to indicate the property of a value is invalid. This
 * exception applies to both bootstrapping
 * ({@link Manageable#bootstrap(PropertyReader)}) and initialization
 * ({@link Manageable#init(PropertyReader)}).
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 */
public final class InvalidPropertyValueException
extends Exception {

   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   /**
    * Creates message based on the specified constructor arguments.
    *
    * @param propertyName
    *    the name of the property, cannot be <code>null</code>.
    *
    * @param propertyValue
    *    the (invalid) value set for the property, cannot be
    *    <code>null</code>.
    *
    * @return
    *    the message, never <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>propertyName == null || propertyValue == null</code>.
    */
   private static final String createMessage(String propertyName,
                                             String propertyValue,
                                             String reason)
   throws IllegalArgumentException {

      // Check preconditions
      MandatoryArgumentChecker.check("propertyName",  propertyName,
                                     "propertyValue", propertyValue);

      // Construct the message
      FastStringBuffer buffer = new FastStringBuffer(150);
      buffer.append("The value \"");
      buffer.append(propertyValue);
      buffer.append("\" is invalid for property \"");
      buffer.append(propertyName);
      if (reason == null) {
         buffer.append("\".");
      } else {
         buffer.append("\": ");
         buffer.append(reason);
      }

      return buffer.toString();
   }


   //-------------------------------------------------------------------------
   // Class functions
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Constructors
   //-------------------------------------------------------------------------

   /**
    * Constructs a new <code>InvalidPropertyValueException</code>.
    *
    * @param propertyName
    *    the name of the property, cannot be <code>null</code>.
    *
    * @param propertyValue
    *    the (invalid) value set for the property, cannot be
    *    <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>propertyName == null || propertyValue == null</code>.
    */
   public InvalidPropertyValueException(String propertyName,
                                        String propertyValue)
   throws IllegalArgumentException {

      this(propertyName, propertyValue, null);
   }

   /**
    * Constructs a new <code>InvalidPropertyValueException</code> with the
    * specified reason.
    *
    * @param propertyName
    *    the name of the property, cannot be <code>null</code>.
    *
    * @param propertyValue
    *    the (invalid) value set for the property, cannot be
    *    <code>null</code>.
    *
    * @param reason
    *    additional description of the problem, or <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>propertyName == null || propertyValue == null</code>.
    *
    * @since XINS 0.150
    */
   public InvalidPropertyValueException(String propertyName,
                                        String propertyValue,
                                        String reason)
   throws IllegalArgumentException {

      // Construct message and call superclass constructor
      super(createMessage(propertyName, propertyValue, reason));

      // Store data
      _propertyName  = propertyName;
      _propertyValue = propertyValue;
      _reason        = reason;
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   /**
    * The name of the property. Cannot be <code>null</code>.
    */
   private final String _propertyName;

   /**
    * The (invalid) value of the property. Cannot be <code>null</code>.
    */
   private final String _propertyValue;

   /**
    * The detailed reason. Can be <code>null</code>.
    */
   private final String _reason;


   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Returns the name of the property.
    *
    * @return
    *    the name of the property, never <code>null</code>.
    */
   public String getPropertyName() {
      return _propertyName;
   }

   /**
    * Returns the (invalid) value of the property.
    *
    * @return
    *    the value of the property, never <code>null</code>.
    */
   public String getPropertyValue() {
      return _propertyValue;
   }

   /**
    * Returns the description of the reason.
    *
    * @return
    *    the reason, or <code>null</code>.
    *
    * @since XINS 0.150
    */
   public String getReason() {
      return _reason;
   }
}
{'fraction_non_alphanumeric': 0.2516549220585095, 'fraction_numerical': 0.0014947683109118087, 'mean_word_length': 1.403643828586092, 'pattern_counts': {'":': 1, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118741', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2128, 'n_words': 603}