Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2017-present Open Networking Foundation |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -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 | package org.onosproject.vpls.store; |
| 17 | |
| 18 | import com.google.common.collect.Maps; |
| 19 | import org.onosproject.store.StoreDelegate; |
| 20 | import org.onosproject.vpls.api.VplsData; |
| 21 | import org.onosproject.vpls.api.VplsStore; |
| 22 | |
| 23 | import java.util.Collection; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | /** |
| 27 | * Test adapter for VPLS store. |
| 28 | */ |
| 29 | public class VplsStoreAdapter implements VplsStore { |
| 30 | protected Map<String, VplsData> vplsDataMap; |
| 31 | protected StoreDelegate<VplsStoreEvent> delegate; |
| 32 | |
| 33 | public VplsStoreAdapter() { |
| 34 | vplsDataMap = Maps.newHashMap(); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void setDelegate(StoreDelegate<VplsStoreEvent> delegate) { |
| 39 | this.delegate = delegate; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void unsetDelegate(StoreDelegate<VplsStoreEvent> delegate) { |
| 44 | this.delegate = null; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean hasDelegate() { |
| 49 | return this.delegate != null; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void addVpls(VplsData vplsData) { |
| 54 | vplsDataMap.put(vplsData.name(), vplsData); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void removeVpls(VplsData vplsData) { |
| 59 | vplsDataMap.remove(vplsData.name()); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void updateVpls(VplsData vplsData) { |
| 64 | vplsDataMap.put(vplsData.name(), vplsData); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public VplsData getVpls(String vplsName) { |
| 69 | return vplsDataMap.get(vplsName); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public Collection<VplsData> getAllVpls() { |
| 74 | return vplsDataMap.values(); |
| 75 | } |
| 76 | } |