Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [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.net.driver; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 20 | import org.onosproject.net.MutableAnnotations; |
| 21 | |
| 22 | import java.util.HashMap; |
| 23 | import java.util.Map; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | |
| 28 | /** |
| 29 | * Default implementation of driver data descriptor. |
| 30 | */ |
| 31 | public class DefaultDriverData implements DriverData { |
| 32 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 33 | private final Driver driver; |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 34 | private final DeviceId deviceId; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 35 | private final Map<String, String> properties; |
| 36 | |
| 37 | /** |
| 38 | * Creates new driver data. |
| 39 | * |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 40 | * @param driver parent driver type |
| 41 | * @param deviceId device identifier |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 42 | */ |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 43 | public DefaultDriverData(Driver driver, DeviceId deviceId) { |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 44 | this.driver = driver; |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 45 | this.deviceId = deviceId; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 46 | this.properties = new HashMap<>(); |
| 47 | } |
| 48 | |
| 49 | @Override |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 50 | public Driver driver() { |
| 51 | return driver; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 55 | public DeviceId deviceId() { |
| 56 | return deviceId; |
| 57 | } |
| 58 | |
| 59 | @Override |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 60 | 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 Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 90 | .add("type", driver) |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 91 | .add("properties", properties) |
| 92 | .toString(); |
| 93 | } |
| 94 | |
| 95 | } |