BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / authorization / Resource.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.authorization;
11
12 import java.io.Serializable;
13
14 /**
15  * It represents the elementary resource along with
16  * the access privilege associated to it
17  */
18 public class Resource implements Serializable {
19     private static final long serialVersionUID = 1L;
20     Object resource; // the generic resource
21     Privilege privilege; // read/use/write privilege
22
23     public Resource(Object resource, Privilege privilege) {
24         this.resource = resource;
25         this.privilege = privilege;
26     }
27
28     public Object getResource() {
29         return resource;
30     }
31
32     public Privilege getPrivilege() {
33         return privilege;
34     }
35
36     @Override
37     public int hashCode() {
38         final int prime = 31;
39         int result = 1;
40         result = prime * result
41                 + ((privilege == null) ? 0 : privilege.hashCode());
42         result = prime * result
43                 + ((resource == null) ? 0 : resource.hashCode());
44         return result;
45     }
46
47     @Override
48     public boolean equals(Object obj) {
49         if (this == obj)
50             return true;
51         if (obj == null)
52             return false;
53         if (getClass() != obj.getClass())
54             return false;
55         Resource other = (Resource) obj;
56         if (privilege != other.privilege)
57             return false;
58         if (resource == null) {
59             if (other.resource != null)
60                 return false;
61         } else if (!resource.equals(other.resource))
62             return false;
63         return true;
64     }
65
66     @Override
67     public String toString() {
68         return "[" + resource + ", " + privilege.toString() + "]";
69     }
70 }