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.jsonschema;
014
015import static org.apache.juneau.common.internal.StringUtils.*;
016import static org.apache.juneau.internal.CollectionUtils.*;
017import java.util.*;
018
019/**
020 * Represents possible values for JSONSCHEMA_addExamplesTo and JSONSCHEMA_addDescriptionsTo.
021 *
022 * <ul class='javatree'>
023 *    <li class='jm'>{@link JsonSchemaGenerator.Builder#addExamplesTo(TypeCategory...)}
024 *    <li class='jm'>{@link JsonSchemaGenerator.Builder#addDescriptionsTo(TypeCategory...)}
025 * </ul>
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.JsonSchemaDetails">JSON-Schema Support</a>
029 * </ul>
030 */
031public enum TypeCategory {
032
033   /** Beans */
034   BEAN,
035
036   /** Map */
037   MAP,
038
039   /** List/Set */
040   COLLECTION,
041
042   /** Array */
043   ARRAY,
044
045   /** Boolean (including primitives) */
046   BOOLEAN,
047
048   /** Short/Integer/Long/Float/Double (including primitives) */
049   NUMBER,
050
051   /** String/CharSequence/Character */
052   STRING,
053
054   /** Enums */
055   ENUM,
056
057   /** Anything else */
058   OTHER,
059
060   /** Anything */
061   ANY;
062
063   /**
064    * Parses a comma-delimited list of values into a set of {@link TypeCategory} values.
065    *
066    * @param s The comma-delimited string.
067    * @return A comma-delimited list of values into a set of {@link TypeCategory} values.
068    */
069   public static Set<TypeCategory> parse(String s) {
070      if (s == null || s.isEmpty())
071         return Collections.emptySet();
072      Set<TypeCategory> set = set();
073      split(s, x -> set.add(valueOf(x.toUpperCase())));
074      return set;
075   }
076
077   /**
078    * Parses a comma-delimited list of values into an array of {@link TypeCategory} values.
079    *
080    * @param s The comma-delimited string.
081    * @return A comma-delimited list of values into an array of {@link TypeCategory} values.
082    */
083   public static TypeCategory[] parseArray(String s) {
084      if (s == null || s.isEmpty())
085         return new TypeCategory[0];
086      List<TypeCategory> list = list();
087      split(s, x -> list.add(valueOf(x.toUpperCase())));
088      return list.toArray(new TypeCategory[list.size()]);
089   }
090}