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