BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / RROLabelSubobject.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
9 package org.opendaylight.protocol.pcep.subobject;
10
11 import com.google.common.base.Objects;
12 import com.google.common.base.Objects.ToStringHelper;
13
14 /**
15  * Structure of Label subobject.
16  *
17  * @see <a href="http://tools.ietf.org/html/rfc3473#section-5.1">Label ERO
18  *      subobject</a>
19  */
20 public abstract class RROLabelSubobject extends ReportedRouteSubobject {
21
22     private final boolean upStream;
23
24     /**
25      * Constructs new Label subobject.
26      *
27      * @param upStream
28      *            if set label is upstream
29      * @param label
30      *            Label
31      * @param loose
32      *            boolean
33      */
34     public RROLabelSubobject(boolean upStream) {
35         this.upStream = upStream;
36     }
37
38     public boolean isUpStream() {
39         return this.upStream;
40     }
41
42     @Override
43     public int hashCode() {
44         final int prime = 31;
45         int result = super.hashCode();
46         result = prime * result + (this.upStream ? 1231 : 1237);
47         return result;
48     }
49
50     @Override
51     public boolean equals(Object obj) {
52         if (this == obj)
53             return true;
54         if (!super.equals(obj))
55             return false;
56         if (this.getClass() != obj.getClass())
57             return false;
58         final RROLabelSubobject other = (RROLabelSubobject) obj;
59         if (this.upStream != other.upStream)
60             return false;
61         return true;
62     }
63
64     @Override
65         public String toString(){
66                 return this.addToStringAttributes(Objects.toStringHelper(this)).toString();
67         }
68
69         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
70                 toStringHelper.add("upStream", this.upStream);
71                 return toStringHelper;
72         }
73 }