Skip to content

Instantly share code, notes, and snippets.

@madhu314
Last active January 15, 2017 16:19
Show Gist options
  • Save madhu314/b0de78daba763ca19ffcc09527c261f5 to your computer and use it in GitHub Desktop.
Save madhu314/b0de78daba763ca19ffcc09527c261f5 to your computer and use it in GitHub Desktop.
@AutoValue public static abstract class SectionArticle {
@Nullable public abstract Article article();
@Nullable public abstract String category();
public static SectionArticle createCategory(Article article) {
return new AutoValue_SectionArticlesActivity_SectionArticle(null, article.category());
}
public static SectionArticle createArticle(Article article) {
return new AutoValue_SectionArticlesActivity_SectionArticle(article, null);
}
public boolean isCategory() {
return article() == null;
}
public boolean isArticle() {
return category() == null;
}
public int compare(SectionArticle that) {
if (this.isCategory() && that.isCategory()) {
return this.category().compareToIgnoreCase(that.category());
} else if (this.isCategory() && that.isArticle()) {
if (this.category().equalsIgnoreCase(that.article().category())) {
return -1;
} else {
return this.category().compareToIgnoreCase(that.article().category());
}
} else if (this.isArticle() && that.isCategory()) {
if (this.article().category().equalsIgnoreCase(that.category())) {
return 1;
} else {
return this.article().category().compareToIgnoreCase(that.category());
}
} else {
if (this.article().category().equalsIgnoreCase(that.article().category())) {
return this.article().compare(that.article());
} else {
return this.article().category().compareToIgnoreCase(that.article().category());
}
}
}
public boolean areContentsTheSame(SectionArticle that) {
return this.equals(that);
}
public boolean areItemsTheSame(SectionArticle that) {
if (this.isCategory() && that.isCategory()) {
return this.category().equalsIgnoreCase(that.category());
} else if (this.isArticle() && that.isArticle()) {
return this.article().id() == that.article().id();
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment