blob: d688961bab6c4eafcd98242b7e1717334a2eb44f [file] [log] [blame]
Yi Tsengf4e13e32017-03-30 15:38:39 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengf4e13e32017-03-30 15:38:39 -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.vpls.store;
17
18import com.google.common.collect.Maps;
19import org.onosproject.store.StoreDelegate;
20import org.onosproject.vpls.api.VplsData;
21import org.onosproject.vpls.api.VplsStore;
22
23import java.util.Collection;
24import java.util.Map;
25
26/**
27 * Test adapter for VPLS store.
28 */
29public 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}