Skip to content

Commit 703b884

Browse files
pekingmedrchen
authored andcommitted
[Color] Replaced computeIfAbsent with equivalent code for API 21 - 23.
PiperOrigin-RevId: 659631592
1 parent f14b0c0 commit 703b884

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/java/com/google/android/material/color/utilities/TonalPalette.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ private TonalPalette(double hue, double chroma, Hct keyColor) {
8080
* @param tone HCT tone, measured from 0 to 100.
8181
* @return ARGB representation of a color with that tone.
8282
*/
83-
// AndroidJdkLibsChecker is higher priority than ComputeIfAbsentUseValue (b/119581923)
84-
@SuppressWarnings("ComputeIfAbsentUseValue")
8583
public int tone(int tone) {
8684
Integer color = cache.get(tone);
8785
if (color == null) {
@@ -177,8 +175,13 @@ public Hct create() {
177175

178176
// Find the maximum chroma for a given tone
179177
private double maxChroma(int tone) {
180-
return chromaCache.computeIfAbsent(
181-
tone, (Integer key) -> Hct.from(hue, MAX_CHROMA_VALUE, key).getChroma());
178+
if (chromaCache.get(tone) == null) {
179+
Double newChroma = Hct.from(hue, MAX_CHROMA_VALUE, tone).getChroma();
180+
if (newChroma != null) {
181+
chromaCache.put(tone, newChroma);
182+
}
183+
}
184+
return chromaCache.get(tone);
182185
}
183186
}
184187
}

0 commit comments

Comments
 (0)