001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.svl; 014 015import static org.apache.juneau.internal.CollectionUtils.*; 016 017import java.util.*; 018 019import org.apache.juneau.svl.vars.*; 020 021/** 022 * Simple list of variables that can consist of either variable classes or instances. 023 * 024 * <h5 class='section'>See Also:</h5><ul> 025 * <li class='link'><a class="doclink" href="../../../../index.html#jm.SimpleVariableLanguage">Simple Variable Language</a> 026 * </ul> 027 * 028 * @serial exclude 029 */ 030public class VarList extends ArrayList<Object> { 031 032 private static final long serialVersionUID = 1L; 033 034 /** 035 * Returns an empty list of variables. 036 * 037 * @return A new empty list of variables. 038 */ 039 public static VarList create() { 040 return new VarList(); 041 } 042 043 /** 044 * Creates a new list of variables. 045 * 046 * @param vars The variables to create. 047 * @return A new list of variables. 048 */ 049 public static VarList of(Var...vars) { 050 return create().append(vars); 051 } 052 053 /** 054 * Creates a new list of variables. 055 * 056 * @param vars The variables to create. 057 * @return A new list of variables. 058 */ 059 @SafeVarargs 060 public static final VarList of(Class<? extends Var>...vars) { 061 return create().append(vars); 062 } 063 064 /** 065 * Constructor. 066 */ 067 protected VarList() { 068 super(); 069 } 070 071 /** 072 * Copy constructor. 073 * 074 * @param copyFrom The list to copy. 075 */ 076 protected VarList(VarList copyFrom) { 077 super(copyFrom); 078 } 079 080 /** 081 * Adds a list of variables to this list. 082 * 083 * @param vars The variables to append to this list. 084 * @return This object. 085 */ 086 public VarList append(Var...vars) { 087 addAll(alist(vars)); 088 return this; 089 } 090 091 /** 092 * Adds a list of variables to this list. 093 * 094 * @param vars The variables to append to this list. 095 * @return This object. 096 */ 097 public VarList append(VarList vars) { 098 addAll(vars); 099 return this; 100 } 101 102 /** 103 * Adds a list of variables to this list. 104 * 105 * @param vars The variables to append to this list. 106 * @return This object. 107 */ 108 @SafeVarargs 109 public final VarList append(Class<? extends Var>...vars) { 110 addAll(alist(vars)); 111 return this; 112 } 113 114 /** 115 * Adds the default variables to this list. 116 * 117 * <p> 118 * The default variables are: 119 * <ul> 120 * <li>{@link SystemPropertiesVar} 121 * <li>{@link EnvVariablesVar} 122 * <li>{@link ArgsVar} 123 * <li>{@link ManifestFileVar} 124 * <li>{@link SwitchVar} 125 * <li>{@link IfVar} 126 * <li>{@link CoalesceVar} 127 * <li>{@link PatternMatchVar} 128 * <li>{@link PatternReplaceVar} 129 * <li>{@link PatternExtractVar} 130 * <li>{@link UpperCaseVar} 131 * <li>{@link LowerCaseVar} 132 * <li>{@link NotEmptyVar} 133 * <li>{@link LenVar} 134 * <li>{@link SubstringVar} 135 * </ul> 136 * 137 * @return This object. 138 */ 139 public VarList addDefault() { 140 return append( 141 SystemPropertiesVar.class, 142 EnvVariablesVar.class, 143 ManifestFileVar.class, 144 ArgsVar.class, 145 SwitchVar.class, 146 IfVar.class, 147 CoalesceVar.class, 148 PatternMatchVar.class, 149 PatternReplaceVar.class, 150 PatternExtractVar.class, 151 UpperCaseVar.class, 152 LowerCaseVar.class, 153 NotEmptyVar.class, 154 LenVar.class, 155 SubstringVar.class 156 ); 157 } 158 159 /** 160 * Makes a copy of this list. 161 * 162 * @return A new copy of this list. 163 */ 164 public VarList copy() { 165 return new VarList(this); 166 } 167}