blob: 3036f6843f10323d7682d1db50c659e268b07010 [file] [log] [blame]
Ray Milkey95c50872015-04-14 14:32:31 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey95c50872015-04-14 14:32:31 -07003 *
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.cli.app;
17
18import java.util.Iterator;
19import java.util.List;
20import java.util.Spliterator;
21import java.util.Spliterators;
22import java.util.stream.StreamSupport;
23
24import org.onosproject.app.ApplicationService;
25import org.onosproject.cli.AbstractChoicesCompleter;
26import org.onosproject.core.Application;
27
28import static java.util.stream.Collectors.toList;
29import static org.onosproject.app.ApplicationState.INSTALLED;
30import static org.onosproject.cli.AbstractShellCommand.get;
31
32/**
33 * All installed application name completer.
34 */
35public class AllApplicationNamesCompleter extends AbstractChoicesCompleter {
36 @Override
37 public List<String> choices() {
38
39 // Fetch the service and return the list of app names
40 ApplicationService service = get(ApplicationService.class);
41 Iterator<Application> it = service.getApplications().iterator();
42
43 // Filter the list of apps, selecting only the installed ones.
44 // Add each app name to the list of choices.
45 return
46 StreamSupport.stream(
47 Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED), false)
48 .filter(app -> service.getState(app.id()) == INSTALLED)
49 .map(app -> app.id().name())
50 .collect(toList());
51
52 }
53
54}