Debian Codegraph @

layoutlib-api/src/main/java/com/android/util/PropertiesMap.java

raw
1 /*
2 * Copyright (C) 2016 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.util;
18
19
20 import com.android.annotations.NonNull;
21
22 import java.util.*;
23
24 /**
25 * LayoutLib can return properties that a View asked for at the time of inflation. This map is from
26 * the property name (XML attribute name) to the value - both pre and post resolution.
27 */
28 public class PropertiesMap extends HashMap<String, PropertiesMap.Property> {
29
30 public static final PropertiesMap EMPTY_MAP = new EmptyMap();
31
32 public PropertiesMap() {
33 }
34
35 public PropertiesMap(int capacity) {
36 super(capacity);
37 }
38
39 public static class Property {
40
41 /**
42 * Pre-resolution resource value
43 */
44 public final String resource;
45 /**
46 * Post-resolution value
47 */
48 public final String value;
49
50 public Property(String resource, String value) {
51 this.resource = resource;
52 this.value = value;
53 }
54
55 public boolean equals(Object other) {
56 if (!(other instanceof Property)) {
57 return false;
58 }
59 Property otherProperty = (Property)other;
60 return Objects.equals(resource, otherProperty.resource) &&
61 Objects.equals(value, otherProperty.value);
62 }
63
64 public int hashCode() {
65 return Objects.hash(resource, value);
66 }
67 }
68
69 private static class EmptyMap extends PropertiesMap {
70
71 EmptyMap() {
72 super(0);
73 }
74
75 @Override
76 public int size() {
77 return 0;
78 }
79
80 @Override
81 public boolean isEmpty() {
82 return true;
83 }
84
85 @Override
86 public Property get(Object key) {
87 return null;
88 }
89
90 @Override
91 public boolean containsKey(Object key) {
92 return false;
93 }
94
95 @Override
96 public Property put(String key, Property value) {
97 throw new UnsupportedOperationException();
98 }
99
100 @Override
101 public void putAll(Map<? extends String, ? extends Property> m) {
102 throw new UnsupportedOperationException();
103
104 }
105
106 @Override
107 public Property remove(Object key) {
108 throw new UnsupportedOperationException();
109 }
110
111 @Override
112 public void clear() {
113 }
114
115 @Override
116 public boolean containsValue(Object value) {
117 return false;
118 }
119
120 @NonNull
121 @Override
122 public Set<String> keySet() {
123 return Collections.emptySet();
124 }
125
126 @NonNull
127 @Override
128 public Collection<Property> values() {
129 return Collections.emptySet();
130 }
131
132 @NonNull
133 @Override
134 public Set<Entry<String, Property>> entrySet() {
135 return Collections.emptySet();
136 }
137
138 @Override
139 public Property getOrDefault(Object key, Property defaultValue) {
140 return defaultValue;
141 }
142
143 @Override
144 public Property putIfAbsent(String key, Property value) {
145 throw new UnsupportedOperationException();
146 }
147
148 @Override
149 public boolean remove(Object key, Object value) {
150 throw new UnsupportedOperationException();
151 }
152
153 @Override
154 public boolean replace(String key, Property oldValue, Property newValue) {
155 throw new UnsupportedOperationException();
156 }
157
158 @Override
159 public Property replace(String key, Property value) {
160 throw new UnsupportedOperationException();
161 }
162
163 @Override
164 public boolean equals(Object o) {
165 return (o instanceof Map) && ((Map<?, ?>) o).isEmpty();
166 }
167
168 @Override
169 public int hashCode() {
170 return 0;
171 }
172 }
173 }