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.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 BlameLine() {
042    // for backward compatibility
043  }
044  
045  /**
046   * Preferred constructor. Date and revision must be set.
047   * @since 5.2
048   */
049  public BlameLine(Date date, String revision) {
050    this.date = date;
051    this.revision = revision;
052  }
053
054  public String revision() {
055    return revision;
056  }
057
058  /**
059   * Mandatory field
060   */
061  public BlameLine revision(String revision) {
062    this.revision = revision;
063    return this;
064  }
065
066  @CheckForNull
067  public String author() {
068    return author;
069  }
070
071  public BlameLine author(@Nullable String author) {
072    this.author = author;
073    return this;
074  }
075
076  /**
077   * @return the commit date
078   */
079  public Date date() {
080    return date;
081  }
082
083  /**
084   * Mandatory field
085   */
086  public BlameLine date(@Nullable Date date) {
087    this.date = date;
088    return this;
089  }
090
091  // For testing purpose
092
093  @Override
094  public boolean equals(Object obj) {
095    if (obj == null) {
096      return false;
097    }
098    if (obj == this) {
099      return true;
100    }
101    if (obj.getClass() != getClass()) {
102      return false;
103    }
104    BlameLine rhs = (BlameLine) obj;
105    return new EqualsBuilder()
106      .append(date, rhs.date)
107      .append(revision, rhs.revision)
108      .append(author, rhs.author)
109      .isEquals();
110  }
111
112  @Override
113  public int hashCode() {
114    return new HashCodeBuilder(27, 45).
115      append(date)
116      .append(revision)
117      .append(author)
118      .toHashCode();
119  }
120
121  @Override
122  public String toString() {
123    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
124  }
125}