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 java.util.function.*;
016
017import org.apache.juneau.http.annotation.*;
018
019/**
020 * Represents a parsed <l>ETag</l> HTTP response header.
021 *
022 * <p>
023 * An identifier for a specific version of a resource, often a message digest.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode w800'>
027 *    ETag: "737060cd8c284d8af7ad3082f209582d"
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The ETag response-header field provides the current value of the entity tag for the requested variant.
033 * The headers used with entity tags are described in sections 14.24, 14.26 and 14.44.
034 * The entity tag MAY be used for comparison with other entities from the same resource (see section 13.3.3).
035 *
036 * <p class='bcode w800'>
037 *    ETag = "ETag" ":" entity-tag
038 * </p>
039 *
040 * <p>
041 * Examples:
042 * <p class='bcode w800'>
043 *    ETag: "xyzzy"
044 *    ETag: W/"xyzzy"
045 *    ETag: ""
046 * </p>
047 *
048 * <ul class='seealso'>
049 *    <li class='extlink'>{@doc ExtRFC2616}
050 * </ul>
051 */
052@Header("ETag")
053public class ETag extends BasicEntityTagHeader {
054
055   private static final long serialVersionUID = 1L;
056
057   /**
058    * Convenience creator.
059    *
060    * @param value
061    *    The header value.
062    *    <br>Can be any of the following:
063    *    <ul>
064    *       <li>{@link String}
065    *       <li>Anything else - Converted to <c>String</c> then parsed.
066    *    </ul>
067    * @return A new {@link ETag} object.
068    */
069   public static ETag of(Object value) {
070      if (value == null)
071         return null;
072      return new ETag(value);
073   }
074
075   /**
076    * Convenience creator using supplier.
077    *
078    * <p>
079    * Header value is re-evaluated on each call to {@link #getValue()}.
080    *
081    * @param value
082    *    The header value supplier.
083    *    <br>Can be any of the following:
084    *    <ul>
085    *       <li>{@link String}
086    *       <li>Anything else - Converted to <c>String</c> then parsed.
087    *    </ul>
088    * @return A new {@link ETag} object.
089    */
090   public static ETag of(Supplier<?> value) {
091      if (value == null)
092         return null;
093      return new ETag(value);
094   }
095
096   /**
097    * Constructor.
098    *
099    * @param value
100    *    The header value.
101    *    <br>Can be any of the following:
102    *    <ul>
103    *       <li>{@link String}
104    *       <li>Anything else - Converted to <c>String</c> then parsed.
105    *       <li>A {@link Supplier} of anything on this list.
106    *    </ul>
107    */
108   public ETag(Object value) {
109      super("ETag", value);
110   }
111
112   /**
113    * Constructor
114    *
115    * @param value
116    *    The header value.
117    */
118   public ETag(String value) {
119      this((Object)value);
120   }
121}