Path: blob/master/test/jdk/javax/sql/testng/util/SuperHero.java
41153 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package util;2324import java.io.Serializable;25import java.sql.SQLData;26import java.sql.SQLException;27import java.sql.SQLInput;28import java.sql.SQLOutput;2930public class SuperHero implements SQLData, Serializable {3132private String first;33private String last;34private String type = "SUPERHERO";35private Integer firstYear;36private String secretIdentity;3738public SuperHero() {3940}4142public SuperHero(String sqlType, String fname, String lname, Integer year,43String identity) {44first = fname;45last = lname;46type = sqlType;47firstYear = year;48secretIdentity = identity;49}5051@Override52public String getSQLTypeName() throws SQLException {53return type;54}5556@Override57public void readSQL(SQLInput stream, String typeName) throws SQLException {58first = stream.readString();59last = stream.readString();60firstYear = stream.readInt();61secretIdentity = stream.readString();62}6364@Override65public void writeSQL(SQLOutput stream) throws SQLException {66stream.writeString(first);67stream.writeString(last);68stream.writeInt(firstYear);69stream.writeString(secretIdentity);70}7172@Override73public String toString() {74return "[ name =" + first + " " + last + " "75+ firstYear + " " + secretIdentity + " ]";76}7778public void setIdentity(String identity) {79secretIdentity = identity;80}8182public String getIdentity() {83return secretIdentity;84}8586@Override87public boolean equals(Object obj) {88if (this == obj) {89return true;90}91if (obj instanceof SuperHero) {92SuperHero ss = (SuperHero) obj;93return first.equals(ss.first) && last.equals(ss.last)94&& firstYear.equals(ss.firstYear)95&& type.equals(ss.type)96&& secretIdentity.equals(ss.secretIdentity);97}98return false;99}100101@Override102public int hashCode() {103return ((31 + first.hashCode()) * 31) * 31104+ ((31 + last.hashCode()) * 31) * 31105+ ((31 + firstYear.hashCode()) * 31) * 31106+ ((31 + type.hashCode()) * 31) * 31107+ secretIdentity.hashCode();108}109}110111112