Initial code drop
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / AbstractLinkstateMP.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.bgp.parser.impl;
9
10 import org.opendaylight.protocol.bgp.linkstate.SourceProtocol;
11
12 /**
13  *
14  */
15 public abstract class AbstractLinkstateMP<T> implements MPReach<T> {
16
17         private final boolean reachable;
18
19         private final long identifier;
20
21         private final SourceProtocol sourceProtocol;
22
23         protected AbstractLinkstateMP(final long identifier, final SourceProtocol sourceProtocol, final boolean reachable) {
24                 this.identifier = identifier;
25                 this.sourceProtocol = sourceProtocol;
26                 this.reachable = reachable;
27         }
28
29         @Override
30         public boolean isReachable() {
31                 return this.reachable;
32         }
33
34         public long getIdentifier() {
35                 return this.identifier;
36         }
37
38         public SourceProtocol getSourceProtocol() {
39                 return this.sourceProtocol;
40         }
41
42         /* (non-Javadoc)
43          * @see java.lang.Object#hashCode()
44          */
45         @Override
46         public int hashCode() {
47                 final int prime = 31;
48                 int result = 1;
49                 result = prime * result + (int) (this.identifier ^ (this.identifier >>> 32));
50                 result = prime * result + (this.reachable ? 1231 : 1237);
51                 result = prime * result + ((this.sourceProtocol == null) ? 0 : this.sourceProtocol.hashCode());
52                 return result;
53         }
54
55         /* (non-Javadoc)
56          * @see java.lang.Object#equals(java.lang.Object)
57          */
58         @Override
59         public boolean equals(final Object obj) {
60                 if (this == obj)
61                         return true;
62                 if (obj == null)
63                         return false;
64                 if (this.getClass() != obj.getClass())
65                         return false;
66                 final AbstractLinkstateMP<?> other = (AbstractLinkstateMP<?>) obj;
67                 if (this.identifier != other.identifier)
68                         return false;
69                 if (this.reachable != other.reachable)
70                         return false;
71                 if (this.sourceProtocol != other.sourceProtocol)
72                         return false;
73                 return true;
74         }
75
76         /* (non-Javadoc)
77          * @see java.lang.Object#toString()
78          */
79         @Override
80         public String toString() {
81                 final StringBuilder builder = new StringBuilder();
82                 builder.append("AbstractLinkstateMP [reachable=");
83                 builder.append(this.reachable);
84                 builder.append(", identifier=");
85                 builder.append(this.identifier);
86                 builder.append(", sourceProtocol=");
87                 builder.append(this.sourceProtocol);
88                 builder.append("]");
89                 return builder.toString();
90         }
91 }