From 160d25fcdbe4d68ba080ba272dec61c082361bcb Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Fri, 6 Apr 2018 08:58:24 -0600 Subject: [PATCH] Move Tuple into elasticsearch-core (#29375) * Move Tuple into elasticsearch-core This allows us to use Tuple from other projects that don't want to rely on the entire Elasticsearch jar. I have also added very simple tests, since there were none. Relates tangentially to #28504 --- .../elasticsearch/common/collect/Tuple.java | 2 +- .../common/collect/TupleTests.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) rename {server => libs/elasticsearch-core}/src/main/java/org/elasticsearch/common/collect/Tuple.java (97%) create mode 100644 libs/elasticsearch-core/src/test/java/org/elasticsearch/common/collect/TupleTests.java diff --git a/server/src/main/java/org/elasticsearch/common/collect/Tuple.java b/libs/elasticsearch-core/src/main/java/org/elasticsearch/common/collect/Tuple.java similarity index 97% rename from server/src/main/java/org/elasticsearch/common/collect/Tuple.java rename to libs/elasticsearch-core/src/main/java/org/elasticsearch/common/collect/Tuple.java index 2a0d860e1a3f4..70c7bcbc045b6 100644 --- a/server/src/main/java/org/elasticsearch/common/collect/Tuple.java +++ b/libs/elasticsearch-core/src/main/java/org/elasticsearch/common/collect/Tuple.java @@ -46,7 +46,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Tuple tuple = (Tuple) o; + Tuple tuple = (Tuple) o; if (v1 != null ? !v1.equals(tuple.v1) : tuple.v1 != null) return false; if (v2 != null ? !v2.equals(tuple.v2) : tuple.v2 != null) return false; diff --git a/libs/elasticsearch-core/src/test/java/org/elasticsearch/common/collect/TupleTests.java b/libs/elasticsearch-core/src/test/java/org/elasticsearch/common/collect/TupleTests.java new file mode 100644 index 0000000000000..79a9969ad0510 --- /dev/null +++ b/libs/elasticsearch-core/src/test/java/org/elasticsearch/common/collect/TupleTests.java @@ -0,0 +1,47 @@ +/* + * 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.collect; + +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.Matchers.equalTo; + +public class TupleTests extends ESTestCase { + + public void testTuple() { + Tuple t1 = new Tuple<>(2L, "foo"); + Tuple t2 = new Tuple<>(2L, "foo"); + Tuple t3 = new Tuple<>(3L, "foo"); + Tuple t4 = new Tuple<>(2L, "bar"); + Tuple t5 = new Tuple<>(2, "foo"); + + assertThat(t1.v1(), equalTo(Long.valueOf(2L))); + assertThat(t1.v2(), equalTo("foo")); + + assertThat(t1, equalTo(t2)); + assertNotEquals(t1, t3); + assertNotEquals(t2, t3); + assertNotEquals(t2, t4); + assertNotEquals(t3, t4); + assertNotEquals(t1, t5); + + assertThat(t1.toString(), equalTo("Tuple [v1=2, v2=foo]")); + } +}