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.ArrayList;
20 
21 /**
22  * Provides the API for creating a ConstraintSet Object for use in the Core
23  * ConstraintLayout & MotionLayout system
24  */
25 public class ConstraintSet {
26     private final String mName;
27     ArrayList<Constraint> mConstraints = new ArrayList<>();
28     ArrayList<Helper> mHelpers = new ArrayList<>();
29 
ConstraintSet(String name)30     public ConstraintSet(String name) {
31         mName = name;
32     }
33 
add(Constraint c)34     public void add(Constraint c) {
35         mConstraints.add(c);
36     }
37 
add(Helper h)38     public void add(Helper h) {
39         mHelpers.add(h);
40     }
41 
42     @Override
toString()43     public String toString() {
44         StringBuilder ret = new StringBuilder(mName + ":{\n");
45         if (!mConstraints.isEmpty()) {
46             for (Constraint cs: mConstraints) {
47                 ret.append(cs.toString());
48             }
49         }
50 
51         if (!mHelpers.isEmpty()) {
52             for (Helper h: mHelpers) {
53                 ret.append(h.toString());
54             }
55         }
56 
57         ret.append("},\n");
58         return ret.toString();
59     }
60 }
61