1 /* 2 * Copyright (C) 2021 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 androidx.constraintlayout.core.parser; 17 18 public class CLArray extends CLContainer { CLArray(char[] content)19 public CLArray(char[] content) { 20 super(content); 21 } 22 23 // @TODO: add description allocate(char[] content)24 public static CLElement allocate(char[] content) { 25 return new CLArray(content); 26 } 27 28 @Override toJSON()29 protected String toJSON() { 30 StringBuilder content = new StringBuilder(getDebugName() + "["); 31 boolean first = true; 32 for (int i = 0; i < mElements.size(); i++) { 33 if (!first) { 34 content.append(", "); 35 } else { 36 first = false; 37 } 38 content.append(mElements.get(i).toJSON()); 39 } 40 return content + "]"; 41 } 42 43 @Override toFormattedJSON(int indent, int forceIndent)44 protected String toFormattedJSON(int indent, int forceIndent) { 45 StringBuilder json = new StringBuilder(); 46 String val = toJSON(); 47 if (forceIndent <= 0 && val.length() + indent < sMaxLine) { 48 json.append(val); 49 } else { 50 json.append("[\n"); 51 boolean first = true; 52 for (CLElement element : mElements) { 53 if (!first) { 54 json.append(",\n"); 55 } else { 56 first = false; 57 } 58 addIndent(json, indent + sBaseIndent); 59 json.append(element.toFormattedJSON(indent + sBaseIndent, forceIndent - 1)); 60 } 61 json.append("\n"); 62 addIndent(json, indent); 63 json.append("]"); 64 } 65 return json.toString(); 66 } 67 } 68