View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.svl;
18  
19  import static org.apache.juneau.commons.utils.CollectionUtils.*;
20  
21  import java.util.*;
22  
23  import org.apache.juneau.svl.vars.*;
24  
25  /**
26   * Simple list of variables that can consist of either variable classes or instances.
27   *
28   * <h5 class='section'>See Also:</h5><ul>
29   * 	<li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SimpleVariableLanguageBasics">Simple Variable Language Basics</a>
30   * </ul>
31   *
32   * @serial exclude
33   */
34  public class VarList extends ArrayList<Object> {
35  
36  	private static final long serialVersionUID = 1L;
37  
38  	/**
39  	 * Returns an empty list of variables.
40  	 *
41  	 * @return A new empty list of variables.
42  	 */
43  	public static VarList create() {
44  		return new VarList();
45  	}
46  
47  	/**
48  	 * Creates a new list of variables.
49  	 *
50  	 * @param vars The variables to create.
51  	 * @return A new list of variables.
52  	 */
53  	@SafeVarargs
54  	public static final VarList of(Class<? extends Var>...vars) {
55  		return create().append(vars);
56  	}
57  
58  	/**
59  	 * Creates a new list of variables.
60  	 *
61  	 * @param vars The variables to create.
62  	 * @return A new list of variables.
63  	 */
64  	public static VarList of(Var...vars) {
65  		return create().append(vars);
66  	}
67  
68  	/**
69  	 * Constructor.
70  	 */
71  	protected VarList() {}
72  
73  	/**
74  	 * Copy constructor.
75  	 *
76  	 * @param copyFrom The list to copy.
77  	 */
78  	protected VarList(VarList copyFrom) {
79  		super(copyFrom);
80  	}
81  
82  	/**
83  	 * Adds the default variables to this list.
84  	 *
85  	 * <p>
86  	 * The default variables are:
87  	 * <ul>
88  	 * 	<li>{@link SystemPropertiesVar}
89  	 * 	<li>{@link EnvVariablesVar}
90  	 * 	<li>{@link ArgsVar}
91  	 * 	<li>{@link ManifestFileVar}
92  	 * 	<li>{@link SwitchVar}
93  	 * 	<li>{@link IfVar}
94  	 * 	<li>{@link CoalesceVar}
95  	 * 	<li>{@link PatternMatchVar}
96  	 * 	<li>{@link PatternReplaceVar}
97  	 * 	<li>{@link PatternExtractVar}
98  	 * 	<li>{@link UpperCaseVar}
99  	 * 	<li>{@link LowerCaseVar}
100 	 * 	<li>{@link NotEmptyVar}
101 	 * 	<li>{@link LenVar}
102 	 * 	<li>{@link SubstringVar}
103 	 * </ul>
104 	 *
105 	 * @return This object.
106 	 */
107 	public VarList addDefault() {
108 		// @formatter:off
109 		return append(
110 			SystemPropertiesVar.class,
111 			EnvVariablesVar.class,
112 			ManifestFileVar.class,
113 			ArgsVar.class,
114 			SwitchVar.class,
115 			IfVar.class,
116 			CoalesceVar.class,
117 			PatternMatchVar.class,
118 			PatternReplaceVar.class,
119 			PatternExtractVar.class,
120 			UpperCaseVar.class,
121 			LowerCaseVar.class,
122 			NotEmptyVar.class,
123 			LenVar.class,
124 			SubstringVar.class
125 		);
126 		// @formatter:on
127 	}
128 
129 	/**
130 	 * Adds a list of variables to this list.
131 	 *
132 	 * @param vars The variables to append to this list.
133 	 * @return This object.
134 	 */
135 	@SafeVarargs
136 	public final VarList append(Class<? extends Var>...vars) {
137 		addAll(l(vars));
138 		return this;
139 	}
140 
141 	/**
142 	 * Adds a list of variables to this list.
143 	 *
144 	 * @param vars The variables to append to this list.
145 	 * @return This object.
146 	 */
147 	public VarList append(Var...vars) {
148 		addAll(l(vars));
149 		return this;
150 	}
151 
152 	/**
153 	 * Adds a list of variables to this list.
154 	 *
155 	 * @param vars The variables to append to this list.
156 	 * @return This object.
157 	 */
158 	public VarList append(VarList vars) {
159 		addAll(vars);
160 		return this;
161 	}
162 
163 	/**
164 	 * Makes a copy of this list.
165 	 *
166 	 * @return A new copy of this list.
167 	 */
168 	public VarList copy() {
169 		return new VarList(this);
170 	}
171 }