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.common.utils.Utils.*; 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 public static VarList of(Var...vars) { 054 return create().append(vars); 055 } 056 057 /** 058 * Creates a new list of variables. 059 * 060 * @param vars The variables to create. 061 * @return A new list of variables. 062 */ 063 @SafeVarargs 064 public static final VarList of(Class<? extends Var>...vars) { 065 return create().append(vars); 066 } 067 068 /** 069 * Constructor. 070 */ 071 protected VarList() { 072 } 073 074 /** 075 * Copy constructor. 076 * 077 * @param copyFrom The list to copy. 078 */ 079 protected VarList(VarList copyFrom) { 080 super(copyFrom); 081 } 082 083 /** 084 * Adds a list of variables to this list. 085 * 086 * @param vars The variables to append to this list. 087 * @return This object. 088 */ 089 public VarList append(Var...vars) { 090 addAll(alist(vars)); 091 return this; 092 } 093 094 /** 095 * Adds a list of variables to this list. 096 * 097 * @param vars The variables to append to this list. 098 * @return This object. 099 */ 100 public VarList append(VarList vars) { 101 addAll(vars); 102 return this; 103 } 104 105 /** 106 * Adds a list of variables to this list. 107 * 108 * @param vars The variables to append to this list. 109 * @return This object. 110 */ 111 @SafeVarargs 112 public final VarList append(Class<? extends Var>...vars) { 113 addAll(alist(vars)); 114 return this; 115 } 116 117 /** 118 * Adds the default variables to this list. 119 * 120 * <p> 121 * The default variables are: 122 * <ul> 123 * <li>{@link SystemPropertiesVar} 124 * <li>{@link EnvVariablesVar} 125 * <li>{@link ArgsVar} 126 * <li>{@link ManifestFileVar} 127 * <li>{@link SwitchVar} 128 * <li>{@link IfVar} 129 * <li>{@link CoalesceVar} 130 * <li>{@link PatternMatchVar} 131 * <li>{@link PatternReplaceVar} 132 * <li>{@link PatternExtractVar} 133 * <li>{@link UpperCaseVar} 134 * <li>{@link LowerCaseVar} 135 * <li>{@link NotEmptyVar} 136 * <li>{@link LenVar} 137 * <li>{@link SubstringVar} 138 * </ul> 139 * 140 * @return This object. 141 */ 142 public VarList addDefault() { 143 return append( 144 SystemPropertiesVar.class, 145 EnvVariablesVar.class, 146 ManifestFileVar.class, 147 ArgsVar.class, 148 SwitchVar.class, 149 IfVar.class, 150 CoalesceVar.class, 151 PatternMatchVar.class, 152 PatternReplaceVar.class, 153 PatternExtractVar.class, 154 UpperCaseVar.class, 155 LowerCaseVar.class, 156 NotEmptyVar.class, 157 LenVar.class, 158 SubstringVar.class 159 ); 160 } 161 162 /** 163 * Makes a copy of this list. 164 * 165 * @return A new copy of this list. 166 */ 167 public VarList copy() { 168 return new VarList(this); 169 } 170}