1 /* ======================================================================== 2 * JCommon : a free general purpose class library for the Java(tm) platform 3 * ======================================================================== 4 * 5 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6 * 7 * Project Info: http://www.jfree.org/jcommon/index.html 8 * 9 * This library is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU Lesser General Public License as published by 11 * the Free Software Foundation; either version 2.1 of the License, or 12 * (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 * License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 * USA. 23 * 24 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25 * in the United States and other countries.] 26 * 27 * ------------- 28 * TypeInfo.java 29 * ------------- 30 * (C)opyright 2003, 2004, by Thomas Morgner and Contributors. 31 * 32 * Original Author: Thomas Morgner; 33 * Contributor(s): David Gilbert (for Object Refinery Limited); 34 * 35 * $Id: TypeInfo.java,v 1.2 2005/10/18 13:32:37 mungady Exp $ 36 * 37 * Changes 38 * ------- 39 * 21.06.2003 : Initial version 40 * 41 */ 42 43 package org.jfree.xml.generator.model; 44 45 /** 46 * Retains information about a type. 47 */ 48 public class TypeInfo { 49 50 /** The type name. */ 51 private String name; 52 53 /** The class. */ 54 private Class type; 55 56 /** A flag indicating whether or not the type can take a null value. */ 57 private boolean nullable; 58 59 /** ??. */ 60 private boolean constrained; 61 62 /** A description. */ 63 private String description; 64 65 /** Comments. */ 66 private Comments comments; 67 68 /** 69 * Creates a new instance. 70 * 71 * @param name the type name (<code>null</code> not permitted). 72 * @param type the class. 73 */ TypeInfo(final String name, final Class type)74 public TypeInfo(final String name, final Class type) { 75 if (name == null) { 76 throw new NullPointerException("Name"); 77 } 78 this.name = name; 79 this.type = type; 80 } 81 82 /** 83 * Returns the class. 84 * 85 * @return The class. 86 */ getType()87 public Class getType() { 88 return this.type; 89 } 90 91 /** 92 * Returns the nullable status. 93 * 94 * @return A boolean. 95 */ isNullable()96 public boolean isNullable() { 97 return this.nullable; 98 } 99 100 /** 101 * Sets the nullable flag. 102 * 103 * @param nullable the flag. 104 */ setNullable(final boolean nullable)105 public void setNullable(final boolean nullable) { 106 this.nullable = nullable; 107 } 108 109 /** 110 * Returns <code>true</code> if the type is constrained, and <code>false</code> otherwise. 111 * 112 * @return A boolean. 113 */ isConstrained()114 public boolean isConstrained() { 115 return this.constrained; 116 } 117 118 /** 119 * Sets the flag that indicates whether or not the type is constrained. 120 * 121 * @param constrained the flag. 122 */ setConstrained(final boolean constrained)123 public void setConstrained(final boolean constrained) { 124 this.constrained = constrained; 125 } 126 127 /** 128 * Returns the type description. 129 * 130 * @return The type description. 131 */ getDescription()132 public String getDescription() { 133 return this.description; 134 } 135 136 /** 137 * Sets the type description. 138 * 139 * @param description the description. 140 */ setDescription(final String description)141 public void setDescription(final String description) { 142 this.description = description; 143 } 144 145 /** 146 * Returns the type name. 147 * 148 * @return The type name. 149 */ getName()150 public String getName() { 151 return this.name; 152 } 153 154 /** 155 * Returns the comments for this type info. 156 * 157 * @return The comments. 158 */ getComments()159 public Comments getComments() { 160 return this.comments; 161 } 162 163 /** 164 * Sets the comments for this type info. 165 * 166 * @param comments the comments. 167 */ setComments(final Comments comments)168 public void setComments(final Comments comments) { 169 this.comments = comments; 170 } 171 /** 172 * Tests this object for equality with another object. 173 * 174 * @param o the other object. 175 * 176 * @return A boolean. 177 */ equals(final Object o)178 public boolean equals(final Object o) { 179 if (this == o) { 180 return true; 181 } 182 if (!(o instanceof TypeInfo)) { 183 return false; 184 } 185 186 final TypeInfo typeInfo = (TypeInfo) o; 187 188 if (!this.name.equals(typeInfo.name)) { 189 return false; 190 } 191 if (!this.type.equals(typeInfo.type)) { 192 return false; 193 } 194 195 return true; 196 } 197 198 /** 199 * Returns a hash code for this object. 200 * 201 * @return A hash code. 202 */ hashCode()203 public int hashCode() { 204 int result; 205 result = this.name.hashCode(); 206 result = 29 * result + this.type.hashCode(); 207 result = 29 * result + (this.nullable ? 1 : 0); 208 result = 29 * result + (this.constrained ? 1 : 0); 209 result = 29 * result + (this.description != null ? this.description.hashCode() : 0); 210 return result; 211 } 212 213 } 214