blob: b59463c93dcb72d4de8d51b083b32df3cb0b2d87 [file] [log] [blame]
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -08003 *
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.onosproject.net;
17
18import java.util.Comparator;
HIGUCHI Yutaca8cb4e2015-12-11 13:57:05 -080019import java.util.TreeSet;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080020
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23
24/**
25 * Comparator implementation for OchSignal. Assumes identical grid type and channel spacing.
26 */
27public class DefaultOchSignalComparator implements Comparator<OchSignal> {
HIGUCHI Yutaca8cb4e2015-12-11 13:57:05 -080028
29 private static final DefaultOchSignalComparator INSTANCE = new DefaultOchSignalComparator();
30
31 /**
32 * Creates a new instance of {@link TreeSet} using this Comparator.
33 * @return {@link TreeSet}
34 */
35 public static TreeSet<OchSignal> newOchSignalTreeSet() {
36 return new TreeSet<>(INSTANCE);
37 }
38
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080039 @Override
40 public int compare(OchSignal o1, OchSignal o2) {
41 checkNotNull(o1.gridType());
42 checkNotNull(o1.channelSpacing());
43
44 checkArgument(o1.gridType().equals(o2.gridType()));
45 checkArgument(o1.channelSpacing().equals(o2.channelSpacing()));
46
47 return o1.spacingMultiplier() * o1.slotGranularity() - o2.spacingMultiplier() * o2.slotGranularity();
48 }
49}