blob: 903e544c46806d8fa7ace531ee0aad29c1ff7907 [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08003 *
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;
Thomas Vachuska80b0a802015-07-17 08:43:30 -070019import org.onosproject.net.DeviceId;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080020import org.onosproject.net.MutableAnnotations;
21
22import java.util.HashMap;
23import java.util.Map;
24import java.util.Set;
25
26import static com.google.common.base.MoreObjects.toStringHelper;
27
28/**
29 * Default implementation of driver data descriptor.
30 */
31public class DefaultDriverData implements DriverData {
32
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070033 private final Driver driver;
Thomas Vachuska80b0a802015-07-17 08:43:30 -070034 private final DeviceId deviceId;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080035 private final Map<String, String> properties;
36
37 /**
38 * Creates new driver data.
39 *
Thomas Vachuskad894b5d2015-07-30 11:59:07 -070040 * @param driver parent driver type
41 * @param deviceId device identifier
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080042 */
Thomas Vachuska80b0a802015-07-17 08:43:30 -070043 public DefaultDriverData(Driver driver, DeviceId deviceId) {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070044 this.driver = driver;
Thomas Vachuska80b0a802015-07-17 08:43:30 -070045 this.deviceId = deviceId;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080046 this.properties = new HashMap<>();
47 }
48
49 @Override
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070050 public Driver driver() {
51 return driver;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080052 }
53
54 @Override
Thomas Vachuska80b0a802015-07-17 08:43:30 -070055 public DeviceId deviceId() {
56 return deviceId;
57 }
58
59 @Override
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080060 public MutableAnnotations set(String key, String value) {
61 properties.put(key, value);
62 return this;
63 }
64
65 @Override
66 public MutableAnnotations clear(String... keys) {
67 if (keys.length == 0) {
68 properties.clear();
69 } else {
70 for (String key : keys) {
71 properties.remove(key);
72 }
73 }
74 return this;
75 }
76
77 @Override
78 public Set<String> keys() {
79 return ImmutableSet.copyOf(properties.keySet());
80 }
81
82 @Override
83 public String value(String key) {
84 return properties.get(key);
85 }
86
87 @Override
88 public String toString() {
89 return toStringHelper(this)
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070090 .add("type", driver)
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080091 .add("properties", properties)
92 .toString();
93 }
94
95}