| 1 | package com.hcarralero.toljava; |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Representa a un objeto TOL de tipo Code. |
|---|
| 5 | * |
|---|
| 6 | * @author Humberto Andrés Carralero López (hcarralero@gmail.com) |
|---|
| 7 | * @version 1.0 |
|---|
| 8 | */ |
|---|
| 9 | public class TOLCode extends TOLLObject { |
|---|
| 10 | |
|---|
| 11 | private String function; |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | * Obtiene el nombre de la función asignada al objeto. |
|---|
| 15 | * |
|---|
| 16 | * @return el nombre de la función asignada al objeto. |
|---|
| 17 | */ |
|---|
| 18 | public String getFunction() { |
|---|
| 19 | return function; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Cambia el nombre de la función asignada al objeto. |
|---|
| 24 | * |
|---|
| 25 | * @param function nuevo nombre. |
|---|
| 26 | */ |
|---|
| 27 | public void setFunction(String function) { |
|---|
| 28 | this.function = function; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | private String info; |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * Obtiene la información del objeto. |
|---|
| 35 | * |
|---|
| 36 | * @return la información del objeto. |
|---|
| 37 | */ |
|---|
| 38 | public String getInfo() { |
|---|
| 39 | return info; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * Construye un objeto de tipo <code>TOLCode</code>. |
|---|
| 44 | * |
|---|
| 45 | * @param function nombre de la función asignada al objeto. |
|---|
| 46 | * @param info información. |
|---|
| 47 | */ |
|---|
| 48 | public TOLCode(String function, String info) { |
|---|
| 49 | this.function = function; |
|---|
| 50 | this.info = info; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Determina si el objeto corresponde al tipo Code de TOL. |
|---|
| 55 | * |
|---|
| 56 | * @return <code>true</code> ya que el objeto corresponde al tipo Code de TOL. |
|---|
| 57 | */ |
|---|
| 58 | @Override |
|---|
| 59 | public boolean isCode() { |
|---|
| 60 | return true; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Compara a este objeto con otro. |
|---|
| 65 | * |
|---|
| 66 | * @param obj el objeto con el que se comparará. |
|---|
| 67 | * @return <code>true</code> si el objeto pasado como parámetro es de tipo <code>TOLCode</code> |
|---|
| 68 | * y tiene nombre e información idéntica. |
|---|
| 69 | */ |
|---|
| 70 | @Override |
|---|
| 71 | public boolean equals(Object obj) { |
|---|
| 72 | if (obj == null) { |
|---|
| 73 | return false; |
|---|
| 74 | } |
|---|
| 75 | if (getClass() != obj.getClass()) { |
|---|
| 76 | return false; |
|---|
| 77 | } |
|---|
| 78 | final TOLCode other = (TOLCode) obj; |
|---|
| 79 | if ((this.function == null) ? (other.function != null) : !this.function.equals(other.function)) { |
|---|
| 80 | return false; |
|---|
| 81 | } |
|---|
| 82 | if ((this.info == null) ? (other.info != null) : !this.info.equals(other.info)) { |
|---|
| 83 | return false; |
|---|
| 84 | } |
|---|
| 85 | return true; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | * Calcula el código hash asignado al objeto. |
|---|
| 90 | * |
|---|
| 91 | * @return el código hash asignado al objeto. |
|---|
| 92 | */ |
|---|
| 93 | @Override |
|---|
| 94 | public int hashCode() { |
|---|
| 95 | int hash = 7; |
|---|
| 96 | hash = 41 * hash + (this.function != null ? this.function.hashCode() : 0); |
|---|
| 97 | hash = 41 * hash + (this.info != null ? this.info.hashCode() : 0); |
|---|
| 98 | return hash; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * Obtiene una representación como cadena de texto del objeto en el formato <function>(<info>). |
|---|
| 103 | * |
|---|
| 104 | * @return la representación como cadena de texto del objeto en el formato <function>(<info>). |
|---|
| 105 | */ |
|---|
| 106 | @Override |
|---|
| 107 | public String toString() { |
|---|
| 108 | String res=""; |
|---|
| 109 | if (this.info!=null&&this.info.length()>0) { |
|---|
| 110 | res+= this.info; |
|---|
| 111 | } else { |
|---|
| 112 | res+= "<null>"; |
|---|
| 113 | } |
|---|
| 114 | return res; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | } |
|---|