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