Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPObjectiveFunctionObject.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 java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.protocol.pcep.PCEPOFCodes;
14 import org.opendaylight.protocol.pcep.PCEPObject;
15 import org.opendaylight.protocol.pcep.PCEPTlv;
16 import com.google.common.base.Objects.ToStringHelper;
17
18 /**
19  * Indicates the desired/required objective function to be applied by the PCE
20  * during path computation or within a PCRep message so as to indicate the
21  * objective function that was used by the PCE during path computation.
22  *
23  * @see <a href="http://tools.ietf.org/html/rfc5541#section-3.1">OF Object</a>
24  */
25 public class PCEPObjectiveFunctionObject extends PCEPObject {
26
27     private final PCEPOFCodes code;
28
29     private final List<PCEPTlv> tlvs;
30
31     /**
32      * Constructs objective function object only with mandatory objects.
33      *
34      * @param code
35      *            PCEPOFCodes
36      * @param processed
37      *            boolean
38      * @param ignored
39      *            boolean
40      */
41     public PCEPObjectiveFunctionObject(PCEPOFCodes code, boolean processed, boolean ignored) {
42         this(code, null, processed, ignored);
43     }
44
45     /**
46      * Constructs objective function object also with optional objects.
47      *
48      * @param code
49      *            PCEPOFCodes
50      * @param tlvs
51      *            the list of tlvs
52      * @param processed
53      *            boolean
54      * @param ignored
55      *            boolean
56      */
57     public PCEPObjectiveFunctionObject(PCEPOFCodes code, List<PCEPTlv> tlvs, boolean processed, boolean ignored) {
58         super(processed, ignored);
59         this.code = code;
60
61         if (tlvs == null)
62             this.tlvs = Collections.emptyList();
63         else
64             this.tlvs = tlvs;
65     }
66
67     /**
68      * Gets the objective function code
69      *
70      * @return the PCEPOFCodes
71      */
72     public PCEPOFCodes getCode() {
73         return this.code;
74     }
75
76     /**
77      * Gets the list of tlvs
78      *
79      * @return the list of tlvs
80      */
81     public List<PCEPTlv> getTlvs() {
82         return this.tlvs;
83     }
84
85     @Override
86         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
87                 toStringHelper.add("code", this.code);
88                 toStringHelper.add("tlvs", this.tlvs);
89                 return super.addToStringAttributes(toStringHelper);
90         }
91
92     @Override
93     public int hashCode() {
94         final int prime = 31;
95         int result = super.hashCode();
96         result = prime * result + ((this.code == null) ? 0 : this.code.hashCode());
97         result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
98         return result;
99     }
100
101     @Override
102     public boolean equals(Object obj) {
103         if (this == obj)
104             return true;
105         if (!super.equals(obj))
106             return false;
107         if (this.getClass() != obj.getClass())
108             return false;
109         final PCEPObjectiveFunctionObject other = (PCEPObjectiveFunctionObject) obj;
110         if (this.code != other.code)
111             return false;
112         if (this.tlvs == null) {
113             if (other.tlvs != null)
114                 return false;
115         } else if (!this.tlvs.equals(other.tlvs))
116             return false;
117         return true;
118     }
119
120 }