Field.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.generic_project.beans;

  21. /**
  22.  * Field
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */
  28. public class Field implements IField {

  29.     private String fieldName;
  30.     private Class<?> fieldType;
  31.    
  32.     private String className;
  33.     private Class<?> classType;
  34.    
  35.     public Field(String fieldName,Class<?> fieldType,String className,Class<?> classType){
  36.         this.fieldName = fieldName;
  37.         this.fieldType = fieldType;
  38.         this.className = className;
  39.         this.classType = classType;
  40.     }

  41.     @Override
  42.     public String getFieldName() {
  43.         return this.fieldName;
  44.     }

  45.     @Override
  46.     public Class<?> getFieldType() {
  47.         return this.fieldType;
  48.     }

  49.     @Override
  50.     public String getClassName() {
  51.         return this.className;
  52.     }

  53.     @Override
  54.     public Class<?> getClassType() {
  55.         return this.classType;
  56.     }
  57.    
  58.     @Override
  59.     public boolean equals(Object o){
  60.         if(o==null){
  61.             return false;
  62.         }
  63.         if(! (o instanceof Field) ){
  64.             if(o instanceof IField)
  65.                 return false;
  66.             else
  67.                 throw new RuntimeException("Expected type ["+Field.class.getName()+"] different from the type found ["+o.getClass().getName()+"]");
  68.         }
  69.         Field f = (Field) o;
  70.        
  71.         String thisClassTypeName = this.classType.getName() + "";
  72.         String fClassTypeName = f.getClassType().getName() + "";
  73.        
  74.         String thisFieldTypeName = this.fieldType.getName() + "";
  75.         String fFieldTypeName = f.getFieldType().getName() + "";
  76.        
  77.         return this.className.equals(f.getClassName()) &&
  78.                 thisClassTypeName.equals(fClassTypeName) &&
  79.             this.fieldName.equals(f.getFieldName()) &&
  80.             thisFieldTypeName.equals(fFieldTypeName);
  81.     }  
  82.    
  83.     @Override
  84.     public int hashCode() {
  85.         return super.hashCode();
  86.     }
  87.    
  88.     @Override
  89.     public String toString(){
  90.         return toString(0);
  91.     }
  92.     @Override
  93.     public String toString(int indent){
  94.        
  95.         StringBuilder indentBuffer = new StringBuilder();
  96.         for (int i = 0; i < indent; i++) {
  97.             indentBuffer.append("   ");
  98.         }
  99.        
  100.         StringBuilder bf = new StringBuilder();
  101.        
  102.         bf.append(indentBuffer.toString());
  103.         bf.append("- field name: "+this.fieldName);
  104.         bf.append("\n");
  105.        
  106.         bf.append(indentBuffer.toString());
  107.         bf.append("- field type: "+this.fieldType);
  108.         bf.append("\n");
  109.        
  110.         bf.append(indentBuffer.toString());
  111.         bf.append("- class name: "+this.className);
  112.         bf.append("\n");
  113.        
  114.         bf.append(indentBuffer.toString());
  115.         bf.append("- class type: "+this.classType);
  116.         bf.append("\n");
  117.        
  118.         return bf.toString();
  119.     }

  120. }