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.util.*;
016
017/**
018 * Identifies how to add elements to a list.
019 */
020public enum AddFlag {
021
022   /**
023    * Any previous value(s) should be overwritten/replaced.
024    */
025   APPEND,
026
027   /**
028    * Any previous value(s) should be overwritten/replaced.
029    */
030   PREPEND,
031
032   /**
033    * Any previous value(s) should be overwritten/replaced.
034    */
035   REPLACE,
036
037   /**
038    * Don't add the value if it's <jk>null</jk> or an empty string.
039    */
040   SKIP_IF_EMPTY;
041
042   /**
043    * Default flags.
044    */
045   public static final EnumSet<AddFlag> DEFAULT_FLAGS = EnumSet.of(APPEND);
046
047   /**
048    * Default skip-if-empty flags.
049    */
050   public static final EnumSet<AddFlag> SKIP_IF_EMPTY_FLAGS = EnumSet.of(APPEND, SKIP_IF_EMPTY);
051
052   /**
053    * Returns {@link #DEFAULT_FLAGS} if the enum set is <jk>null</jk> or empty.
054    *
055    * @param s The set to check.
056    * @return Either the same set or {@link #DEFAULT_FLAGS}.  Never <jk>null</jk>.
057    */
058   public static EnumSet<AddFlag> orDefault(EnumSet<AddFlag> s) {
059      return s == null || s.isEmpty() ? DEFAULT_FLAGS : s;
060   }
061}