• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.common.rendering.api;
18 
19 /**
20  * A resource reference. This contains the String ID of the resource and whether this is a framework
21  * reference.
22  * This is an immutable class.
23  *
24  */
25 public class ResourceReference {
26     private final String mName;
27     private final boolean mIsFramework;
28 
29     /**
30      * Builds a resource reference.
31      * @param name the name of the resource
32      * @param isFramework whether the reference is to a framework resource.
33      */
ResourceReference(String name, boolean isFramework)34     public ResourceReference(String name, boolean isFramework) {
35         mName = name;
36         mIsFramework = isFramework;
37     }
38 
39     /**
40      * Builds a non-framework resource reference.
41      * @param name the name of the resource
42      */
ResourceReference(String name)43     public ResourceReference(String name) {
44         this(name, false /*platformLayout*/);
45     }
46 
47     /**
48      * Returns the name of the resource, as defined in the XML.
49      */
getName()50     public final String getName() {
51         return mName;
52     }
53 
54     /**
55      * Returns whether the resource is a framework resource (<code>true</code>) or a project
56      * resource (<code>false</false>).
57      */
isFramework()58     public final boolean isFramework() {
59         return mIsFramework;
60     }
61 
62     /* (non-Javadoc)
63      * @see java.lang.Object#hashCode()
64      */
65     @Override
hashCode()66     public int hashCode() {
67         final int prime = 31;
68         int result = 1;
69         result = prime * result + (mIsFramework ? 1231 : 1237);
70         result = prime * result + ((mName == null) ? 0 : mName.hashCode());
71         return result;
72     }
73 
74     /* (non-Javadoc)
75      * @see java.lang.Object#equals(java.lang.Object)
76      */
77     @Override
equals(Object obj)78     public boolean equals(Object obj) {
79         if (this == obj)
80             return true;
81         if (obj == null)
82             return false;
83         if (getClass() != obj.getClass())
84             return false;
85         ResourceReference other = (ResourceReference) obj;
86         if (mIsFramework != other.mIsFramework)
87             return false;
88         if (mName == null) {
89             if (other.mName != null)
90                 return false;
91         } else if (!mName.equals(other.mName))
92             return false;
93         return true;
94     }
95 
96     /* (non-Javadoc)
97      * @see java.lang.Object#toString()
98      */
99     @Override
toString()100     public String toString() {
101         return "ResourceReference [" + mName + " (framework:" + mIsFramework+ ")]";
102     }
103 }
104