View Javadoc
1   package org.imageconverter.infra.exception;
2   
3   import org.apache.commons.lang3.ArrayUtils;
4   
5   /**
6    * Element already exists exception.
7    * 
8    * @author Fernando Romulo da Silva
9    */
10  public class ElementAlreadyExistsException extends ElementConflictException {
11  
12      private static final long serialVersionUID = 1L;
13  
14      /**
15       * Constructs a new ElementAlreadyExistsException exception and create detail message regard of parameters. </br>
16       * For instance for Person object with id 10: </br>
17       * "Person with id '10' already exists"
18       * 
19       * @param <T> The class type
20       * @param cls Class element
21       * @param id  Object id that repeated
22       */
23      public <T> ElementAlreadyExistsException(final Class<T> cls, final Object id) {
24  	super("{exception.elementIdAlreadyExists}", cls.getSimpleName(), id); //
25      }
26  
27      /**
28       * Constructs a new ElementAlreadyExistsException exception and create detail message regard of parameters. </br>
29       * The exception detail msg will be: cls.getSimpleName() + " with " + msg + " already exists". </br>
30       * For instance for Person object and msg equals to "id '10' and name 'Fernando'": </br>
31       * "Person with id '10' and name 'Fernando' already exists"
32       * 
33       * @param <T> The class type
34       * @param cls Class element
35       * @param msg The specific message
36       */
37      public <T> ElementAlreadyExistsException(final Class<T> cls, final Object[] params) {
38  	super("{exception.elementFieldsAlreadyExists}", ArrayUtils.addAll(new Object[] { cls.getSimpleName() }, params));
39      }
40  }