BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / ExplicitRouteSubobject.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.subobject;
9
10 import com.google.common.base.Objects;
11 import com.google.common.base.Objects.ToStringHelper;
12
13 /**
14  * Base class for Explicit route subobjects.
15  *
16  * @see <a href="http://tools.ietf.org/html/rfc3209#section-4.3">4.3. Explicit
17  *      Route Object</a>
18  */
19 public abstract class ExplicitRouteSubobject {
20     protected final boolean loose;
21
22     protected ExplicitRouteSubobject() {
23         this.loose = false;
24     }
25
26     protected ExplicitRouteSubobject(boolean loose) {
27         this.loose = loose;
28     }
29
30     /**
31      * @see <a href="http://tools.ietf.org/html/rfc3209#section-4.3.3.1">Strict
32      *      and Loose Subobjects</a>
33      *
34      * @return true if L flag is set and false if is not.
35      */
36     public boolean isLoose() {
37         return this.loose;
38     }
39
40         @Override
41         public String toString(){
42                 return this.addToStringAttributes(Objects.toStringHelper(this)).toString();
43         }
44
45         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
46                 toStringHelper.add("loose", this.loose);
47                 return toStringHelper;
48         }
49
50     @Override
51     public int hashCode() {
52         final int prime = 31;
53         int result = 1;
54         result = prime * result + (this.loose ? 1231 : 1237);
55         return result;
56     }
57
58     @Override
59     public boolean equals(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 ExplicitRouteSubobject other = (ExplicitRouteSubobject) obj;
67         if (this.loose != other.loose)
68             return false;
69         return true;
70     }
71 }