diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/support/Integers.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/support/Integers.java deleted file mode 100644 index e1834fc6201..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/support/Integers.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.watcher.support; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.Objects; - -public class Integers { - private Integers() { - } - - public static Iterable asIterable(int[] values) { - Objects.requireNonNull(values); - return () -> new Iterator() { - private int position = 0; - @Override - public boolean hasNext() { - return position < values.length; - } - - @Override - public Integer next() { - if (position < values.length) { - return values[position++]; - } else { - throw new NoSuchElementException("position: " + position + ", length: " + values.length); - } - } - }; - } - - public static boolean contains(int[] values, final int value) { - return Arrays.stream(values).anyMatch(v -> v == value); - } -} diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java index 8f85c89d410..96329687042 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java @@ -13,14 +13,14 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.xpack.watcher.support.Strings; import java.util.Arrays; +import java.util.List; import java.util.stream.Collectors; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.xpack.watcher.support.Integers.asIterable; -import static org.elasticsearch.xpack.watcher.support.Integers.contains; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -147,7 +147,7 @@ public class HourlyScheduleTests extends ScheduleTestCase { int[] minutes = validMinutes(); XContentBuilder builder = jsonBuilder() .startObject() - .field("minute", asIterable(minutes)) + .field("minute", minutes) .endObject(); BytesReference bytes = builder.bytes(); XContentParser parser = createParser(JsonXContent.jsonXContent, bytes); @@ -155,8 +155,9 @@ public class HourlyScheduleTests extends ScheduleTestCase { HourlySchedule schedule = new HourlySchedule.Parser().parse(parser); assertThat(schedule, notNullValue()); assertThat(schedule.minutes().length, is(minutes.length)); + List ints = Arrays.stream(schedule.minutes()).mapToObj(Integer::valueOf).collect(Collectors.toList()); for (int i = 0; i < minutes.length; i++) { - assertThat(contains(schedule.minutes(), minutes[i]), is(true)); + assertThat(ints, hasItem(minutes[i])); } } @@ -164,7 +165,7 @@ public class HourlyScheduleTests extends ScheduleTestCase { int[] minutes = invalidMinutes(); XContentBuilder builder = jsonBuilder() .startObject() - .field("minute", asIterable(minutes)) + .field("minute", minutes) .endObject(); BytesReference bytes = builder.bytes(); XContentParser parser = createParser(JsonXContent.jsonXContent, bytes); @@ -181,7 +182,7 @@ public class HourlyScheduleTests extends ScheduleTestCase { int[] minutes = validMinutes(); XContentBuilder builder = jsonBuilder() .startObject() - .field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList())) + .field("minute", Arrays.stream(minutes).mapToObj(Integer::toString).collect(Collectors.toList())) .endObject(); BytesReference bytes = builder.bytes(); XContentParser parser = createParser(JsonXContent.jsonXContent, bytes); @@ -189,8 +190,10 @@ public class HourlyScheduleTests extends ScheduleTestCase { HourlySchedule schedule = new HourlySchedule.Parser().parse(parser); assertThat(schedule, notNullValue()); assertThat(schedule.minutes().length, is(minutes.length)); + + List ints = Arrays.stream(schedule.minutes()).mapToObj(Integer::valueOf).collect(Collectors.toList()); for (int i = 0; i < minutes.length; i++) { - assertThat(contains(schedule.minutes(), minutes[i]), is(true)); + assertThat(ints, hasItem(minutes[i])); } } @@ -198,7 +201,7 @@ public class HourlyScheduleTests extends ScheduleTestCase { int[] minutes = invalidMinutes(); XContentBuilder builder = jsonBuilder() .startObject() - .field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList())) + .field("minute", Arrays.stream(minutes).mapToObj(Integer::toString).collect(Collectors.toList())) .endObject(); BytesReference bytes = builder.bytes(); XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);