001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.batch.scm; 021 022import org.apache.commons.lang.StringUtils; 023import org.apache.commons.lang.builder.EqualsBuilder; 024import org.apache.commons.lang.builder.HashCodeBuilder; 025import org.apache.commons.lang.builder.ToStringBuilder; 026import org.apache.commons.lang.builder.ToStringStyle; 027 028import javax.annotation.CheckForNull; 029import javax.annotation.Nullable; 030 031import java.util.Date; 032 033/** 034 * @since 5.0 035 */ 036public class BlameLine { 037 038 private Date date; 039 private String revision; 040 private String author; 041 042 public BlameLine() { 043 // for backward compatibility 044 } 045 046 /** 047 * Preferred constructor. Date and revision must be set. 048 * @since 5.2 049 */ 050 public BlameLine(Date date, String revision) { 051 this.date = date; 052 this.revision = revision; 053 } 054 055 public String revision() { 056 return revision; 057 } 058 059 /** 060 * Mandatory field 061 */ 062 public BlameLine revision(String revision) { 063 this.revision = revision; 064 return this; 065 } 066 067 @CheckForNull 068 public String author() { 069 return author; 070 } 071 072 /** 073 * Sets author for this line. 074 * The string will be trimmed, and null will be set if it is empty. 075 */ 076 public BlameLine author(@Nullable String author) { 077 this.author = StringUtils.trimToNull(author); 078 return this; 079 } 080 081 /** 082 * @return the commit date 083 */ 084 public Date date() { 085 return date; 086 } 087 088 /** 089 * Mandatory field 090 */ 091 public BlameLine date(@Nullable Date date) { 092 this.date = date; 093 return this; 094 } 095 096 // For testing purpose 097 098 @Override 099 public boolean equals(Object obj) { 100 if (obj == null) { 101 return false; 102 } 103 if (obj == this) { 104 return true; 105 } 106 if (obj.getClass() != getClass()) { 107 return false; 108 } 109 BlameLine rhs = (BlameLine) obj; 110 return new EqualsBuilder() 111 .append(date, rhs.date) 112 .append(revision, rhs.revision) 113 .append(author, rhs.author) 114 .isEquals(); 115 } 116 117 @Override 118 public int hashCode() { 119 return new HashCodeBuilder(27, 45). 120 append(date) 121 .append(revision) 122 .append(author) 123 .toHashCode(); 124 } 125 126 @Override 127 public String toString() { 128 return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); 129 } 130}