Jian Li | c87b23b | 2017-04-24 15:28:10 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | c87b23b | 2017-04-24 15:28:10 +0900 | [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 | package org.onosproject.mapping.cli; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
Jian Li | 6e960ef | 2017-05-03 16:38:19 +0900 | [diff] [blame] | 19 | import org.apache.commons.lang3.StringUtils; |
Jian Li | c87b23b | 2017-04-24 15:28:10 +0900 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractChoicesCompleter; |
| 21 | import org.onosproject.mapping.MappingStore.Type; |
| 22 | |
| 23 | import java.util.List; |
| 24 | import java.util.stream.Collectors; |
| 25 | |
| 26 | /** |
| 27 | * Mapping store type completer. |
| 28 | */ |
| 29 | public class MappingStoreTypeCompleter extends AbstractChoicesCompleter { |
| 30 | |
| 31 | private static final List<Type> STORE_TYPES = |
| 32 | ImmutableList.of(Type.MAP_CACHE, Type.MAP_DATABASE); |
Jian Li | 6e960ef | 2017-05-03 16:38:19 +0900 | [diff] [blame] | 33 | private static final String MAP_PREFIX = "map_"; |
Jian Li | c87b23b | 2017-04-24 15:28:10 +0900 | [diff] [blame] | 34 | |
| 35 | @Override |
| 36 | protected List<String> choices() { |
| 37 | return STORE_TYPES.stream().map(type -> |
Jian Li | 6e960ef | 2017-05-03 16:38:19 +0900 | [diff] [blame] | 38 | removeMapPrefix(type.toString().toLowerCase())) |
| 39 | .collect(Collectors.toList()); |
| 40 | } |
| 41 | |
| 42 | private String removeMapPrefix(String type) { |
| 43 | return StringUtils.replaceAll(type, MAP_PREFIX, ""); |
Jian Li | c87b23b | 2017-04-24 15:28:10 +0900 | [diff] [blame] | 44 | } |
| 45 | } |