Sho SHIMIZU | 2908d9e | 2015-05-08 16:40:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | 2908d9e | 2015-05-08 16:40:06 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onlab.util; |
| 17 | |
| 18 | import 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 | */ |
| 25 | public 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 | } |