blob: e83afe8eb6e5deb718b459db5fc41f8230db7135 [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.net.driver;
17
18import com.google.common.collect.ImmutableSet;
19import org.onosproject.net.MutableAnnotations;
20
21import java.util.HashMap;
22import java.util.Map;
23import java.util.Set;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26
27/**
28 * Default implementation of driver data descriptor.
29 */
30public class DefaultDriverData implements DriverData {
31
32 private final Driver type;
33 private final Map<String, String> properties;
34
35 /**
36 * Creates new driver data.
37 *
38 * @param type parent driver type
39 */
40 public DefaultDriverData(Driver type) {
41 this.type = type;
42 this.properties = new HashMap<>();
43 }
44
45 @Override
46 public Driver type() {
47 return type;
48 }
49
50 @Override
51 public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
52 return type.createBehaviour(this, behaviourClass, false);
53 }
54
55 @Override
56 public MutableAnnotations set(String key, String value) {
57 properties.put(key, value);
58 return this;
59 }
60
61 @Override
62 public MutableAnnotations clear(String... keys) {
63 if (keys.length == 0) {
64 properties.clear();
65 } else {
66 for (String key : keys) {
67 properties.remove(key);
68 }
69 }
70 return this;
71 }
72
73 @Override
74 public Set<String> keys() {
75 return ImmutableSet.copyOf(properties.keySet());
76 }
77
78 @Override
79 public String value(String key) {
80 return properties.get(key);
81 }
82
83 @Override
84 public String toString() {
85 return toStringHelper(this)
86 .add("type", type)
87 .add("properties", properties)
88 .toString();
89 }
90
91}