package uk.ivanc.archimvvm.model; import android.os.Parcel; import android.os.Parcelable; import com.google.gson.annotations.SerializedName; public class Repository implements Parcelable { public long id; public String name; public String description; public int forks; public int watchers; @SerializedName("stargazers_count") public int stars; public String language; public String homepage; public User owner; public boolean fork; public Repository() { } public boolean hasHomepage() { return homepage != null && !homepage.isEmpty(); } public boolean hasLanguage() { return language != null && !language.isEmpty(); } public boolean isFork() { return fork; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeLong(this.id); dest.writeString(this.name); dest.writeString(this.description); dest.writeInt(this.forks); dest.writeInt(this.watchers); dest.writeInt(this.stars); dest.writeString(this.language); dest.writeString(this.homepage); dest.writeParcelable(this.owner, 0); dest.writeByte(fork ? (byte) 1 : (byte) 0); } protected Repository(Parcel in) { this.id = in.readLong(); this.name = in.readString(); this.description = in.readString(); this.forks = in.readInt(); this.watchers = in.readInt(); this.stars = in.readInt(); this.language = in.readString(); this.homepage = in.readString(); this.owner = in.readParcelable(User.class.getClassLoader()); this.fork = in.readByte() != 0; } public static final Creator<Repository> CREATOR = new Creator<Repository>() { public Repository createFromParcel(Parcel source) { return new Repository(source); } public Repository[] newArray(int size) { return new Repository[size]; } }; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Repository that = (Repository) o; if (id != that.id) return false; if (forks != that.forks) return false; if (watchers != that.watchers) return false; if (stars != that.stars) return false; if (fork != that.fork) return false; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (description != null ? !description.equals(that.description) : that.description != null) return false; if (language != null ? !language.equals(that.language) : that.language != null) return false; if (homepage != null ? !homepage.equals(that.homepage) : that.homepage != null) return false; return !(owner != null ? !owner.equals(that.owner) : that.owner != null); } @Override public int hashCode() { int result = (int) (id ^ (id >>> 32)); result = 31 * result + (name != null ? name.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + forks; result = 31 * result + watchers; result = 31 * result + stars; result = 31 * result + (language != null ? language.hashCode() : 0); result = 31 * result + (homepage != null ? homepage.hashCode() : 0); result = 31 * result + (owner != null ? owner.hashCode() : 0); result = 31 * result + (fork ? 1 : 0); return result; } }