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;
16 public class DeviationBuilder implements Builder {
17 private final DeviationImpl instance;
18 private final int line;
20 DeviationBuilder(final String targetPathStr, final int line) {
22 final SchemaPath targetPath = YangModelBuilderUtil
23 .parseAugmentPath(targetPathStr);
24 instance = new DeviationImpl(targetPath);
28 public Deviation build() {
33 public int getLine() {
37 public void setDeviate(final String deviate) {
38 if ("not-supported".equals(deviate)) {
39 instance.setDeviate(Deviate.NOT_SUPPORTED);
40 } else if ("add".equals(deviate)) {
41 instance.setDeviate(Deviate.ADD);
42 } else if ("replace".equals(deviate)) {
43 instance.setDeviate(Deviate.REPLACE);
44 } else if ("delete".equals(deviate)) {
45 instance.setDeviate(Deviate.DELETE);
47 throw new IllegalArgumentException(
48 "Unsupported type of 'deviate' statement: " + deviate);
52 public void setReference(final String reference) {
53 instance.setReference(reference);
56 private static class DeviationImpl implements Deviation {
57 private final SchemaPath targetPath;
58 private Deviate deviate;
59 private String reference;
61 private DeviationImpl(final SchemaPath targetPath) {
62 this.targetPath = targetPath;
66 public SchemaPath getTargetPath() {
71 public Deviate getDeviate() {
75 private void setDeviate(final Deviate deviate) {
76 this.deviate = deviate;
80 public String getReference() {
84 private void setReference(final String reference) {
85 this.reference = reference;
89 public int hashCode() {
92 result = prime * result
93 + ((targetPath == null) ? 0 : targetPath.hashCode());
94 result = prime * result
95 + ((deviate == null) ? 0 : deviate.hashCode());
96 result = prime * result
97 + ((reference == null) ? 0 : reference.hashCode());
102 public boolean equals(Object obj) {
109 if (getClass() != obj.getClass()) {
112 DeviationImpl other = (DeviationImpl) obj;
113 if (targetPath == null) {
114 if (other.targetPath != null) {
117 } else if (!targetPath.equals(other.targetPath)) {
120 if (deviate == null) {
121 if (other.deviate != null) {
124 } else if (!deviate.equals(other.deviate)) {
127 if (reference == null) {
128 if (other.reference != null) {
131 } else if (!reference.equals(other.reference)) {
138 public String toString() {
139 StringBuilder sb = new StringBuilder(
140 DeviationImpl.class.getSimpleName());
142 sb.append("targetPath=" + targetPath);
143 sb.append(", deviate=" + deviate);
144 sb.append(", reference=" + reference);
146 return sb.toString();