blob: 036282153bdb159f3c8ebaf4c5f6c3666b7f46c3 [file] [log] [blame]
Gaurav Agrawal4efc8cc2017-02-09 18:41:31 +05301/*
Brian O'Connor72b2df22017-08-03 18:48:28 -07002 * Copyright 2017-present Open Networking Foundation
Gaurav Agrawal4efc8cc2017-02-09 18:41:31 +05303 *
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
Vidyashree Rama120446e2017-04-25 16:55:25 +053017package org.onosproject.yang.model;
Gaurav Agrawal4efc8cc2017-02-09 18:41:31 +053018
19import java.util.LinkedList;
20import java.util.List;
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24import static java.util.Objects.hash;
25
26/**
27 * Representation of default implementation of resource data.
28 */
29public class DefaultResourceData implements ResourceData {
30
31 private List<DataNode> nodes;
32 private ResourceId resourceId;
33
34 /**
35 * Creates an instance of resource data.
36 *
37 * @param b resource data builder
38 */
39 protected DefaultResourceData(Builder b) {
40 resourceId = b.resourceId;
41 nodes = b.nodes;
42 }
43
44 @Override
45 public List<DataNode> dataNodes() {
46 return nodes;
47 }
48
49 @Override
50 public ResourceId resourceId() {
51 return resourceId;
52 }
53
54 @Override
55 public int hashCode() {
56 return hash(resourceId, nodes);
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (obj instanceof DefaultResourceData) {
65 DefaultResourceData that = (DefaultResourceData) obj;
66 return Objects.equals(resourceId, that.resourceId) &&
67 Objects.equals(nodes, that.nodes);
68 }
69 return false;
70 }
71
72 @Override
73 public String toString() {
74 return toStringHelper(getClass())
75 .add("resourceId", resourceId)
76 .add("nodes", nodes)
77 .toString();
78 }
79
80 /**
81 * Retrieves a new resource data builder.
82 *
83 * @return resource data builder
84 */
85 public static Builder builder() {
86 return new Builder();
87 }
88
89 /**
90 * Represents implementation of resource data builder.
91 */
92 public static class Builder implements ResourceData.Builder {
93
94 private List<DataNode> nodes;
95 private ResourceId resourceId;
96
97 /**
98 * Creates an instance of resource data builder.
99 */
100 protected Builder() {
101 nodes = new LinkedList<>();
102 }
103
104 @Override
105 public ResourceData.Builder addDataNode(DataNode node) {
106 nodes.add(node);
107 return this;
108 }
109
110 @Override
111 public ResourceData.Builder resourceId(ResourceId id) {
112 resourceId = id;
113 return this;
114 }
115
116 @Override
117 public ResourceData build() {
118 return new DefaultResourceData(this);
119 }
120 }
121}