2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.yang.parser.builder.impl;
10 import org.opendaylight.controller.yang.model.api.Deviation;
11 import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
12 import org.opendaylight.controller.yang.model.api.SchemaPath;
13 import org.opendaylight.controller.yang.parser.builder.api.Builder;
14 import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
15 import org.opendaylight.controller.yang.parser.util.YangParseException;
17 public final class DeviationBuilder implements Builder {
18 private final DeviationImpl instance;
19 private final int line;
21 DeviationBuilder(final String targetPathStr, final int line) {
23 final SchemaPath targetPath = YangModelBuilderUtil
24 .parseAugmentPath(targetPathStr);
25 instance = new DeviationImpl(targetPath);
29 public Deviation build() {
34 public int getLine() {
38 public void setDeviate(final String deviate) {
39 if ("not-supported".equals(deviate)) {
40 instance.setDeviate(Deviate.NOT_SUPPORTED);
41 } else if ("add".equals(deviate)) {
42 instance.setDeviate(Deviate.ADD);
43 } else if ("replace".equals(deviate)) {
44 instance.setDeviate(Deviate.REPLACE);
45 } else if ("delete".equals(deviate)) {
46 instance.setDeviate(Deviate.DELETE);
48 throw new YangParseException(line,
49 "Unsupported type of 'deviate' statement: " + deviate);
53 public void setReference(final String reference) {
54 instance.setReference(reference);
57 private final class DeviationImpl implements Deviation {
58 private final SchemaPath targetPath;
59 private Deviate deviate;
60 private String reference;
62 private DeviationImpl(final SchemaPath targetPath) {
63 this.targetPath = targetPath;
67 public SchemaPath getTargetPath() {
72 public Deviate getDeviate() {
76 private void setDeviate(final Deviate deviate) {
77 this.deviate = deviate;
81 public String getReference() {
85 private void setReference(final String reference) {
86 this.reference = reference;
90 public int hashCode() {
93 result = prime * result
94 + ((targetPath == null) ? 0 : targetPath.hashCode());
95 result = prime * result
96 + ((deviate == null) ? 0 : deviate.hashCode());
97 result = prime * result
98 + ((reference == null) ? 0 : reference.hashCode());
103 public boolean equals(Object obj) {
110 if (getClass() != obj.getClass()) {
113 DeviationImpl other = (DeviationImpl) obj;
114 if (targetPath == null) {
115 if (other.targetPath != null) {
118 } else if (!targetPath.equals(other.targetPath)) {
121 if (deviate == null) {
122 if (other.deviate != null) {
125 } else if (!deviate.equals(other.deviate)) {
128 if (reference == null) {
129 if (other.reference != null) {
132 } else if (!reference.equals(other.reference)) {
139 public String toString() {
140 StringBuilder sb = new StringBuilder(
141 DeviationImpl.class.getSimpleName());
143 sb.append("targetPath=" + targetPath);
144 sb.append(", deviate=" + deviate);
145 sb.append(", reference=" + reference);
147 return sb.toString();