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.rest.arg;
018
019import static org.apache.juneau.commons.utils.AssertionUtils.*;
020import static org.apache.juneau.commons.utils.CollectionUtils.*;
021
022import java.util.*;
023
024import org.apache.juneau.*;
025import org.apache.juneau.cp.*;
026
027/**
028 * A list of {@link RestOpArg} classes.
029 *
030 * <h5 class='section'>See Also:</h5><ul>
031 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestOpAnnotatedMethodBasics">@RestOp-Annotated Method Basics</a>
032 * </ul>
033 */
034public class RestOpArgList {
035   /**
036    * Builder class.
037    */
038   public static class Builder extends BeanBuilder<RestOpArgList> {
039
040      List<Class<? extends RestOpArg>> entries;
041
042      /**
043       * Constructor.
044       *
045       * @param beanStore The bean store to use for creating beans.
046       */
047      protected Builder(BeanStore beanStore) {
048         super(RestOpArgList.class, beanStore);
049         entries = list();
050      }
051
052      /**
053       * Prepends the specified rest op arg classes to the list.
054       *
055       * @param values The values to add.
056       * @return This object.
057       * @throws IllegalArgumentException if any class does not extend from {@link RestOpArg}.
058       */
059      public Builder add(Class<?>...values) {
060         prependAll(entries, assertClassArrayArgIsType("values", RestOpArg.class, values));
061         return this;
062      }
063
064      @Override /* Overridden from BeanBuilder */
065      public Builder impl(Object value) {
066         super.impl(value);
067         return this;
068      }
069
070      @Override /* Overridden from BeanBuilder */
071      public Builder type(Class<?> value) {
072         super.type(value);
073         return this;
074      }
075
076      @Override /* Overridden from BeanBuilder */
077      protected RestOpArgList buildDefault() {
078         return new RestOpArgList(this);
079      }
080   }
081
082   /**
083    * Static creator.
084    *
085    * @param beanStore The bean store to use for creating beans.
086    * @return A new builder for this object.
087    */
088   public static Builder create(BeanStore beanStore) {
089      return new Builder(beanStore);
090   }
091
092   private final Class<? extends RestOpArg>[] entries;
093
094   /**
095    * Constructor.
096    *
097    * @param builder The builder containing the contents for this list.
098    */
099   @SuppressWarnings("unchecked")
100   protected RestOpArgList(Builder builder) {
101      entries = builder.entries.stream().toArray(Class[]::new);
102   }
103
104   /**
105    * Returns the contents of this list as a {@link Class} array.
106    *
107    * @return The contents of this list as a {@link Class} array.
108    */
109   public Class<? extends RestOpArg>[] asArray() {
110      return entries;
111   }
112}