Improvements to BookMeta API

* Added hasGeneration()
* Fixed `applyHash()` (used by `CraftMetaItem.hashCode()`) not taking generation into account
* Fixed `equalsCommon()` (used by `CraftMetaItem.equals()`) not taking generation into account
This commit is contained in:
Roy Curtis 2016-06-14 22:40:46 +01:00 committed by md_5
parent 02f4218da5
commit 9856d8a183

View File

@ -175,6 +175,10 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
return !pages.isEmpty(); return !pages.isEmpty();
} }
public boolean hasGeneration() {
return generation != null;
}
public String getTitle() { public String getTitle() {
return this.title; return this.title;
} }
@ -292,6 +296,9 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
if (hasPages()) { if (hasPages()) {
hash = 61 * hash + 17 * this.pages.hashCode(); hash = 61 * hash + 17 * this.pages.hashCode();
} }
if (hasGeneration()) {
hash = 61 * hash + 19 * this.generation.hashCode();
}
return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash; return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash;
} }
@ -305,7 +312,8 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
return (hasTitle() ? that.hasTitle() && this.title.equals(that.title) : !that.hasTitle()) return (hasTitle() ? that.hasTitle() && this.title.equals(that.title) : !that.hasTitle())
&& (hasAuthor() ? that.hasAuthor() && this.author.equals(that.author) : !that.hasAuthor()) && (hasAuthor() ? that.hasAuthor() && this.author.equals(that.author) : !that.hasAuthor())
&& (hasPages() ? that.hasPages() && this.pages.equals(that.pages) : !that.hasPages()); && (hasPages() ? that.hasPages() && this.pages.equals(that.pages) : !that.hasPages())
&& (hasGeneration() ? that.hasGeneration() && this.generation.equals(that.generation) : !that.hasGeneration());
} }
return true; return true;
} }