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;
018
019import java.lang.annotation.*;
020import java.util.*;
021
022import org.apache.juneau.reflect.*;
023import org.apache.juneau.svl.*;
024
025/**
026 * A list of {@link AnnotationWork} objects.
027 *
028 * <h5 class='section'>See Also:</h5><ul>
029 * </ul>
030 *
031 * @serial exclude
032 */
033public class AnnotationWorkList extends ArrayList<AnnotationWork> {
034   private static final long serialVersionUID = 1L;
035
036   //-----------------------------------------------------------------------------------------------------------------
037   // Static
038   //-----------------------------------------------------------------------------------------------------------------
039
040   /**
041    * Static creator.
042    *
043    * @param annotations The annotations to create work from.
044    * @param vrs The variable resolver.
045    * @return A new list.
046    */
047   public static AnnotationWorkList of(VarResolverSession vrs, AnnotationList annotations) {
048      return create(vrs).add(annotations);
049   }
050
051   /**
052    * Static creator.
053    *
054    * @param annotations The annotations to create work from.
055    * @return A new list.
056    */
057   public static AnnotationWorkList of(AnnotationList annotations) {
058      return create().add(annotations);
059   }
060
061   /**
062    * Static creator.
063    *
064    * @return A new list.
065    */
066   public static AnnotationWorkList create() {
067      return new AnnotationWorkList(VarResolver.DEFAULT.createSession());
068   }
069
070   /**
071    * Static creator.
072    *
073    * @param vrs The variable resolver.
074    * @return A new list.
075    */
076   public static AnnotationWorkList create(VarResolverSession vrs) {
077      return new AnnotationWorkList(vrs);
078   }
079
080   //-----------------------------------------------------------------------------------------------------------------
081   // Instance
082   //-----------------------------------------------------------------------------------------------------------------
083
084   private final VarResolverSession vrs;
085
086   private AnnotationWorkList(VarResolverSession vrs) {
087      this.vrs = vrs;
088   }
089
090   /**
091    * Adds an entry to this list.
092    *
093    * @param ai The annotation being applied.
094    * @param aa The applier for the annotation.
095    * @return This object.
096    */
097   public AnnotationWorkList add(AnnotationInfo<?> ai, AnnotationApplier<Annotation,Object> aa) {
098      add(new AnnotationWork(ai, aa));
099      return this;
100   }
101
102   /**
103    * Adds entries for the specified annotations to this work list.
104    *
105    * @param annotations The annotations to create work from.
106    * @return This object.
107    */
108   public AnnotationWorkList add(AnnotationList annotations) {
109      annotations.sort().forEach(x ->  x.getApplies(vrs, y -> add(x, y)));
110      return this;
111   }
112}