Gaurav Agrawal | 4efc8cc | 2017-02-09 18:41:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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 | */ |
| 16 | |
| 17 | package org.onosproject.yang.runtime; |
| 18 | |
Gaurav Agrawal | 2779d36 | 2017-02-17 16:10:22 +0530 | [diff] [blame] | 19 | import org.onosproject.yang.model.ResourceData; |
| 20 | |
Gaurav Agrawal | 4efc8cc | 2017-02-09 18:41:31 +0530 | [diff] [blame] | 21 | import java.util.LinkedList; |
| 22 | import java.util.List; |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | import static java.util.Objects.hash; |
| 27 | |
| 28 | /** |
| 29 | * Representation of default implementation of composite data. |
| 30 | */ |
| 31 | public class DefaultCompositeData implements CompositeData { |
| 32 | |
| 33 | private ResourceData data; |
| 34 | private List<AnnotatedNodeInfo> annotationsInfo; |
| 35 | |
| 36 | /** |
| 37 | * Creates an instance of composite data. |
| 38 | * |
| 39 | * @param b composite data builder |
| 40 | */ |
| 41 | protected DefaultCompositeData(Builder b) { |
| 42 | data = b.data; |
| 43 | annotationsInfo = b.annotationsInfo; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public ResourceData resourceData() { |
| 48 | return data; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public List<AnnotatedNodeInfo> annotatedNodesInfo() { |
| 53 | return annotationsInfo; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
| 58 | return hash(data, annotationsInfo); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object obj) { |
| 63 | if (this == obj) { |
| 64 | return true; |
| 65 | } |
| 66 | if (obj instanceof DefaultCompositeData) { |
| 67 | DefaultCompositeData that = (DefaultCompositeData) obj; |
| 68 | return Objects.equals(data, that.data) && |
| 69 | Objects.equals(annotationsInfo, that.annotationsInfo); |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return toStringHelper(getClass()) |
| 77 | .add("data", data) |
| 78 | .add("annotationsInfo", annotationsInfo) |
| 79 | .toString(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Retrieves a new composite data builder. |
| 84 | * |
| 85 | * @return composite data builder |
| 86 | */ |
| 87 | public static Builder builder() { |
| 88 | return new Builder(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Represents implementation of composite data builder. |
| 93 | */ |
| 94 | public static class Builder implements CompositeData.Builder { |
| 95 | |
| 96 | private ResourceData data; |
| 97 | private List<AnnotatedNodeInfo> annotationsInfo; |
| 98 | |
| 99 | /** |
| 100 | * Creates an instance of composite data builder. |
| 101 | */ |
| 102 | protected Builder() { |
| 103 | annotationsInfo = new LinkedList<>(); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Builder resourceData(ResourceData rd) { |
| 108 | data = rd; |
| 109 | return this; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public Builder addAnnotatedNodeInfo(AnnotatedNodeInfo info) { |
| 114 | annotationsInfo.add(info); |
| 115 | return this; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public CompositeData build() { |
| 120 | return new DefaultCompositeData(this); |
| 121 | } |
| 122 | } |
| 123 | } |