Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPEndPointsObject.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.NetworkAddress;
11 import com.google.common.base.Objects.ToStringHelper;
12
13 /**
14  * Parameterized structure of PCEP End Points Object.
15  *
16  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.6">PCEP
17  *      EndPointsObject</a>
18  * @param <T>
19  *            subtype of NetworkAddress
20  */
21 public class PCEPEndPointsObject<T extends NetworkAddress<T>> extends PCEPEndPoints {
22
23     private final T sourceAddress;
24
25     private final T destinationAddress;
26
27     /**
28      * Constructs Close Object with mandatory object.
29      *
30      * @param sourceAddress
31      *            T. Cant't be null.
32      * @param destinationAddress
33      *            T. Cant't be null.
34      */
35     public PCEPEndPointsObject(T sourceAddress, T destinationAddress) {
36         super(true, false);
37         if (sourceAddress == null)
38             throw new IllegalArgumentException("Source address is mantadory.");
39         this.sourceAddress = sourceAddress;
40         if (destinationAddress == null)
41             throw new IllegalArgumentException("Destination address is mantadory.");
42         this.destinationAddress = destinationAddress;
43     }
44
45     /**
46      * Gets source address of type T.
47      *
48      * @return T. Can't be null.
49      */
50     public T getSourceAddress() {
51         return this.sourceAddress;
52     }
53
54     /**
55      * Gets destination address of type T.
56      *
57      * @return T. Can't be null.
58      */
59     public T getDestinationAddress() {
60         return this.destinationAddress;
61     }
62
63         @Override
64         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
65                 toStringHelper.add("sourceAddress", this.sourceAddress);
66                 toStringHelper.add("destinationAddress", this.destinationAddress);
67                 return super.addToStringAttributes(toStringHelper);
68         }
69
70     @Override
71     public int hashCode() {
72         final int prime = 31;
73         int result = super.hashCode();
74         result = prime * result + ((this.destinationAddress == null) ? 0 : this.destinationAddress.hashCode());
75         result = prime * result + ((this.sourceAddress == null) ? 0 : this.sourceAddress.hashCode());
76         return result;
77     }
78
79     @Override
80     public boolean equals(Object obj) {
81         if (this == obj)
82             return true;
83         if (!super.equals(obj))
84             return false;
85         if (!(obj instanceof PCEPEndPointsObject))
86             return false;
87         final PCEPEndPointsObject<?> other = (PCEPEndPointsObject<?>) obj;
88         if (this.destinationAddress == null) {
89             if (other.destinationAddress != null)
90                 return false;
91         } else if (!this.destinationAddress.equals(other.destinationAddress))
92             return false;
93         if (this.sourceAddress == null) {
94             if (other.sourceAddress != null)
95                 return false;
96         } else if (!this.sourceAddress.equals(other.sourceAddress))
97             return false;
98         return true;
99     }
100 }