Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,216 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.InputStreamResource; + +/** + * Utility class to create a graph of company model instances from an xml + * representation. + * + * @author Michael Bouschen + */ +public class CompanyModelReader extends XmlBeanFactory { + + /** The format of date values in the xml representation */ + public static final String DATE_PATTERN = "d/MMM/yyyy"; + + /** + * Create a CompanyModelReader for the specified resourceName. + * @param resourceName the name of the resource + */ + public CompanyModelReader(String resourceName) { + // Use the class loader of the Company class to find the resource + this(resourceName, Company.class.getClassLoader()); + } + + /** + * Create a CompanyModelReader for the specified resourceName. + * @param resourceName the name of the resource + */ + public CompanyModelReader(String resourceName, ClassLoader classLoader) { + super(new ClassPathResource(resourceName, classLoader)); + configureFactory(); + } + + /** + * Create a CompanyModelReader for the specified InputStream. + * @param stream the input stream + */ + public CompanyModelReader(InputStream stream) { + super(new InputStreamResource(stream)); + configureFactory(); + } + + /** + * Configure the CompanyModelReader, e.g. register CustomEditor classes + * to convert the string representation of a property into an instance + * of the right type. + */ + private void configureFactory() { + SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN, Locale.US); + formatter.setTimeZone(TimeZone.getTimeZone("America/New_York")); + CustomDateEditor dateEditor = + new CustomDateEditor(formatter, true); + registerCustomEditor(Date.class, dateEditor); + } + + // Convenience methods + + /** + * Convenience method returning an Address instance for the specified + * name. The method returns <code>null</code> if there is no Address + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Address bean. + */ + public Address getAddress(String name) { + return (Address)getBean(name, Address.class); + } + + /** + * Convenience method returning a Company instance for the specified + * name. The method returns <code>null</code> if there is no Company + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Company bean. + */ + public Company getCompany(String name) { + return (Company)getBean(name, Company.class); + } + + /** + * Convenience method returning a DentalInsurance instance for the + * specified name. The method returns <code>null</code> if there is no + * DentalInsurance bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * DentalInsurance bean. + */ + public DentalInsurance getDentalInsurance(String name) { + return (DentalInsurance)getBean(name, DentalInsurance.class); + } + + /** + * Convenience method returning a Department instance for the specified + * name. The method returns <code>null</code> if there is no Department + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Department bean. + */ + public Department getDepartment(String name) { + return (Department)getBean(name, Department.class); + } + + /** + * Convenience method returning an Employee instance for the specified + * name. The method returns <code>null</code> if there is no Employee + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Employee bean. + */ + public Employee getEmployee(String name) { + return (Employee)getBean(name, Employee.class); + } + + /** + * Convenience method returning a FullTimeEmployee instance for the + * specified name. The method returns <code>null</code> if there is no + * FullTimeEmployee bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * FullTimeEmployee bean. + */ + public FullTimeEmployee getFullTimeEmployee(String name) { + return (FullTimeEmployee)getBean(name, FullTimeEmployee.class); + } + + /** + * Convenience method returning an Insurance instance for the specified + * name. The method returns <code>null</code> if there is no Insurance + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Insurance bean. + */ + public Insurance getInsurance(String name) { + return (Insurance)getBean(name, Insurance.class); + } + + /** + * Convenience method returning a MedicalInsurance instance for the + * specified name. The method returns <code>null</code> if there is no + * MedicalInsurance bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * MedicalInsurance bean. + */ + public MedicalInsurance getMedicalInsurance(String name) { + return (MedicalInsurance)getBean(name, MedicalInsurance.class); + } + + /** + * Convenience method returning a PartTimeEmployee instance for the + * specified name. The method returns <code>null</code> if there is no + * PartTimeEmployee bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * PartTimeEmployee bean. + */ + public PartTimeEmployee getPartTimeEmployee(String name) { + return (PartTimeEmployee)getBean(name, PartTimeEmployee.class); + } + + /** + * Convenience method returning a Person instance for the specified + * name. The method returns <code>null</code> if there is no Person + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Person bean. + */ + public Person getPerson(String name) { + return (Person)getBean(name, Person.class); + } + + /** + * Convenience method returning a Project instance for the specified + * name. The method returns <code>null</code> if there is no Project + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or <code>null</code> if there no + * Project bean. + */ + public Project getProject(String name) { + return (Project)getBean(name, Project.class); + } + +} +
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/DentalInsurance.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/DentalInsurance.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/DentalInsurance.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/DentalInsurance.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,95 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.math.BigDecimal; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a dental insurance carrier selection for a + * particular <code>Employee</code>. + */ +public class DentalInsurance extends Insurance { + + private BigDecimal lifetimeOrthoBenefit; + + /** This is the JDO-required no-args constructor */ + protected DentalInsurance() {} + + /** + * Initialize a <code>DentalInsurance</code> instance. + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param lifetimeOrthoBenefit The lifetimeOrthoBenefit. + */ + public DentalInsurance(long insid, String carrier, + BigDecimal lifetimeOrthoBenefit) { + super(insid, carrier); + this.lifetimeOrthoBenefit = lifetimeOrthoBenefit; + } + + /** + * Initialize a <code>DentalInsurance</code> instance. + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param employee The employee associated with this insurance. + * @param lifetimeOrthoBenefit The lifetimeOrthoBenefit. + */ + public DentalInsurance(long insid, String carrier, Employee employee, + BigDecimal lifetimeOrthoBenefit) { + super(insid, carrier, employee); + this.lifetimeOrthoBenefit = lifetimeOrthoBenefit; + } + + /** + * Get the insurance lifetimeOrthoBenefit. + * @return The insurance lifetimeOrthoBenefit. + */ + public BigDecimal getLifetimeOrthoBenefit() { + return lifetimeOrthoBenefit; + } + + /** + * Set the insurance lifetimeOrthoBenefit. + * @param lifetimeOrthoBenefit The insurance lifetimeOrthoBenefit. + */ + public void setLifetimeOrthoBenefit(BigDecimal lifetimeOrthoBenefit) { + this.lifetimeOrthoBenefit = lifetimeOrthoBenefit; + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + DentalInsurance otherIns = (DentalInsurance)other; + return super.deepCompareFields(otherIns, helper) && + helper.equals(lifetimeOrthoBenefit, + otherIns.lifetimeOrthoBenefit); + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/DentalInsurance.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Department.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Department.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Department.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Department.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,355 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a department within a company. + */ +public class Department + implements Serializable, Comparable, DeepEquality { + + private long deptid; + private String name; + private Company company; + private Employee employeeOfTheMonth; + private transient Set employees = new HashSet(); // element type is Employee + private transient Set fundedEmps = new HashSet(); // element type is Employee + + /** This is the JDO-required no-args constructor */ + protected Department() {} + + /** + * Initialize a <code>Department</code> instance. + * @param deptid The department id. + * @param name The name of the department. + */ + public Department(long deptid, String name) { + this.deptid = deptid; + this.name = name; + } + + /** + * Initialize a <code>Department</code> instance. + * @param deptid The department id. + * @param name The name of the department. + * @param company The company that the department is associated with. + */ + public Department(long deptid, String name, Company company) { + this.deptid = deptid; + this.name = name; + this.company = company; + } + + /** + * Initialize a <code>Department</code> instance. + * @param deptid The department id. + * @param name The name of the department. + * @param company The company that the department is associated with. + * @param employeeOfTheMonth The employee of the month the + * department is associated with. + */ + public Department(long deptid, String name, Company company, + Employee employeeOfTheMonth) { + this.deptid = deptid; + this.name = name; + this.company = company; + this.employeeOfTheMonth = employeeOfTheMonth; + } + + /** + * Get the department id. + * @return The department id. + */ + public long getDeptid() { + return deptid; + } + + /** + * Get the name of the department. + * @return The name of the department. + */ + public String getName() { + return name; + } + + /** + * Set the name of the department. + * @param name The name to set for the department. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the company associated with the department. + * @return The company. + */ + public Company getCompany() { + return company; + } + + /** + * Set the company for the department. + * @param company The company to associate with the department. + */ + public void setCompany(Company company) { + this.company = company; + } + + /** + * Get the employee of the month associated with the department. + * @return The employee of the month. + */ + public Employee getEmployeeOfTheMonth() { + return employeeOfTheMonth; + } + + /** + * Set the employee of the month for the department. + * @param employeeOfTheMonth The employee of the month to + * associate with the department. + */ + public void setEmployeeOfTheMonth(Employee employeeOfTheMonth) { + this.employeeOfTheMonth = employeeOfTheMonth; + } + + /** + * Get the employees in the department as an unmodifiable set. + * @return The set of employees in the department, as an unmodifiable + * set. + */ + public Set getEmployees() { + return Collections.unmodifiableSet(employees); + } + + /** + * Add an employee to the department. + * @param emp The employee to add to the department. + */ + public void addEmployee(Employee emp) { + employees.add(emp); + } + + /** + * Remove an employee from the department. + * @param emp The employee to remove from the department. + */ + public void removeEmployee(Employee emp) { + employees.remove(emp); + } + + /** + * Set the employees to be in this department. + * @param employees The set of employees for this department. + */ + public void setEmployees(Set employees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.employees = (employees != null) ? new HashSet(employees) : null; + } + + /** + * Get the funded employees in the department as an unmodifiable set. + * @return The set of funded employees in the department, as an + * unmodifiable set. + */ + public Set getFundedEmps() { + return Collections.unmodifiableSet(fundedEmps); + } + + /** + * Add an employee to the collection of funded employees of this + * department. + * @param emp The employee to add to the department. + */ + public void addFundedEmp(Employee emp) { + fundedEmps.add(emp); + } + + /** + * Remove an employee from collection of funded employees of this + * department. + * @param emp The employee to remove from the department. + */ + public void removeFundedEmp(Employee emp) { + fundedEmps.remove(emp); + } + + /** + * Set the funded employees to be in this department. + * @param employees The set of funded employees for this department. + */ + public void setFundedEmps(Set employees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.fundedEmps = (fundedEmps != null) ? new HashSet(employees) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + employees = new HashSet(); + fundedEmps = new HashSet(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Department otherDept = (Department)other; + return (deptid == otherDept.deptid) && + helper.equals(name, otherDept.name) && + helper.deepEquals(company, otherDept.company) && + helper.deepEquals(employeeOfTheMonth, otherDept.employeeOfTheMonth) && + helper.deepEquals(employees, otherDept.employees) && + helper.deepEquals(fundedEmps, otherDept.fundedEmps); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((Department)o); + } + + /** + * Compares this object with the specified Department object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Department object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified + * Department object. + */ + public int compareTo(Department other) { + long otherId = other.deptid; + return (deptid < otherId ? -1 : (deptid == otherId ? 0 : 1)); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return <code>true</code> if this object is the same as the obj + * argument; <code>false</code> otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof Department) { + return compareTo((Department)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)deptid; + } + + /** + * The application identity class associated with the + * <code>Department</code> class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the application identifier field + * for the <code>Department</code> class. + * It must match in name and type with the field in the + * <code>Department</code> class. + */ + public long deptid; + + /** + * The required public, no-arg constructor. + */ + public Oid() { } + + /** + * A constructor to initialize the identifier field. + * @param deptid the deptid of the Department. + */ + public Oid(long deptid) { + this.deptid = deptid; + } + + public Oid(String s) { deptid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + deptid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o = (Oid) obj; + if( this.deptid != o.deptid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) deptid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( deptid < other.deptid ) return -1; + if( deptid > other.deptid ) return 1; + return 0; + } + + } + +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Department.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Employee.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Employee.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Employee.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Employee.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,414 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents an employee. + */ +public abstract class Employee extends Person { + + private Date hiredate; + private double weeklyhours; + private DentalInsurance dentalInsurance; + private MedicalInsurance medicalInsurance; + private Department department; + private Department fundingDept; + private Employee manager; + private Employee mentor; + private Employee protege; + private Employee hradvisor; + private transient Set reviewedProjects = new HashSet(); // element-type is Project + private transient Set projects = new HashSet(); // element-type is Project + private transient Set team = new HashSet(); // element-type is Employee + private transient Set hradvisees = new HashSet(); // element-type is Employee + + /** This is the JDO-required no-args constructor */ + protected Employee() {} + + /** + * Initialize an <code>Employee</code> instance. + * @param personid The identifier for the person. + * @param firstname The first name of the employee. + * @param lastname The last name of the employee. + * @param middlename The middle name of the employee. + * @param birthdate The birth date of the employee. + * @param address The address of the employee. + * @param hiredate The date that the employee was hired. + */ + public Employee(long personid, String firstname, String lastname, + String middlename, Date birthdate, Address address, + Date hiredate) { + super(personid, firstname, lastname, middlename, birthdate, address); + this.hiredate = hiredate; + } + + /** + * Get the date that the employee was hired. + * @return The date the employee was hired. + */ + public Date getHiredate() { + return hiredate; + } + + /** + * Set the date that the employee was hired. + * @param hiredate The date the employee was hired. + */ + public void setHiredate(Date hiredate) { + this.hiredate = hiredate; + } + + /** + * Get the weekly hours of the employee. + * @return The number of hours per week that the employee works. + */ + public double getWeeklyhours() { + return weeklyhours; + } + + /** + * Set the number of hours per week that the employee works. + * @param weeklyhours The number of hours per week that the employee + * works. + */ + public void setWeeklyhours(double weeklyhours) { + this.weeklyhours = weeklyhours; + } + + /** + * Get the reviewed projects. + * @return The reviewed projects as an unmodifiable set. + */ + public Set getReviewedProjects() { + return Collections.unmodifiableSet(reviewedProjects); + } + + /** + * Add a reviewed project. + * @param project A reviewed project. + */ + public void addReviewedProjects(Project project) { + reviewedProjects.add(project); + } + + /** + * Remove a reviewed project. + * @param project A reviewed project. + */ + public void removeReviewedProject(Project project) { + reviewedProjects.remove(project); + } + + /** + * Set the reviewed projects for the employee. + * @param reviewedProjects The set of reviewed projects. + */ + public void setReviewedProjects(Set reviewedProjects) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.reviewedProjects = + (reviewedProjects != null) ? new HashSet(reviewedProjects) : null; + } + + /** + * Get the employee's projects. + * @return The employee's projects are returned as an unmodifiable + * set. + */ + public Set getProjects() { + return Collections.unmodifiableSet(projects); + } + + /** + * Add a project for the employee. + * @param project The project. + */ + public void addProject(Project project) { + projects.add(project); + } + + /** + * Remove a project from an employee's set of projects. + * @param project The project. + */ + public void removeProject(Project project) { + projects.remove(project); + } + + /** + * Set the projects for the employee. + * @param projects The set of projects of the employee. + */ + public void setProjects(Set projects) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.projects = (projects != null) ? new HashSet(projects) : null; + } + + /** + * Get the dental insurance of the employee. + * @return The employee's dental insurance. + */ + public DentalInsurance getDentalInsurance() { + return dentalInsurance; + } + + /** + * Set the dental insurance object for the employee. + * @param dentalInsurance The dental insurance object to associate with + * the employee. + */ + public void setDentalInsurance(DentalInsurance dentalInsurance) { + this.dentalInsurance = dentalInsurance; + } + /** + * Get the medical insurance of the employee. + * @return The employee's medical insurance. + */ + public MedicalInsurance getMedicalInsurance() { + return medicalInsurance; + } + + /** + * Set the medical insurance object for the employee. + * @param medicalInsurance The medical insurance object to associate + * with the employee. + */ + public void setMedicalInsurance(MedicalInsurance medicalInsurance) { + this.medicalInsurance = medicalInsurance; + } + + /** + * Get the employee's department. + * @return The department associated with the employee. + */ + public Department getDepartment() { + return department; + } + + /** + * Set the employee's department. + * @param department The department. + */ + public void setDepartment(Department department) { + this.department = department; + } + + /** + * Get the employee's funding department. + * @return The funding department associated with the employee. + */ + public Department getFundingDept() { + return fundingDept; + } + + /** + * Set the employee's funding department. + * @param department The funding department. + */ + public void setFundingDept(Department department) { + this.fundingDept = department; + } + + /** + * Get the employee's manager. + * @return The employee's manager. + */ + public Employee getManager() { + return manager; + } + + /** + * Set the employee's manager. + * @param manager The employee's manager. + */ + public void setManager(Employee manager) { + this.manager = manager; + } + + /** + * Get the employee's team. + * @return The set of <code>Employee</code>s on this employee's team, + * returned as an unmodifiable set. + */ + public Set getTeam() { + return Collections.unmodifiableSet(team); + } + + /** + * Add an <code>Employee</code> to this employee's team. + * This method sets both sides of the relationship, modifying + * this employees team to include parameter emp and modifying + * emp to set its manager attribute to this object. + * @param emp The <code>Employee</code> to add to the team. + */ + public void addToTeam(Employee emp) { + team.add(emp); + emp.manager = this; + } + + /** + * Remove an <code>Employee</code> from this employee's team. + * This method will also set the <code>emp</code> manager to null. + * @param emp The <code>Employee</code> to remove from the team. + */ + public void removeFromTeam(Employee emp) { + team.remove(emp); + emp.manager = null; + } + + /** + * Set the employee's team. + * @param team The set of <code>Employee</code>s. + */ + public void setTeam(Set team) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.team = (team != null) ? new HashSet(team) : null; + } + + /** + * Set the mentor for this employee and also set the inverse protege + * relationship. + * @param mentor The mentor for this employee. + */ + public void setMentor(Employee mentor) { + this.mentor = mentor; + mentor.protege = this; + } + + /** + * Get the mentor for this employee. + * @return The mentor. + */ + public Employee getMentor() { + return mentor; + } + + /** + * Get the protege of this employee. + * @return The protege of this employee. + */ + public Employee getProtege() { + return protege; + } + + /** + * Get the HR advisor for the employee. + * @return The HR advisor. + */ + public Employee getHradvisor() { + return hradvisor; + } + + /** + * Get the HR advisees of this HR advisor. + * @return An unmodifiable <code>Set</code> containing the + * <code>Employee</code>s that are HR advisees of this employee. + */ + public Set getHradvisees() { + return Collections.unmodifiableSet(hradvisees); + } + + /** + * Add an <code>Employee</code> as an advisee of this HR advisor. + * This method also sets the <code>emp</code> hradvisor to reference + * this object. In other words, both sides of the relationship are + * set. + * @param emp The employee to add as an advisee. + */ + public void addAdvisee(Employee emp) { + hradvisees.add(emp); + emp.hradvisor = this; + } + + /** + * Remove an <code>Employee</code> as an advisee of this HR advisor. + * This method also sets the <code>emp</code> hradvisor to null. + * In other words, both sides of the relationship are set. + * @param emp The employee to add as an HR advisee. + */ + public void removeAdvisee(Employee emp) { + hradvisees.remove(emp); + emp.hradvisor = null; + } + + /** + * Set the HR advisees of this HR advisor. + * @param hradvisees The <code>Employee</code>s that are HR advisees of + * this employee. + */ + public void setHradvisees(Set hradvisees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.hradvisees = (hradvisees != null) ? new HashSet(hradvisees) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + reviewedProjects = new HashSet(); + projects = new HashSet(); + team = new HashSet(); + hradvisees = new HashSet(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the corresponding fields of the specified Employee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Employee otherEmp = (Employee)other; + return super.deepCompareFields(otherEmp, helper) && + helper.equals(hiredate, otherEmp.hiredate) && + helper.closeEnough(weeklyhours, otherEmp.weeklyhours) && + helper.deepEquals(dentalInsurance, otherEmp.dentalInsurance) && + helper.deepEquals(medicalInsurance, otherEmp.medicalInsurance) && + helper.deepEquals(department, otherEmp.department) && + helper.deepEquals(fundingDept, otherEmp.fundingDept) && + helper.deepEquals(manager, otherEmp.manager) && + helper.deepEquals(mentor, otherEmp.mentor) && + helper.deepEquals(protege, otherEmp.protege) && + helper.deepEquals(hradvisor, otherEmp.hradvisor) && + helper.deepEquals(reviewedProjects, otherEmp.reviewedProjects) && + helper.deepEquals(projects, otherEmp.projects) && + helper.deepEquals(team, otherEmp.team) && + helper.deepEquals(hradvisees, otherEmp.hradvisees); + } + +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Employee.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,95 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a full-time employee. + */ +public class FullTimeEmployee extends Employee { + + private double salary; + + /** This is the JDO-required no-args constructor */ + protected FullTimeEmployee() {} + + /** + * Initialize a full-time employee. + * @param personid The person identifier. + * @param first The person's first name. + * @param last The person's last name. + * @param middle The person's middle name. + * @param born The person's birthdate. + * @param addr The person's address. + * @param hired The date that the person was hired. + * @param sal The salary of the full-time employee. + */ + public FullTimeEmployee(long personid, String first, String last, + String middle, Date born, Address addr, + Date hired, double sal) { + super(personid, first, last, middle, born, addr, hired); + salary = sal; + } + + /** + * Get the salary of the full time employee. + * @return The salary of the full time employee. + */ + public double getSalary() { + return salary; + } + + /** + * Set the salary for the full-time employee. + * @param salary The salary to set for the full-time employee. + */ + public void setSalary(double salary) { + this.salary = salary; + } + + /** */ + public String toString() { + StringBuffer rc = new StringBuffer("FullTimeEmployee: "); + rc.append(super.toString()); + rc.append(" $" + salary); + return rc.toString(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified + * FullTimeEmployee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + FullTimeEmployee otherEmp = (FullTimeEmployee)other; + return super.deepCompareFields(otherEmp, helper) && + helper.closeEnough(salary, otherEmp.salary); + } + +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Insurance.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Insurance.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Insurance.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Insurance.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,239 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.io.Serializable; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents an insurance carrier selection for a particular + * <code>Employee</code>. + */ +public abstract class Insurance + implements Serializable, Comparable, DeepEquality { + + private long insid; + private String carrier; + private Employee employee; + + /** This is the JDO-required no-args constructor. */ + protected Insurance() {} + + /** + * Initialize an <code>Insurance</code> instance. + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + */ + protected Insurance(long insid, String carrier) { + this.insid = insid; + this.carrier = carrier; + } + + /** + * Initialize an <code>Insurance</code> instance. + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param employee The employee associated with this insurance. + */ + protected Insurance(long insid, String carrier, Employee employee) { + this.insid = insid; + this.carrier = carrier; + this.employee = employee; + } + + /** + * Get the insurance ID. + * @return the insurance ID. + */ + public long getInsid() { + return insid; + } + + /** + * Set the insurance ID. + * @param insid The insurance ID value. + */ + public void setInsid(long insid) { + this.insid = insid; + } + + /** + * Get the insurance carrier. + * @return The insurance carrier. + */ + public String getCarrier() { + return carrier; + } + + /** + * Set the insurance carrier. + * @param carrier The insurance carrier. + */ + public void setCarrier(String carrier) { + this.carrier = carrier; + } + + /** + * Get the associated employee. + * @return The employee for this insurance. + */ + public Employee getEmployee() { + return employee; + } + + /** + * Set the associated employee. + * @param employee The associated employee. + */ + public void setEmployee(Employee employee) { + this.employee = employee; + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Insurance otherInd = (Insurance)other; + return (insid == otherInd.insid) && + helper.equals(carrier, otherInd.carrier) && + helper.deepEquals(employee, otherInd.employee); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((Insurance)o); + } + + /** + * Compares this object with the specified Insurance object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Insurance object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified + * Insurance object. + */ + public int compareTo(Insurance other) { + long otherId = other.insid; + return (insid < otherId ? -1 : (insid == otherId ? 0 : 1)); + } + + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return <code>true</code> if this object is the same as the obj + * argument; <code>false</code> otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof Insurance) { + return compareTo((Insurance)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)insid; + } + + /** + * This class is used to represent the application + * identifier for the <code>Insurance</code> class. + */ + public static class Oid implements Serializable, Comparable + { + /** + * This field represents the application identifier for the + * <code>Insurance</code> class. It must match the field in the + * <code>Insurance</code> class in both name and type. + */ + public long insid; + + /** + * The required public no-args constructor. + */ + public Oid() { } + + /** + * Initialize with an insurance identifier. + * @param insid the insurance ID. + */ + public Oid(long insid) { + this.insid = insid; + } + + public Oid(String s) { insid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + insid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o=(Oid) obj; + if( this.insid!=o.insid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) insid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( insid < other.insid ) return -1; + if( insid > other.insid ) return 1; + return 0; + } + + } + +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Insurance.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,115 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.io.Serializable; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a dental insurance carrier selection for a + * particular <code>Employee</code>. + */ +public class MedicalInsurance extends Insurance { + + private String planType; // possible values: "PPO", "EPO", "NPO" + + /** This is the JDO-required no-args constructor */ + protected MedicalInsurance() {} + + /** + * Initialize a <code>MedicalInsurance</code> instance. + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param planType The planType. + */ + public MedicalInsurance(long insid, String carrier, + String planType) + { + super(insid, carrier); + this.planType = planType; + } + + /** + * Initialize a <code>MedicalInsurance</code> instance. + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param employee The employee associated with this insurance. + * @param planType The planType. + */ + public MedicalInsurance(long insid, String carrier, + Employee employee, String planType) + { + super(insid, carrier, employee); + this.planType = planType; + } + + /** + * Get the insurance planType. + * @return The insurance planType. + */ + public String getPlanType() { + return planType; + } + + /** + * Set the insurance planType. + * @param planType The insurance planType. + */ + public void setPlanType(String planType) { + this.planType = planType; + } + + /** + * Indicates whether some other object is "deep equal to" this one. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if this object is deep equal to the + * specified object; <code>false</code> otherwise. + */ + public boolean deepEquals(DeepEquality other, EqualityHelper helper) { + if (this == other) + return true; + if (!(other instanceof MedicalInsurance)) + return false; + if (helper.isProcessed(this)) + return true; + helper.markProcessed(this); + return deepCompareFields((MedicalInsurance)other, helper); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + MedicalInsurance otherIns = (MedicalInsurance)other; + return super.deepCompareFields(otherIns, helper) && + helper.equals(planType, otherIns.planType); + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/PartTimeEmployee.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/PartTimeEmployee.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/PartTimeEmployee.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/PartTimeEmployee.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,93 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a part-time employee. + */ +public class PartTimeEmployee extends Employee { + private double wage; + + /** This is the JDO-required no-args constructor. */ + protected PartTimeEmployee() {} + + /** + * Initialize a part-time employee. + * @param personid The identifier for the person. + * @param first The person's first name. + * @param last The person's last name. + * @param middle The person's middle name. + * @param born The person's birthdate. + * @param addr The person's address. + * @param hired The date the person was hired. + * @param wage The person's wage. + */ + public PartTimeEmployee(long personid, String first, String last, + String middle, Date born, Address addr, + Date hired, double wage ) { + super(personid, first, last, middle, born, addr, hired); + this.wage = wage; + } + + /** + * Get the wage of the part-time employee. + * @return The wage of the part-time employee. + */ + public double getWage() { + return wage; + } + + /** + * Set the wage of the part-time employee. + * @param wage The wage of the part-time employee. + */ + public void setWage(double wage) { + this.wage = wage; + } + + /** */ + public String toString() { + StringBuffer rc = new StringBuffer("PartTimeEmployee: "); + rc.append(super.toString()); + rc.append(" $" + wage); + return rc.toString(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified + * PartTimeEmployee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(PartTimeEmployee other, + EqualityHelper helper) { + PartTimeEmployee otherEmp = (PartTimeEmployee)other; + return super.deepCompareFields(otherEmp, helper) && + helper.closeEnough(wage, otherEmp.wage); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/PartTimeEmployee.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Person.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Person.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Person.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Person.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,367 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.jdo.tck.pc.company; + +import java.io.Serializable; + +import java.text.SimpleDateFormat; + +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a person. + */ +public class Person + implements Serializable, Comparable, DeepEquality { + + private long personid; + private String firstname; + private String lastname; + private String middlename; + private Date birthdate; + private Address address; + + // maps phone number types ("home", "work", "mobile", etc.) + // to phone numbers specified as String + private Map phoneNumbers = new HashMap(); + + protected static SimpleDateFormat formatter = + new SimpleDateFormat("d/MMM/yyyy"); + + /** This is the JDO-required no-args constructor. */ + protected Person() {} + + /** + * Initialize a <code>Person</code> instance. + * @param personid The person identifier. + * @param firstname The person's first name. + * @param lastname The person's last name. + * @param middlename The person's middle name. + * @param birthdate The person's birthdate. + * @param address The person's address. + */ + public Person(long personid, String firstname, String lastname, + String middlename, Date birthdate, Address address) { + this.personid = personid; + this.firstname = firstname; + this.lastname = lastname; + this.middlename = middlename; + this.address = address; + this.birthdate = birthdate; + } + + /** + * Get the person's id. + * @return The personid. + */ + public long getPersonid() { + return personid; + } + + /** + * Set the person's id. + * @param personid The personid. + */ + public void setLastname(long personid) { + this.personid = personid; + } + + /** + * Get the person's last name. + * @return The last name. + */ + public String getLastname() { + return lastname; + } + + /** + * Set the person's last name. + * @param lastname The last name. + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * Get the person's first name. + * @return The first name. + */ + public String getFirstname() { + return firstname; + } + + /** + * Set the person's first name. + * @param firstname The first name. + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * Get the person's middle name. + * @return The middle name. + */ + public String getMiddlename() { + return middlename; + } + + /** + * Set the person's middle name. + * @param middlename The middle name. + */ + public void setMiddlename(String middlename) { + this.middlename = middlename; + } + + /** + * Get the address. + * @return The address. + */ + public Address getAddress() { + return address; + } + + /** + * Set the address. + * @param address The address. + */ + public void setAddress(Address address) { + this.address = address; + } + + /** + * Get the person's birthdate. + * @return The person's birthdate. + */ + public Date getBirthdate() { + return birthdate; + } + + /** + * Set the person's birthdate. + * @param birthdate The person's birthdate. + */ + public void setBirthdate(Date birthdate) { + this. birthdate = birthdate; + } + + /** + * Get the map of phone numbers as an unmodifiable map. + * @return The map of phone numbers, as an unmodifiable map. + */ + public Map getPhoneNumbers() { + return Collections.unmodifiableMap(phoneNumbers); + } + + /** + * Get the phone number for the specified phone number type. + * @param type The phone number type ("home", "work", "mobile", etc.). + * @return The phone number associated with specified type, or + * <code>null</code> if there was no phone number for the type. + */ + public String getPhoneNumber(String type) { + return (String)phoneNumbers.get(type); + } + + /** + * Associates the specified phone number with the specified type in the + * map of phone numbers of this person. + * @param type The phone number type ("home", "work", "mobile", etc.). + * @param phoneNumber The phone number + * @return The previous phone number associated with specified type, or + * <code>null</code> if there was no phone number for the type. + */ + public String putPhoneNumber(String type, String phoneNumber) { + return (String)phoneNumbers.put(type, phoneNumber); + } + + /** + * Remove a phoneNumber from the map of phone numbers. + * @param type The phone number type ("home", "work", "mobile", etc.). + * @return The previous phone number associated with specified type, or + * <code>null</code> if there was no phone number for the type. + */ + public String removePhoneNumber(String type) { + return (String)phoneNumbers.remove(type); + } + + /** + * Set the phoneNumber map to be in this person. + * @param phoneNumbers The map of phoneNumbers for this person. + */ + public void setPhoneNumbers(Map phoneNumbers) { + // workaround: create a new HashMap, because fostore does not + // support LinkedHashMap + this.phoneNumbers = + (phoneNumbers != null) ? new HashMap(phoneNumbers) : null; + } + + /** + * Return a String representation of a <code>Person</code> object. + */ + public String toString() { + StringBuffer rc = new StringBuffer("Person: "); + rc.append(personid); + rc.append(", "); + rc.append(lastname); + rc.append(", " + firstname); + rc.append(", born " + formatter.format(birthdate)); + rc.append(", phone " + phoneNumbers); + return rc.toString(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Person otherPerson = (Person)other; + return (personid == otherPerson.personid) && + helper.equals(firstname, otherPerson.firstname) && + helper.equals(lastname, otherPerson.lastname) && + helper.equals(middlename, otherPerson.middlename) && + helper.equals(birthdate, otherPerson.birthdate) && + helper.deepEquals(address, otherPerson.address) && + helper.deepEquals(phoneNumbers, otherPerson.phoneNumbers); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((Person)o); + } + + /** + * Compares this object with the specified Person object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Person object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Person + * object. + */ + public int compareTo(Person other) { + long otherId = other.personid; + return (personid < otherId ? -1 : (personid == otherId ? 0 : 1)); + } + + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return <code>true</code> if this object is the same as the obj + * argument; <code>false</code> otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof Person) { + return compareTo((Person)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)personid; + } + /** + * This class is used to represent the application identifier + * for the <code>Person</code> class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the identifier for the <code>Person</code> + * class. It must match a field in the <code>Person</code> class in + * both name and type. + */ + public long personid; + + /** + * The required public no-arg constructor. + */ + public Oid() { } + + /** + * Initialize the identifier. + * @param personid The person identifier. + */ + public Oid(long personid) { + this.personid = personid; + } + + public Oid(String s) { personid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + personid;} + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || + !this.getClass().equals(obj.getClass()) ) return( false ); + Oid o = (Oid) obj; + if( this.personid != o.personid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) personid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( personid < other.personid ) return -1; + if( personid > other.personid ) return 1; + return 0; + } + + } + +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Person.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Project.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Project.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Project.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Project.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,308 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.company; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Set; +import java.util.HashSet; +import java.math.BigDecimal; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a project, a budgeted task with one or more + * employees working on it. + */ +public class Project + implements Serializable, Comparable, DeepEquality { + + private long projid; + private String name; + private BigDecimal budget; + private transient Set reviewers = new HashSet(); // element type is Employee + private transient Set members = new HashSet(); // element type is Employee + + /** This is the JDO-required no-args constructor. */ + protected Project() {} + + /** + * Initialize a project. + * @param projid The project identifier. + * @param name The name of the project. + * @param budget The budget for the project. + */ + public Project(long projid, String name, BigDecimal budget) { + this.projid = projid; + this.name = name; + this.budget = budget; + } + + /** + * Get the project ID. + * @return The project ID. + */ + public long getProjid() { + return projid; + } + + /** + * Get the name of the project. + * @return The name of the project. + */ + public String getName() { + return name; + } + + /** + * Set the name of the project. + * @param name The name of the project. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the project's budget. + * @return The project's budget. + */ + public BigDecimal getBudget() { + return budget; + } + + /** + * Set the project's budget. + * @param budget The project's budget. + */ + public void setBudget(BigDecimal budget) { + this.budget = budget; + } + + /** + * Get the reviewers associated with this project. + */ + public Set getReviewers() { + return Collections.unmodifiableSet(reviewers); + } + + /** + * Add a reviewer to the project. + * @param emp The employee to add as a reviewer. + */ + public void addReviewer(Employee emp) { + reviewers.add(emp); + } + + /** + * Remove a reviewer from the project. + * @param emp The employee to remove as a reviewer of this project. + */ + public void removeReviewer(Employee emp) { + reviewers.remove(emp); + } + + /** + * Set the reviewers associated with this project. + * @param reviewers The set of reviewers to associate with this project. + */ + public void setReviewers(Set reviewers) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.reviewers = (reviewers != null) ? new HashSet(reviewers) : null; + } + + /** + * Get the project members. + * @return The members of the project is returned as an unmodifiable + * set of <code>Employee</code>s. + */ + public Set getMembers() { + return Collections.unmodifiableSet(members); + } + + /** + * Add a new member to the project. + * @param emp The employee to add to the project. + */ + public void addMember(Employee emp) { + members.add(emp); + } + + /** + * Remove a member from the project. + * @param emp The employee to remove from the project. + */ + public void removeMember(Employee emp) { + members.remove(emp); + } + + /** + * Set the members of the project. + * @param employees The set of employees to be the members of this + * project. + */ + public void setMembers(Set employees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.members = (members != null) ? new HashSet(employees) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + reviewers = new HashSet(); + members = new HashSet(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Project otherProject = (Project)other; + return (projid == otherProject.projid) && + helper.equals(name, otherProject.name) && + helper.equals(budget, otherProject.budget) && + helper.deepEquals(reviewers, otherProject.reviewers) && + helper.deepEquals(members, otherProject.members); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((Project)o); + } + + /** + * Compares this object with the specified Project object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Project object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Project + * object. + */ + public int compareTo(Project other) { + long otherId = other.projid; + return (projid < otherId ? -1 : (projid == otherId ? 0 : 1)); + } + + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return <code>true</code> if this object is the same as the obj + * argument; <code>false</code> otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof Project) { + return compareTo((Project)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)projid; + } + + /** + * This class is used to represent the application identity + * for the <code>Project</code> class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the identifier for the + * <code>Project</code> class. It must match a field in the + * <code>Project</code> class in both name and type. + */ + public long projid; + + /** + * The required public no-arg constructor. + */ + public Oid() { } + + /** + * Initialize the application identifier with a project ID. + * @param projid The id of the project. + */ + public Oid(long projid) { + this.projid = projid; + } + + public Oid(String s) { projid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + projid;} + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o = (Oid) obj; + if( this.projid != o.projid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) projid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( projid < other.projid ) return -1; + if( projid > other.projid ) return 1; + return 0; + } + + } + +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Project.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/company.jpg URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/company.jpg?view=auto&rev=160090 ============================================================================== Binary file - no diff available. Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/company.jpg ------------------------------------------------------------------------------ svn:executable = * Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/company.jpg ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream