Commits

Roy Curtis authored and md_5 committed 9856d8a1839
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
No tags

src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java

Modified
168 168 }
169 169
170 170 public boolean hasTitle() {
171 171 return !Strings.isNullOrEmpty(title);
172 172 }
173 173
174 174 public boolean hasPages() {
175 175 return !pages.isEmpty();
176 176 }
177 177
178 + public boolean hasGeneration() {
179 + return generation != null;
180 + }
181 +
178 182 public String getTitle() {
179 183 return this.title;
180 184 }
181 185
182 186 public boolean setTitle(final String title) {
183 187 if (title == null) {
184 188 this.title = null;
185 189 return true;
186 190 } else if (title.length() > MAX_TITLE_LENGTH) {
187 191 return false;
285 289 int hash = original = super.applyHash();
286 290 if (hasTitle()) {
287 291 hash = 61 * hash + this.title.hashCode();
288 292 }
289 293 if (hasAuthor()) {
290 294 hash = 61 * hash + 13 * this.author.hashCode();
291 295 }
292 296 if (hasPages()) {
293 297 hash = 61 * hash + 17 * this.pages.hashCode();
294 298 }
299 + if (hasGeneration()) {
300 + hash = 61 * hash + 19 * this.generation.hashCode();
301 + }
295 302 return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash;
296 303 }
297 304
298 305 @Override
299 306 boolean equalsCommon(CraftMetaItem meta) {
300 307 if (!super.equalsCommon(meta)) {
301 308 return false;
302 309 }
303 310 if (meta instanceof CraftMetaBook) {
304 311 CraftMetaBook that = (CraftMetaBook) meta;
305 312
306 313 return (hasTitle() ? that.hasTitle() && this.title.equals(that.title) : !that.hasTitle())
307 314 && (hasAuthor() ? that.hasAuthor() && this.author.equals(that.author) : !that.hasAuthor())
308 - && (hasPages() ? that.hasPages() && this.pages.equals(that.pages) : !that.hasPages());
315 + && (hasPages() ? that.hasPages() && this.pages.equals(that.pages) : !that.hasPages())
316 + && (hasGeneration() ? that.hasGeneration() && this.generation.equals(that.generation) : !that.hasGeneration());
309 317 }
310 318 return true;
311 319 }
312 320
313 321 @Override
314 322 boolean notUncommon(CraftMetaItem meta) {
315 323 return super.notUncommon(meta) && (meta instanceof CraftMetaBook || isBookEmpty());
316 324 }
317 325
318 326 @Override

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut