blob: 5b0d1c055b27d4d166ade602be4b6e1ae715a3e7 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.flink.streaming.tests;
import org.apache.flink.api.java.tuple.Tuple2;
/** Variation of the {@link Tuple2} which implements {@link Comparable}. */
public class ComparableTuple2<T0 extends Comparable<? super T0>, T1 extends Comparable<? super T1>>
extends Tuple2<T0, T1> implements Comparable<ComparableTuple2<T0, T1>> {
private static final long serialVersionUID = 1L;
public ComparableTuple2(T0 f0, T1 f1) {
super(f0, f1);
}
@Override
public int compareTo(ComparableTuple2<T0, T1> other) {
int d = this.f0.compareTo(other.f0);
if (d == 0) {
return this.f1.compareTo(other.f1);
}
return d;
}
/** Creates a new key-value pair. */
public static <K extends Comparable<? super K>, T1 extends Comparable<? super T1>>
ComparableTuple2<K, T1> of(K key, T1 value) {
return new ComparableTuple2<>(key, value);
}
}