Skip to content
181 changes: 152 additions & 29 deletions src/java/main/br/ufpe/cin/groundhog/Commit.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package br.ufpe.cin.groundhog;

import java.util.Date;
import java.util.List;

import br.ufpe.cin.groundhog.util.Dates;

Expand Down Expand Up @@ -32,9 +33,11 @@ public class Commit extends GitHubEntity {

private Date commitDate;

private int additionsCount;

private int deletionsCount;
private CommitStats stats;

private List<CommitFile> files;

private List<CommitParent> parents;

public Commit(String sha, Project project) {
this.sha = sha;
Expand Down Expand Up @@ -103,46 +106,55 @@ public void setCommitDate(String date) {
}

/**
* Informs the sum of added lines among the files committed
* @param deletionsCount
* Gives the abbreviated SHA of the {@link Commit} object
* @return a {@link String} object
*/
public int getAdditionsCount() {
return this.additionsCount;
public String getabbrevSHA() {
return this.sha.substring(0, 7);
}

public void setAdditionsCount(int additionsCount) {
this.additionsCount = additionsCount;
public List<CommitFile> getFiles() {
return this.files;
}

/**
* Informs the sum of deleted lines among the files committed
* @param deletionsCount
*/
public int getDeletionsCount() {
return this.deletionsCount;
public CommitStats getStats() {
return this.stats;
}

public void setDeletionsCount(int deletionsCount) {
this.deletionsCount = deletionsCount;
public List<CommitParent> getParents() {
return this.parents;
}
/**
* Gives the abbreviated SHA of the {@link Commit} object
* @return a {@link String} object
*/
public String getabbrevSHA() {
return this.sha.substring(0, 7);

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((sha == null) ? 0 : sha.hashCode());
return result;
}

/**
* Two {@link Commit} objects are considered equal if and only if both have the same SHA hash
* @param commit
* @return
*/
public boolean equals(Commit commit) {
return this.sha == commit.sha;
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Commit other = (Commit) obj;
if (sha == null) {
if (other.sha != null)
return false;
} else if (!sha.equals(other.sha))
return false;
return true;
}

@Override
public String toString() {
return "Commit [" + (sha != null ? "sha=" + sha + ", " : "")
Expand All @@ -159,4 +171,115 @@ public String getURL() {
this.getProject().getName(),
this.sha);
}
}

/**
* The commit changes stats, i.e., number of additions, deletions and total
* @author Irineu
*
*/
public static final class CommitStats {
private int additions;

private int deletions;

private int total;

public int getAdditions() {
return additions;
}

public int getDeletions() {
return deletions;
}

public int getTotal() {
return total;
}

@Override
public String toString() {
return "CommitStats [additions=" + additions + ", deletions="
+ deletions + ", total=" + total + "]";
}

}

public static final class CommitFile {
@SerializedName(value="filename")
private String fileName;

@SerializedName(value="additions")
private int additionsCount;

@SerializedName(value="deletions")
private int deletionsCount;

@SerializedName(value="changes")
private int changesCount;

@SerializedName(value="status")
private String status;

@SerializedName(value="blob_url")
private String blobUrl;

@SerializedName(value="patch")
private String patch;

public String getFileName() {
return fileName;
}

public int getAdditionsCount() {
return additionsCount;
}

public int getDeletionsCount() {
return deletionsCount;
}

public int getChangesCount() {
return changesCount;
}

public String getStatus() {
return status;
}

public String getBlobUrl() {
return blobUrl;
}

public String getPatch() {
return patch;
}

@Override
public String toString() {
return "CommitFile [fileName=" + fileName + ", additionsCount="
+ additionsCount + ", deletionsCount=" + deletionsCount
+ ", changesCount=" + changesCount + ", status=" + status
+ ", patch=" + patch + "]";
}
}

public static class CommitParent {

private String url;

private String sha;

public String getUrl() {
return url;
}

public String getSha() {
return sha;
}

@Override
public String toString() {
return "CommitParent [url=" + url + ", sha=" + sha + "]";
}
}
}
Loading