blob: 87fee9cb703dc51b03f0d88a2f6ed3e25075c6b2 [file] [log] [blame]
Sho SHIMIZU2908d9e2015-05-08 16:40:06 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZU2908d9e2015-05-08 16:40:06 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.util;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20/**
21 * Extends useful methods for comparison to {@link Comparable} interface.
22 *
23 * @param <T> type of instance to be compared
24 */
25public interface RichComparable<T> extends Comparable<T> {
26 /**
27 * Compares if this object is less than the specified object.
28 *
29 * @param other the object to be compared
30 * @return true if this object is less than the specified object
31 */
32 default boolean isLessThan(T other) {
33 return compareTo(checkNotNull(other)) < 0;
34 }
35
36 /**
37 * Compares if this object is greater than the specified object.
38 *
39 * @param other the object to be compared
40 * @return true if this object is less thant the specified object
41 */
42 default boolean isGreaterThan(T other) {
43 return compareTo(checkNotNull(other)) > 0;
44 }
45}