Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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.onosproject.net; |
| 17 | |
| 18 | import java.util.Comparator; |
| 19 | |
| 20 | import static com.google.common.base.Preconditions.checkArgument; |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * Comparator implementation for OchSignal. Assumes identical grid type and channel spacing. |
| 25 | */ |
| 26 | public class DefaultOchSignalComparator implements Comparator<OchSignal> { |
| 27 | @Override |
| 28 | public int compare(OchSignal o1, OchSignal o2) { |
| 29 | checkNotNull(o1.gridType()); |
| 30 | checkNotNull(o1.channelSpacing()); |
| 31 | |
| 32 | checkArgument(o1.gridType().equals(o2.gridType())); |
| 33 | checkArgument(o1.channelSpacing().equals(o2.channelSpacing())); |
| 34 | |
| 35 | return o1.spacingMultiplier() * o1.slotGranularity() - o2.spacingMultiplier() * o2.slotGranularity(); |
| 36 | } |
| 37 | } |