From d39c3f439a4744d8fbdab69f050112d4a778d5e9 Mon Sep 17 00:00:00 2001 From: Zafar Khaja Date: Wed, 20 Nov 2013 20:21:03 +0400 Subject: [PATCH] Get rid of 'unchecked' warnings --- .../github/zafarkhaja/semver/util/Stream.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/zafarkhaja/semver/util/Stream.java b/src/main/java/com/github/zafarkhaja/semver/util/Stream.java index 62c509f..22142a9 100644 --- a/src/main/java/com/github/zafarkhaja/semver/util/Stream.java +++ b/src/main/java/com/github/zafarkhaja/semver/util/Stream.java @@ -98,11 +98,14 @@ public class Stream implements Iterable { * Consumes the next element in this stream * only if it is of the expected types. * + * @param represents the element type of this stream, removes the + * "unchecked generic array creation for varargs parameter" + * warnings * @param expected the types which are expected * @return the next element in this stream * @throws UnexpectedElementTypeException if the next element is of an unexpected type */ - public E consume(ElementType... expected) { + public > E consume(T... expected) { E lookahead = lookahead(1); for (ElementType type : expected) { if (type.isMatchedBy(lookahead)) { @@ -140,11 +143,14 @@ public class Stream implements Iterable { /** * Checks if the next element in this stream is of the expected types. * + * @param represents the element type of this stream, removes the + * "unchecked generic array creation for varargs parameter" + * warnings * @param expected the expected types * @return {@code true} if the next element is of the expected types * or {@code false} otherwise */ - public boolean positiveLookahead(ElementType... expected) { + public > boolean positiveLookahead(T... expected) { for (ElementType type : expected) { if (type.isMatchedBy(lookahead(1))) { return true; @@ -157,14 +163,17 @@ public class Stream implements Iterable { * Checks if there exists an element in this stream of * the expected types before the specified type. * + * @param represents the element type of this stream, removes the + * "unchecked generic array creation for varargs parameter" + * warnings * @param before the type before which to search * @param expected the expected types * @return {@code true} if there is an element of the expected types * before the specified type or {@code false} otherwise */ - public boolean positiveLookaheadBefore( + public > boolean positiveLookaheadBefore( ElementType before, - ElementType... expected + T... expected ) { E lookahead; for (int i = 1; i <= elements.length; i++) { @@ -185,14 +194,17 @@ public class Stream implements Iterable { * Checks if there is an element in this stream of * the expected types until the specified position. * + * @param represents the element type of this stream, removes the + * "unchecked generic array creation for varargs parameter" + * warnings * @param until the position until which to search * @param expected the expected types * @return {@code true} if there is an element of the expected types * until the specified position or {@code false} otherwise */ - public boolean positiveLookaheadUntil( + public > boolean positiveLookaheadUntil( int until, - ElementType... expected + T... expected ) { for (int i = 1; i <= until; i++) { for (ElementType type : expected) {