All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.googlecode.genericdao.model.Project Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
/* Copyright 2009 The Revere Group
 * 
 * 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 test.googlecode.genericdao.model;

import java.util.Calendar;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;


@Entity
public class Project {
	private Long id;
	private String name;
	private Integer inceptionYear;
	private Set members;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getInceptionYear() {
		return inceptionYear;
	}

	public void setInceptionYear(Integer inceptionYear) {
		this.inceptionYear = inceptionYear;
	}
	
	@ManyToMany
	public Set getMembers() {
		return members;
	}

	public void setMembers(Set members) {
		this.members = members;
	}

	/**
	 * Calculated property
	 */
	@Transient
	public int getDuration() {
		if (inceptionYear == null)
			return 0;
		return Calendar.getInstance().get(Calendar.YEAR) - inceptionYear;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((inceptionYear == null) ? 0 : inceptionYear.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Project other = (Project) obj;
		if (inceptionYear == null) {
			if (other.inceptionYear != null)
				return false;
		} else if (!inceptionYear.equals(other.inceptionYear))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	public String toString() {
		return "Project::id:" + id + ",name:" + name + ",inceptionYear:" + inceptionYear + ",duration:" + getDuration();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy