001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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.builder.EqualsBuilder;
023import org.apache.commons.lang.builder.HashCodeBuilder;
024import org.apache.commons.lang.builder.ToStringBuilder;
025import org.apache.commons.lang.builder.ToStringStyle;
026
027import javax.annotation.CheckForNull;
028import javax.annotation.Nullable;
029
030import java.util.Date;
031
032/**
033 * @since 5.0
034 */
035public class BlameLine {
036
037  private Date date;
038  private String revision;
039  private String author;
040
041  public String revision() {
042    return revision;
043  }
044
045  public BlameLine revision(String revision) {
046    this.revision = revision;
047    return this;
048  }
049
050  @CheckForNull
051  public String author() {
052    return author;
053  }
054
055  public BlameLine author(@Nullable String author) {
056    this.author = author;
057    return this;
058  }
059
060  /**
061   * @return the commit date
062   */
063  @CheckForNull
064  public Date date() {
065    return date;
066  }
067
068  public BlameLine date(@Nullable Date date) {
069    this.date = date;
070    return this;
071  }
072
073  // For testing purpose
074
075  @Override
076  public boolean equals(Object obj) {
077    if (obj == null) {
078      return false;
079    }
080    if (obj == this) {
081      return true;
082    }
083    if (obj.getClass() != getClass()) {
084      return false;
085    }
086    BlameLine rhs = (BlameLine) obj;
087    return new EqualsBuilder()
088      .append(date, rhs.date)
089      .append(revision, rhs.revision)
090      .append(author, rhs.author)
091      .isEquals();
092  }
093
094  @Override
095  public int hashCode() {
096    return new HashCodeBuilder(27, 45).
097      append(date)
098      .append(revision)
099      .append(author)
100      .toHashCode();
101  }
102
103  @Override
104  public String toString() {
105    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
106  }
107}