Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / PCEPObject.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;
9
10 import com.google.common.base.Objects;
11 import com.google.common.base.Objects.ToStringHelper;
12
13 /**
14  * Basic structure for PCEP Objects.
15  *
16  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.2">Common Object
17  *      Header</a>
18  */
19 public abstract class PCEPObject {
20
21         private final boolean processed;
22
23         private final boolean ignored;
24
25         /**
26          * Constructor is protected to prevent direct instantiation, but to allow to
27          * call this constructor via super().
28          *
29          * @param processed
30          *            P flag
31          * @param ignored
32          *            I flag
33          */
34         protected PCEPObject(boolean processed, boolean ignored) {
35                 this.processed = processed;
36                 this.ignored = ignored;
37         }
38
39         /**
40          * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.2"> Common
41          *      Object Header</a>
42          *
43          * @return true if P flag is set and false if is not.
44          */
45         public boolean isProcessed() {
46                 return this.processed;
47         }
48
49         /**
50          * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.2"> Common
51          *      Object Header</a>
52          *
53          * @return true if I flag is set and false if is not.
54          */
55         public boolean isIgnored() {
56                 return this.ignored;
57         }
58
59         @Override
60         public int hashCode() {
61                 final int prime = 31;
62                 int result = 1;
63                 result = prime * result + (this.ignored ? 1231 : 1237);
64                 result = prime * result + (this.processed ? 1231 : 1237);
65                 return result;
66         }
67
68         @Override
69         public boolean equals(Object obj) {
70                 if (this == obj)
71                         return true;
72                 if (obj == null)
73                         return false;
74                 if (this.getClass() != obj.getClass())
75                         return false;
76                 final PCEPObject other = (PCEPObject) obj;
77                 if (this.ignored != other.ignored)
78                         return false;
79                 if (this.processed != other.processed)
80                         return false;
81                 return true;
82         }
83
84         @Override
85         public String toString(){
86                 return addToStringAttributes(Objects.toStringHelper(this)).toString();
87         }
88
89         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
90                 toStringHelper.add("processed", this.processed);
91                 toStringHelper.add("ignored", this.ignored);
92                 return toStringHelper;
93         }
94
95 }