BUG-47 : unfinished PCEP migration to generated DTOs.
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / ObjectHeaderImpl.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.spi;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
11 import org.opendaylight.yangtools.yang.binding.DataContainer;
12
13 /**
14  * Header parser for {@link org.opendaylight.protocol.pcep.PCEPObject PCEPObject}
15  */
16 public class ObjectHeaderImpl implements ObjectHeader {
17
18         /*
19          * Common object header fields lengths in bytes
20          */
21         public final static int OC_F_LENGTH = 1;
22         public final static int OT_FLAGS_MF_LENGTH = 1; // multi-field
23         public final static int OBJ_LENGTH_F_LENGTH = 2;
24
25         /*
26          * size of fields inside of multi-filed in bits
27          */
28         public final static int OT_SF_LENGTH = 4;
29         public final static int FLAGS_SF_LENGTH = 4;
30
31         /*
32          * offsets of fields inside of multi-field in bits
33          */
34         public final static int OT_SF_OFFSET = 0;
35         public final static int FLAGS_SF_OFFSET = OT_SF_OFFSET + OT_SF_LENGTH;
36
37         /*
38          * flags offsets inside multi-filed
39          */
40         public final static int P_FLAG_OFFSET = 6;
41         public final static int I_FLAG_OFFSET = 7;
42
43         /*
44          * Common object header fields offsets in bytes;
45          */
46         public final static int OC_F_OFFSET = 0;
47         public final static int OT_FLAGS_MF_OFFSET = OC_F_OFFSET + OC_F_LENGTH;
48         public final static int OBJ_LENGTH_F_OFFSET = OT_FLAGS_MF_OFFSET + OT_FLAGS_MF_LENGTH;
49         public final static int OBJ_BODY_OFFSET = OBJ_LENGTH_F_OFFSET + OBJ_LENGTH_F_LENGTH;
50
51         /*
52          * Common object header length in bytes
53          */
54         public final static int COMMON_OBJECT_HEADER_LENGTH = (OC_F_LENGTH + OT_FLAGS_MF_LENGTH + OBJ_LENGTH_F_LENGTH);
55
56         public final boolean processed;
57         public final boolean ignored;
58
59         public ObjectHeaderImpl(final boolean processed, final boolean ignore) {
60                 this.processed = processed;
61                 this.ignored = ignore;
62
63         }
64         
65         @Override
66         public Class<? extends DataContainer> getImplementedInterface() {
67                 return ObjectHeader.class;
68         }
69
70         @Override
71         public Boolean isIgnore() {
72                 return this.ignored;
73         }
74
75         @Override
76         public Boolean isProcessingRule() {
77                 return this.processed;
78         }
79
80         @Override
81         public String toString() {
82                 final StringBuilder builder = new StringBuilder();
83                 builder.append("ObjectHeader [objClass=");
84                 builder.append(", processed=");
85                 builder.append(this.processed);
86                 builder.append(", ignored=");
87                 builder.append(this.ignored);
88                 builder.append("]");
89                 return builder.toString();
90         }
91
92         @Override
93         public int hashCode() {
94                 final int prime = 31;
95                 int result = 1;
96                 result = prime * result + (this.ignored ? 1231 : 1237);
97                 result = prime * result + (this.processed ? 1231 : 1237);
98                 return result;
99         }
100
101         @Override
102         public boolean equals(final Object obj) {
103                 if (this == obj)
104                         return true;
105                 if (obj == null)
106                         return false;
107                 if (this.getClass() != obj.getClass())
108                         return false;
109                 final ObjectHeaderImpl other = (ObjectHeaderImpl) obj;
110                 if (this.ignored != other.ignored)
111                         return false;
112                 if (this.processed != other.processed)
113                         return false;
114                 return true;
115         }
116 }