Debian Codegraph @

layoutlib-api/src/main/java/com/android/ide/common/rendering/api/TextResourceValue.java

raw
1 /*
2 * Copyright (C) 2014 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 package com.android.ide.common.rendering.api;
17
18 import com.android.resources.ResourceType;
19
20 /**
21 * A {@link com.android.ide.common.rendering.api.ResourceValue} intended for text nodes
22 * where we need access to the raw XML text
23 */
24 public class TextResourceValue extends ResourceValue {
25 private String mRawXmlValue;
26
27 public TextResourceValue(ResourceType type, String name, boolean isFramework) {
28 this(type, name, isFramework, null);
29 }
30
31 public TextResourceValue(ResourceType type, String name, boolean isFramework, String libraryName) {
32 super(type, name, isFramework, libraryName);
33 }
34
35 public TextResourceValue(ResourceType type, String name, String textValue, String rawXmlValue,
36 boolean isFramework) {
37 this(type, name, textValue, rawXmlValue, isFramework, null);
38 }
39
40 public TextResourceValue(ResourceType type, String name, String textValue, String rawXmlValue,
41 boolean isFramework, String libraryName) {
42 super(type, name, textValue, isFramework, libraryName);
43 mRawXmlValue = rawXmlValue;
44 }
45
46 @Override
47 public String getRawXmlValue() {
48 if (mRawXmlValue != null) {
49 return mRawXmlValue;
50 }
51 return super.getValue();
52 }
53
54 public void setRawXmlValue(String value) {
55 mRawXmlValue = value;
56 }
57
58 @Override
59 public int hashCode() {
60 final int prime = 31;
61 int result = super.hashCode();
62 result = prime * result + ((mRawXmlValue == null) ? 0 : mRawXmlValue.hashCode());
63 return result;
64 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (this == obj)
69 return true;
70 if (!super.equals(obj))
71 return false;
72 if (getClass() != obj.getClass())
73 return false;
74 TextResourceValue other = (TextResourceValue) obj;
75 if (mRawXmlValue == null) {
76 //noinspection VariableNotUsedInsideIf
77 if (other.mRawXmlValue != null)
78 return false;
79 } else if (!mRawXmlValue.equals(other.mRawXmlValue))
80 return false;
81 return true;
82 }
83
84 }