1 /* 2 * Copyright (C) 2022 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 androidx.constraintlayout.core.dsl; 18 19 import java.util.Arrays; 20 21 /** 22 * This is the base Key for all the key (KeyCycle, KeyPosition, etc.) Objects 23 */ 24 public class Keys { 25 unpack(String[] str)26 protected String unpack(String[] str) { 27 StringBuilder ret = new StringBuilder("["); 28 for (int i = 0; i < str.length; i++) { 29 30 ret.append((i == 0) ? "'" : ",'"); 31 32 ret.append(str[i]); 33 ret.append("'"); 34 35 } 36 ret.append("]"); 37 return ret.toString(); 38 } 39 append(StringBuilder builder, String name, int value)40 protected void append(StringBuilder builder, String name, int value) { 41 if (value != Integer.MIN_VALUE) { 42 builder.append(name); 43 builder.append(":'").append(value).append("',\n"); 44 } 45 } 46 append(StringBuilder builder, String name, String value)47 protected void append(StringBuilder builder, String name, String value) { 48 if (value != null) { 49 builder.append(name); 50 builder.append(":'").append(value).append("',\n"); 51 } 52 } 53 append(StringBuilder builder, String name, float value)54 protected void append(StringBuilder builder, String name, float value) { 55 if (Float.isNaN(value)) { 56 return; 57 } 58 builder.append(name); 59 builder.append(":").append(value).append(",\n"); 60 61 } 62 append(StringBuilder builder, String name, String[] array)63 protected void append(StringBuilder builder, String name, String[] array) { 64 if (array != null) { 65 builder.append(name); 66 builder.append(":").append(unpack(array)).append(",\n"); 67 } 68 } 69 append(StringBuilder builder, String name, float[] array)70 protected void append(StringBuilder builder, String name, float[] array) { 71 if (array != null) { 72 builder.append(name); 73 builder.append("percentWidth:").append(Arrays.toString(array)).append(",\n"); 74 } 75 } 76 77 } 78