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.http.header;
014
015import static org.apache.juneau.http.Constants.*;
016
017import java.util.function.*;
018
019import org.apache.juneau.http.annotation.*;
020import org.apache.juneau.internal.*;
021
022/**
023 * Represents a parsed <l>X-Client-Version</l> HTTP request header.
024 */
025@Header("X-Client-Version")
026public class ClientVersion extends BasicStringHeader {
027
028   private static final long serialVersionUID = 1L;
029
030   private static final Cache<String,ClientVersion> CACHE = new Cache<>(NOCACHE, CACHE_MAX_SIZE);
031
032   /**
033    * Returns a parsed and cached header.
034    *
035    * @param value
036    *    The header value.
037    * @return A cached {@link ClientVersion} object.
038    */
039   public static ClientVersion of(String value) {
040      if (value == null)
041         return null;
042      ClientVersion x = CACHE.get(value);
043      if (x == null)
044         x = CACHE.put(value, new ClientVersion(value));
045      return x;
046   }
047
048   /**
049    * Convenience creator.
050    *
051    * @param value
052    *    The header value.
053    *    <br>Can be any of the following:
054    *    <ul>
055    *       <li>{@link String}
056    *       <li>Anything else - Converted to <c>String</c> then parsed.
057    *    </ul>
058    * @return A new {@link ClientVersion} object.
059    */
060   public static ClientVersion of(Object value) {
061      if (value == null)
062         return null;
063      return new ClientVersion(value);
064   }
065
066   /**
067    * Convenience creator using supplier.
068    *
069    * <p>
070    * Header value is re-evaluated on each call to {@link #getValue()}.
071    *
072    * @param value
073    *    The header value supplier.
074    *    <br>Can be any of the following:
075    *    <ul>
076    *       <li>{@link String}
077    *       <li>Anything else - Converted to <c>String</c> then parsed.
078    *    </ul>
079    * @return A new {@link ClientVersion} object.
080    */
081   public static ClientVersion of(Supplier<?> value) {
082      if (value == null)
083         return null;
084      return new ClientVersion(value);
085   }
086
087   /**
088    * Constructor.
089    *
090    * @param value
091    *    The header value.
092    *    <br>Can be any of the following:
093    *    <ul>
094    *       <li>{@link String}
095    *       <li>Anything else - Converted to <c>String</c> then parsed.
096    *       <li>A {@link Supplier} of anything on this list.
097    *    </ul>
098    */
099   public ClientVersion(Object value) {
100      super("X-Client-Version", value);
101   }
102
103   /**
104    * Constructor
105    *
106    * @param value
107    *    The header value.
108    */
109   public ClientVersion(String value) {
110      this((Object)value);
111   }
112}