Java tutorial
/* The MIT License (MIT) Copyright (c) 2015 QAXML Pty Ltd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.qatickets.domain; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.validation.constraints.NotNull; import org.apache.commons.lang3.time.DateFormatUtils; import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.SafeHtml; @SuppressWarnings("serial") @Entity @Table(name = "VERSION") public class Version implements Serializable { @Id @Column(name = "VERSION_ID") @GeneratedValue(strategy = GenerationType.AUTO) private int id; @NotBlank @SafeHtml @Column(name = "NAME", length = 128, nullable = false) private String name; @SafeHtml @Column(name = "DESCRIPTION", length = 256, nullable = false) private String description; @Column(name = "START_DATE") private Date startDate; @Column(name = "RELEASE_DATE") private Date releaseDate; @NotNull @Column(name = "RELEASED") private boolean released; @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PROJECT_ID") private Project project; public String getDescription() { return description; } public boolean isLate() { return this.releaseDate != null && this.releaseDate.before(new Date()) && false == released; } public void setDescription(String description) { this.description = description; } public int getId() { return id; } public Integer getIdAsInteger() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getStartDate() { return startDate; } public String getStartDateISO() { return startDate == null ? "" : DateFormatUtils.ISO_DATE_FORMAT.format(startDate); } public void setStartDate(Date startDate) { this.startDate = startDate; } public Date getReleaseDate() { return releaseDate; } public String getReleaseDateISO() { return releaseDate == null ? "" : DateFormatUtils.ISO_DATE_FORMAT.format(releaseDate); } public void setReleaseDate(Date releaseDate) { this.releaseDate = releaseDate; } public boolean isReleased() { return released; } public void setReleased(boolean released) { this.released = released; } public Project getProject() { return project; } public void setProject(Project project) { this.project = project; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Version other = (Version) obj; if (id != other.id) return false; return true; } @Override public String toString() { return "Version [id=" + id + ", name=" + name + "]"; } public static void main(String[] a) { // DD, dd MM yyyy // Wednesday, 14 May 2014 String d = new SimpleDateFormat("EEEE, dd MMM yyyy").format(new Date()); System.out.println(d); System.out.println(d.equals("Wednesday, 14 May 2014")); } }