blob: eaa53fffc9efe14a86df442941d003f6784c2305 [file] [log] [blame]
Jian Lic87b23b2017-04-24 15:28:10 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Lic87b23b2017-04-24 15:28:10 +09003 *
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.mapping.cli;
17
18import com.google.common.collect.ImmutableList;
Jian Li6e960ef2017-05-03 16:38:19 +090019import org.apache.commons.lang3.StringUtils;
Ray Milkey01ad6a42018-10-09 14:08:21 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Jian Lic87b23b2017-04-24 15:28:10 +090021import org.onosproject.cli.AbstractChoicesCompleter;
22import org.onosproject.mapping.MappingStore.Type;
23
24import java.util.List;
25import java.util.stream.Collectors;
26
27/**
28 * Mapping store type completer.
29 */
Ray Milkey01ad6a42018-10-09 14:08:21 -070030@Service
Jian Lic87b23b2017-04-24 15:28:10 +090031public class MappingStoreTypeCompleter extends AbstractChoicesCompleter {
32
33 private static final List<Type> STORE_TYPES =
34 ImmutableList.of(Type.MAP_CACHE, Type.MAP_DATABASE);
Jian Li6e960ef2017-05-03 16:38:19 +090035 private static final String MAP_PREFIX = "map_";
Jian Lic87b23b2017-04-24 15:28:10 +090036
37 @Override
38 protected List<String> choices() {
39 return STORE_TYPES.stream().map(type ->
Jian Li6e960ef2017-05-03 16:38:19 +090040 removeMapPrefix(type.toString().toLowerCase()))
41 .collect(Collectors.toList());
42 }
43
44 private String removeMapPrefix(String type) {
45 return StringUtils.replaceAll(type, MAP_PREFIX, "");
Jian Lic87b23b2017-04-24 15:28:10 +090046 }
47}