@Override public int hashCode() { if (this.getId() != StudyImpl.UNSAVED_ID) { return (int) getId(); } else { final int PRIME = 37; int hashcode = 1; if (getName() != null) hashcode = PRIME * hashcode + getName().hashCode(); if (getAlias() != null) hashcode = PRIME * hashcode + getAlias().hashCode(); return hashcode; } }
@Override public SecurityProfile getDeletionSecurityProfile() { return getSecurityProfile(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getName()); sb.append(" : "); sb.append(getAlias()); sb.append(" : "); sb.append(getDescription()); sb.append(" : "); sb.append(getStudyType()); sb.append(" : "); if (getProject() != null) { sb.append(getProject().getAlias()); sb.append("(" + getProject().getName() + ")"); } return sb.toString(); }
@Override public String getDeleteDescription() { Project p = getProject(); return (p.getShortName() == null ? p.getAlias() : p.getShortName()) + " " + getName() + " (" + getAlias() + ")"; }
@Override public boolean isSaved() { return getId() != UNSAVED_ID; }
/** * Construct a new Study with a default empty SecurityProfile */ public StudyImpl() { setSecurityProfile(new SecurityProfile()); }
public static Study to(@Nonnull StudyDto dto) { Study to = new StudyImpl(); to.setId(dto.getId()); return to; }
/** * Construct a new Study with a SecurityProfile owned by the given User * * @param user * of type User */ public StudyImpl(User user) { setSecurityProfile(new SecurityProfile(user)); }
/** * Equivalency is based on getProjectId() if set, otherwise on name, description and creation date. */ @Override public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; if (!(obj instanceof Study)) return false; Study them = (Study) obj; // If not saved, then compare resolved actual objects. Otherwise // just compare IDs. if (getId() == StudyImpl.UNSAVED_ID || them.getId() == StudyImpl.UNSAVED_ID) { if (getName() != null && them.getName() != null) { return getName().equals(them.getName()); } else { return getAlias().equals(them.getAlias()); } } else { return this.getId() == them.getId(); } }