From dea7989a0fda5c4e475788d250651bc8f72009f0 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 18 Sep 2015 00:07:55 -0400 Subject: [PATCH] Move method to CollectionUtils to reduce number of source files --- .../common/util/CollectionUtils.java | 5 ++++ .../common/util/primitives/Integers.java | 30 ------------------- .../ClusterDiscoveryConfiguration.java | 4 +-- 3 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java diff --git a/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java b/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java index ec37fb21de1..e4a074b3961 100644 --- a/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java +++ b/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java @@ -277,6 +277,11 @@ public enum CollectionUtils { }.sort(0, array.size()); } + public static int[] toArray(Collection ints) { + Objects.requireNonNull(ints); + return ints.stream().mapToInt(s -> s).toArray(); + } + private static class RotatedList extends AbstractList implements RandomAccess { private final List in; diff --git a/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java b/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java deleted file mode 100644 index 1c49b3f3fa3..00000000000 --- a/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.common.util.primitives; - -import java.util.Collection; -import java.util.Objects; - -public class Integers { - public static int[] toArray(Collection ints) { - Objects.requireNonNull(ints); - return ints.stream().mapToInt(s -> s).toArray(); - } -} diff --git a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java index ad46047855b..e549c185616 100644 --- a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java +++ b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java @@ -23,7 +23,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.network.NetworkUtils; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.primitives.Integers; +import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.NodeConfigurationSource; @@ -82,7 +82,7 @@ public class ClusterDiscoveryConfiguration extends NodeConfigurationSource { while (ordinals.size() != numOfUnicastHosts) { ordinals.add(RandomizedTest.randomInt(numOfNodes - 1)); } - unicastHostOrdinals = Integers.toArray(ordinals); + unicastHostOrdinals = CollectionUtils.toArray(ordinals); } this.unicastHostPorts = unicastHostPorts(numOfNodes); assert unicastHostOrdinals.length <= unicastHostPorts.length;