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
This commit is contained in:
Lee Hinman 2018-04-06 08:58:24 -06:00 committed by GitHub
parent cb3295b212
commit 160d25fcdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View File

@ -46,7 +46,7 @@ public class Tuple<V1, V2> {
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;

View File

@ -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<Long, String> t1 = new Tuple<>(2L, "foo");
Tuple<Long, String> t2 = new Tuple<>(2L, "foo");
Tuple<Long, String> t3 = new Tuple<>(3L, "foo");
Tuple<Long, String> t4 = new Tuple<>(2L, "bar");
Tuple<Integer, String> 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]"));
}
}