blob: 2edd396ffa49c956d5a32d8685ff3901519f7cf7 [file] [log] [blame]
Simon Hunt4854f3d2016-08-02 18:13:15 -07001/*
2 * Copyright 2016-present 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
17package org.onosproject.ui.impl.topo.cli;
18
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.ui.model.topo.UiElement;
21
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.Comparator;
25import java.util.List;
26import java.util.Set;
27
28/**
29 * Base class for model cache CLI commands.
30 */
Simon Hunt34327012017-05-26 16:16:16 -070031abstract class AbstractUiCacheElementCommand extends AbstractShellCommand {
Simon Hunt4854f3d2016-08-02 18:13:15 -070032
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}