BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / EROGeneralizedLabelSubobject.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 java.util.Arrays;
12
13 import com.google.common.base.Objects.ToStringHelper;
14
15 /**
16  * Structure of Generalized Label subobject
17  *
18  * @see <a href="http://tools.ietf.org/html/rfc3471#section-3.2">3.2.
19  *      Generalized Label</a>
20  */
21 public class EROGeneralizedLabelSubobject extends EROLabelSubobject {
22
23     private final byte[] label;
24
25     public EROGeneralizedLabelSubobject(byte[] label, boolean upStream, boolean loose) {
26         super(upStream);
27
28         if (label.length % 4 != 0)
29             throw new IllegalArgumentException("Length of label is not multiple of 4.");
30
31         this.label = label;
32     }
33
34     public byte[] getLabel() {
35         return this.label;
36     }
37
38     @Override
39     public int hashCode() {
40         final int prime = 31;
41         int result = super.hashCode();
42         result = prime * result + Arrays.hashCode(this.label);
43         return result;
44     }
45
46     @Override
47     public boolean equals(Object obj) {
48         if (this == obj)
49             return true;
50         if (!super.equals(obj))
51             return false;
52         if (this.getClass() != obj.getClass())
53             return false;
54         final EROGeneralizedLabelSubobject other = (EROGeneralizedLabelSubobject) obj;
55         if (!Arrays.equals(this.label, other.label))
56             return false;
57         return true;
58     }
59
60     @Override
61         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
62                 toStringHelper.add("label", this.label);
63                 return super.addToStringAttributes(toStringHelper);
64         }
65
66 }