Simon Hunt | 4854f3d | 2016-08-02 18:13:15 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Simon Hunt | 4854f3d | 2016-08-02 18:13:15 -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 | |
| 17 | package org.onosproject.ui.impl.topo.cli; |
| 18 | |
| 19 | import org.onosproject.cli.AbstractShellCommand; |
| 20 | import org.onosproject.ui.model.topo.UiElement; |
| 21 | |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.Collections; |
| 24 | import java.util.Comparator; |
| 25 | import java.util.List; |
| 26 | import java.util.Set; |
| 27 | |
| 28 | /** |
| 29 | * Base class for model cache CLI commands. |
| 30 | */ |
Simon Hunt | 3432701 | 2017-05-26 16:16:16 -0700 | [diff] [blame] | 31 | abstract class AbstractUiCacheElementCommand extends AbstractShellCommand { |
Simon Hunt | 4854f3d | 2016-08-02 18:13:15 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Built in comparator for elements. |
| 35 | */ |
| 36 | private static final Comparator<UiElement> ELEMENT_COMPARATOR = |
| 37 | (o1, o2) -> o1.idAsString().compareTo(o2.idAsString()); |
| 38 | |
| 39 | /** |
| 40 | * Returns the given elements in a list, sorted by string representation |
| 41 | * of the identifiers. |
| 42 | * |
| 43 | * @param elements the elements to sort |
| 44 | * @return the sorted elements |
| 45 | */ |
| 46 | protected List<UiElement> sorted(Set<? extends UiElement> elements) { |
| 47 | List<UiElement> list = new ArrayList<>(elements); |
| 48 | Collections.sort(list, ELEMENT_COMPARATOR); |
| 49 | return list; |
| 50 | } |
| 51 | } |