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

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

/**
 * Exception that indicates that a specified name was invalid for that type of
 * component.
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 *
 * @since XINS 0.141
 */
public final class InvalidNameException extends Exception {

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

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

   /**
    * Creates the message the constructor can pass up to the superconstructor.
    *
    * @param type
    *    the type of component for which the name is considered invalid,
    *    cannot be <code>null</code>.
    *
    * @param name
    *    the name that is considered invalid, cannot be <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>type == null || name == null</code>.
    */
   private static final String createMessage(SpecType type, String name)
   throws IllegalArgumentException {

      // Check preconditions
      MandatoryArgumentChecker.check("type", type, "name", name);

      String typeName = type.getTypeName();

      boolean vowel = isVowel(typeName.charAt(0));

      FastStringBuffer buffer = new FastStringBuffer(80);
      buffer.append("The specified name \"");
      buffer.append(name);
      buffer.append("\" is invalid for a");
      if (vowel) {
         buffer.append('n');
      }
      buffer.append(' ');
      buffer.append(typeName);
      buffer.append('.');

      return buffer.toString();
   }

   /**
    * Checks if the specified character is a vowel.
    *
    * @param c
    *    the character to check.
    *
    * @return
    *    <code>true</code> if the specified character is a vowel,
    *    <code>false</code> otherwise.
    */
   private static final boolean isVowel(char c) {
      // TODO: Move this function to a utility class
      return c == 'a' || c == 'A'
          || c == 'e' || c == 'E'
          || c == 'i' || c == 'I'
          || c == 'o' || c == 'O'
          || c == 'u' || c == 'U';
   }


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

   /**
    * Constructs a new <code>InvalidNameException</code>.
    *<commit_msg>Simplified exception message.<commit_after>/*
 * $Id$
 */
package org.xins.specs;

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

/**
 * Exception that indicates that a specified name was invalid for that type of
 * component.
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 *
 * @since XINS 0.141
 */
public final class InvalidNameException extends Exception {

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

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

   /**
    * Creates the message the constructor can pass up to the superconstructor.
    *
    * @param type
    *    the type of component for which the name is considered invalid,
    *    cannot be <code>null</code>.
    *
    * @param name
    *    the name that is considered invalid, cannot be <code>null</code>.
    *
    * @throws IllegalArgumentException
    *    if <code>type == null || name == null</code>.
    */
   private static final String createMessage(SpecType type, String name)
   throws IllegalArgumentException {

      // Check preconditions
      MandatoryArgumentChecker.check("type", type, "name", name);

      String typeName = type.getTypeName();

      boolean vowel = isVowel(typeName.charAt(0));

      FastStringBuffer buffer = new FastStringBuffer(80);
      buffer.append("The specified name \"");
      buffer.append(name);
      buffer.append("\" is invalid for a component of type \"");
      buffer.append(typeName);
      buffer.append("\".");

      return buffer.toString();
   }


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

   /**
    * Constructs a new <code>InvalidNameException</code>.
    *
{'fraction_non_alphanumeric': 0.29603040540540543, 'fraction_numerical': 0.0029560810810810812, 'mean_word_length': 1.3661338661338662, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4737117', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1151, 'n_words': 335}