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.model.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.model.parser.builder.api.Builder;
14 import org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil;
16 public class DeviationBuilder implements Builder {
18 private final DeviationImpl instance;
20 DeviationBuilder(final String targetPathStr) {
21 final SchemaPath targetPath = YangModelBuilderUtil
22 .parseAugmentPath(targetPathStr);
23 instance = new DeviationImpl(targetPath);
27 public Deviation build() {
31 public void setDeviate(final String deviate) {
32 if ("not-supported".equals(deviate)) {
33 instance.setDeviate(Deviate.NOT_SUPPORTED);
34 } else if ("add".equals(deviate)) {
35 instance.setDeviate(Deviate.ADD);
36 } else if ("replace".equals(deviate)) {
37 instance.setDeviate(Deviate.REPLACE);
38 } else if ("delete".equals(deviate)) {
39 instance.setDeviate(Deviate.DELETE);
41 throw new IllegalArgumentException(
42 "Unsupported type of 'deviate' statement: " + deviate);
46 public void setReference(final String reference) {
47 instance.setReference(reference);
50 private static class DeviationImpl implements Deviation {
51 private final SchemaPath targetPath;
52 private Deviate deviate;
53 private String reference;
55 private DeviationImpl(final SchemaPath targetPath) {
56 this.targetPath = targetPath;
60 public SchemaPath getTargetPath() {
65 public Deviate getDeviate() {
69 private void setDeviate(final Deviate deviate) {
70 this.deviate = deviate;
74 public String getReference() {
78 private void setReference(final String reference) {
79 this.reference = reference;
83 public int hashCode() {
86 result = prime * result
87 + ((targetPath == null) ? 0 : targetPath.hashCode());
88 result = prime * result
89 + ((deviate == null) ? 0 : deviate.hashCode());
90 result = prime * result
91 + ((reference == null) ? 0 : reference.hashCode());
96 public boolean equals(Object obj) {
103 if (getClass() != obj.getClass()) {
106 DeviationImpl other = (DeviationImpl) obj;
107 if (targetPath == null) {
108 if (other.targetPath != null) {
111 } else if (!targetPath.equals(other.targetPath)) {
114 if (deviate == null) {
115 if (other.deviate != null) {
118 } else if (!deviate.equals(other.deviate)) {
121 if (reference == null) {
122 if (other.reference != null) {
125 } else if (!reference.equals(other.reference)) {
132 public String toString() {
133 StringBuilder sb = new StringBuilder(DeviationImpl.class.getSimpleName());
135 sb.append("targetPath="+ targetPath);
136 sb.append(", deviate="+ deviate);
137 sb.append(", reference="+ reference);
139 return sb.toString();