001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.svl; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020 021import java.util.*; 022 023import org.apache.juneau.svl.vars.*; 024 025/** 026 * Simple list of variables that can consist of either variable classes or instances. 027 * 028 * <h5 class='section'>See Also:</h5><ul> 029 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SimpleVariableLanguageBasics">Simple Variable Language Basics</a> 030 * </ul> 031 * 032 * @serial exclude 033 */ 034public class VarList extends ArrayList<Object> { 035 036 private static final long serialVersionUID = 1L; 037 038 /** 039 * Returns an empty list of variables. 040 * 041 * @return A new empty list of variables. 042 */ 043 public static VarList create() { 044 return new VarList(); 045 } 046 047 /** 048 * Creates a new list of variables. 049 * 050 * @param vars The variables to create. 051 * @return A new list of variables. 052 */ 053 @SafeVarargs 054 public static final VarList of(Class<? extends Var>...vars) { 055 return create().append(vars); 056 } 057 058 /** 059 * Creates a new list of variables. 060 * 061 * @param vars The variables to create. 062 * @return A new list of variables. 063 */ 064 public static VarList of(Var...vars) { 065 return create().append(vars); 066 } 067 068 /** 069 * Constructor. 070 */ 071 protected VarList() {} 072 073 /** 074 * Copy constructor. 075 * 076 * @param copyFrom The list to copy. 077 */ 078 protected VarList(VarList copyFrom) { 079 super(copyFrom); 080 } 081 082 /** 083 * Adds the default variables to this list. 084 * 085 * <p> 086 * The default variables are: 087 * <ul> 088 * <li>{@link SystemPropertiesVar} 089 * <li>{@link EnvVariablesVar} 090 * <li>{@link ArgsVar} 091 * <li>{@link ManifestFileVar} 092 * <li>{@link SwitchVar} 093 * <li>{@link IfVar} 094 * <li>{@link CoalesceVar} 095 * <li>{@link PatternMatchVar} 096 * <li>{@link PatternReplaceVar} 097 * <li>{@link PatternExtractVar} 098 * <li>{@link UpperCaseVar} 099 * <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}