Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPMetricObject.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.object;
9
10 import org.opendaylight.protocol.concepts.AbstractMetric;
11 import org.opendaylight.protocol.pcep.PCEPObject;
12 import com.google.common.base.Objects.ToStringHelper;
13
14 /**
15  * Structure of PCEP Metric Object.
16  *
17  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.8">PCEP Metric
18  *      Object</a>
19  */
20 public class PCEPMetricObject extends PCEPObject {
21
22     private final boolean bound;
23
24     private final boolean computedMetric;
25
26     private final AbstractMetric<?> metric;
27
28     /**
29      * Constructs PCEP Metric Object.
30      *
31      * @param bound
32      *            boolean
33      * @param computedMetric
34      *            boolean
35      * @param metric
36      *            cannot be null
37      * @param processed
38      *            boolean
39      * @param ignored
40      *            boolean
41      */
42     public PCEPMetricObject(boolean bound, boolean computedMetric, AbstractMetric<?> metric, boolean processed, boolean ignored) {
43         super(processed, ignored);
44         this.bound = bound;
45         this.computedMetric = computedMetric;
46         if (metric == null)
47             throw new IllegalArgumentException("Mandatory parameter metric cannot be null.");
48         this.metric = metric;
49     }
50
51     /**
52      * Gets Bound flag.
53      *
54      * @return boolean
55      */
56     public boolean isBound() {
57         return this.bound;
58     }
59
60     /**
61      * Gets Computed Metric flag.
62      *
63      * @return boolean
64      */
65     public boolean isComputedMetric() {
66         return this.computedMetric;
67     }
68
69     /**
70      * Gets {@link AbstractMetric<?>}.
71      *
72      * @return AbstractMetric<?>
73      */
74     public AbstractMetric<?> getMetric() {
75         return this.metric;
76     }
77
78     @Override
79     public int hashCode() {
80         final int prime = 31;
81         int result = super.hashCode();
82         result = prime * result + (this.bound ? 1231 : 1237);
83         result = prime * result + (this.computedMetric ? 1231 : 1237);
84         result = prime * result + ((this.metric == null) ? 0 : this.metric.hashCode());
85         return result;
86     }
87
88     @Override
89     public boolean equals(Object obj) {
90         if (this == obj)
91             return true;
92         if (!super.equals(obj))
93             return false;
94         if (this.getClass() != obj.getClass())
95             return false;
96         final PCEPMetricObject other = (PCEPMetricObject) obj;
97         if (this.bound != other.bound)
98             return false;
99         if (this.computedMetric != other.computedMetric)
100             return false;
101         if (this.metric == null) {
102             if (other.metric != null)
103                 return false;
104         } else if (!this.metric.equals(other.metric))
105             return false;
106         return true;
107     }
108
109         @Override
110         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
111                 toStringHelper.add("bound", this.bound);
112                 toStringHelper.add("computedMetric", this.computedMetric);
113                 toStringHelper.add("metric", this.metric);
114                 return super.addToStringAttributes(toStringHelper);
115         }
116 }