@@ -70,7 +70,7 @@ public static Version version() {
7070
7171 @ SuppressWarnings ("OptionalUsedAsFieldOrParameterType" )
7272 public static class Version implements Comparable <Version > {
73- private final List <Integer > version ;
73+ private final List <Integer > version ; // I wish these could be OptionalInt, but the getters require otherwise
7474 private final Optional <String > pre ;
7575 private final Optional <Integer > build ;
7676 private final Optional <String > optional ;
@@ -279,7 +279,10 @@ private int compareOptional(Version obj) {
279279 public String toString () {
280280 final StringBuilder sb = new StringBuilder (version .stream ().map (Object ::toString ).collect (Collectors .joining ("." )));
281281
282- pre .ifPresent (v -> sb .append ("-" ).append (v ));
282+ //noinspection OptionalIsPresent
283+ if (pre .isPresent ()) {
284+ sb .append ("-" ).append (pre .get ());
285+ }
283286
284287 if (build .isPresent ()) {
285288 sb .append ("+" ).append (build .get ());
@@ -298,36 +301,27 @@ public String toString() {
298301 @ Override
299302 @ SuppressWarnings ("EqualsWhichDoesntCheckParameterClass" )
300303 public boolean equals (Object obj ) {
301- final boolean ret = equalsIgnoreOptional (obj );
302- if (!ret ) {
303- return false ;
304- }
305-
306- final Version that = (Version )obj ;
307- return this .optional ().equals (that .optional ());
304+ return equalsIgnoreOptional (obj ) && optional ().equals (((Version )obj ).optional ());
308305 }
309306
310307 public boolean equalsIgnoreOptional (Object obj ) {
311308 if (this == obj ) {
312309 return true ;
313310 }
314- if ((obj instanceof Version )) {
315- final Version that = (Version )obj ;
316- return this .version ().equals (that .version ) && this .pre ().equals (that .pre ()) && this .build ().equals (that .build ());
311+ if (!(obj instanceof Version )) {
312+ return false ;
317313 }
318- return false ;
314+ final Version o = (Version )obj ;
315+ return version ().equals (o .version ) && pre ().equals (o .pre ()) && build ().equals (o .build ());
319316 }
320317
321318 @ Override
322319 public int hashCode () {
323320 int h = 1 ;
324- final int p = 17 ;
325-
326- h = p * h + version .hashCode ();
327- h = p * h + pre .hashCode ();
328- h = p * h + build .hashCode ();
329- h = p * h + optional .hashCode ();
330-
321+ h = 17 * h + version .hashCode ();
322+ h = 17 * h + pre .hashCode ();
323+ h = 17 * h + build .hashCode ();
324+ h = 17 * h + optional .hashCode ();
331325 return h ;
332326 }
333327 }
0 commit comments