Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPP2MPEndPointsObject.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.List;
11
12 import org.opendaylight.protocol.concepts.NetworkAddress;
13 import com.google.common.base.Objects.ToStringHelper;
14
15 public class PCEPP2MPEndPointsObject<T extends NetworkAddress<T>> extends PCEPEndPoints {
16
17     private final long leafType;
18
19     private final T sourceAddress;
20
21     private final List<T> destinationAddresses;
22
23     public PCEPP2MPEndPointsObject(long leafType, T sourceAddress, List<T> destinationAddresses, boolean processed, boolean ignored) {
24         super(processed, ignored);
25         this.leafType = leafType;
26         this.sourceAddress = sourceAddress;
27         if (destinationAddresses == null || destinationAddresses.isEmpty())
28             throw new IllegalArgumentException("At least one destination have to be specified.");
29
30         this.destinationAddresses = destinationAddresses;
31     }
32
33     /**
34      * @return the leafType
35      */
36     public long getLeafType() {
37         return this.leafType;
38     }
39
40     /**
41      * @return the sourceAddress
42      */
43     public T getSourceAddress() {
44         return this.sourceAddress;
45     }
46
47     /**
48      * @return the destinationAddresses
49      */
50     public List<T> getDestinationAddresses() {
51         return this.destinationAddresses;
52     }
53
54     @Override
55     public int hashCode() {
56         final int prime = 31;
57         int result = super.hashCode();
58         result = prime * result + ((this.destinationAddresses == null) ? 0 : this.destinationAddresses.hashCode());
59         result = prime * result + (int) (this.leafType ^ (this.leafType >>> 32));
60         result = prime * result + ((this.sourceAddress == null) ? 0 : this.sourceAddress.hashCode());
61         return result;
62     }
63
64     @Override
65     public boolean equals(Object obj) {
66         if (this == obj)
67             return true;
68         if (!super.equals(obj))
69             return false;
70         if (this.getClass() != obj.getClass())
71             return false;
72         final PCEPP2MPEndPointsObject<?> other = (PCEPP2MPEndPointsObject<?>) obj;
73         if (this.destinationAddresses == null) {
74             if (other.destinationAddresses != null)
75                 return false;
76         } else if (!this.destinationAddresses.equals(other.destinationAddresses))
77             return false;
78         if (this.leafType != other.leafType)
79             return false;
80         if (this.sourceAddress == null) {
81             if (other.sourceAddress != null)
82                 return false;
83         } else if (!this.sourceAddress.equals(other.sourceAddress))
84             return false;
85         return true;
86     }
87
88         @Override
89         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
90                 toStringHelper.add("leafType", this.leafType);
91                 toStringHelper.add("sourceAddress", this.sourceAddress);
92                 toStringHelper.add("destinationAddresses", this.destinationAddresses);
93                 return super.addToStringAttributes(toStringHelper);
94         }
95
96 }