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(String targetPathStr) {
21 SchemaPath targetPath = YangModelBuilderUtil
22 .parseAugmentPath(targetPathStr);
23 instance = new DeviationImpl(targetPath);
27 public Deviation build() {
31 public void setDeviate(String deviate) {
32 if (deviate.equals("not-supported")) {
33 instance.setDeviate(Deviate.NOT_SUPPORTED);
34 } else if (deviate.equals("add")) {
35 instance.setDeviate(Deviate.ADD);
36 } else if (deviate.equals("replace")) {
37 instance.setDeviate(Deviate.REPLACE);
38 } else if (deviate.equals("delete")) {
39 instance.setDeviate(Deviate.DELETE);
41 throw new IllegalArgumentException(
42 "Unsupported type of 'deviate' statement: " + deviate);
46 public void setReference(String reference) {
47 instance.setReference(reference);
50 private static class DeviationImpl implements Deviation {
52 private SchemaPath targetPath;
53 private Deviate deviate;
54 private String reference;
56 private DeviationImpl(SchemaPath targetPath) {
57 this.targetPath = targetPath;
61 public SchemaPath getTargetPath() {
66 public Deviate getDeviate() {
70 private void setDeviate(Deviate deviate) {
71 this.deviate = deviate;
75 public String getReference() {
79 private void setReference(String reference) {
80 this.reference = reference;
84 public int hashCode() {
87 result = prime * result
88 + ((targetPath == null) ? 0 : targetPath.hashCode());
89 result = prime * result
90 + ((deviate == null) ? 0 : deviate.hashCode());
91 result = prime * result
92 + ((reference == null) ? 0 : reference.hashCode());
97 public boolean equals(Object obj) {
104 if (getClass() != obj.getClass()) {
107 DeviationImpl other = (DeviationImpl) obj;
108 if (targetPath == null) {
109 if (other.targetPath != null) {
112 } else if (!targetPath.equals(other.targetPath)) {
115 if (deviate == null) {
116 if (other.deviate != null) {
119 } else if (!deviate.equals(other.deviate)) {
122 if (reference == null) {
123 if (other.reference != null) {
126 } else if (!reference.equals(other.reference)) {
133 public String toString() {
134 StringBuilder sb = new StringBuilder(DeviationImpl.class.getSimpleName());
136 sb.append("targetPath="+ targetPath);
137 sb.append(", deviate="+ deviate);
138 sb.append(", reference="+ reference);
140 return sb.toString();