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'>
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'>
037 *    ETag = "ETag" ":" entity-tag
038 * </p>
039 *
040 * <p>
041 * Examples:
042 * <p class='bcode'>
043 *    ETag: "xyzzy"
044 *    ETag: W/"xyzzy"
045 *    ETag: ""
046 * </p>
047 *
048 * <h5 class='section'>See Also:</h5><ul>
049 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
050 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
051 * </ul>
052 *
053 * @serial exclude
054 */
055@Header("ETag")
056public class ETag extends BasicEntityTagHeader {
057
058   //-----------------------------------------------------------------------------------------------------------------
059   // Static
060   //-----------------------------------------------------------------------------------------------------------------
061
062   private static final long serialVersionUID = 1L;
063   private static final String NAME = "ETag";
064
065   /**
066    * Static creator.
067    *
068    * @param value
069    *    The header value.
070    *    <br>Must be an entity tag value (e.g. <js>"\"xyzzy\""</js>).
071    *    <br>Can be <jk>null</jk>.
072    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
073    */
074   public static ETag of(String value) {
075      return value == null ? null : new ETag(value);
076   }
077
078   /**
079    * Static creator.
080    *
081    * @param value
082    *    The header value.
083    *    <br>Can be <jk>null</jk>.
084    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
085    */
086   public static ETag of(EntityTag value) {
087      return value == null ? null : new ETag(value);
088   }
089
090   /**
091    * Static creator with delayed value.
092    *
093    * <p>
094    * Header value is re-evaluated on each call to {@link #getValue()}.
095    *
096    * @param value
097    *    The supplier of the header value.
098    *    <br>Can be <jk>null</jk>.
099    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
100    */
101   public static ETag of(Supplier<EntityTag> value) {
102      return value == null ? null : new ETag(value);
103   }
104
105   //-----------------------------------------------------------------------------------------------------------------
106   // Static
107   //-----------------------------------------------------------------------------------------------------------------
108
109   /**
110    * Constructor.
111    *
112    * @param value
113    *    The header value.
114    *    <br>Must be an entity tag value (e.g. <js>"\"xyzzy\""</js>).
115    *    <br>Can be <jk>null</jk>.
116    */
117   public ETag(String value) {
118      super(NAME, value);
119   }
120
121   /**
122    * Constructor.
123    *
124    * @param value
125    *    The header value.
126    *    <br>Can be <jk>null</jk>.
127    */
128   public ETag(EntityTag value) {
129      super(NAME, value);
130   }
131
132   /**
133    * Constructor with delayed value.
134    *
135    * <p>
136    * Header value is re-evaluated on each call to {@link #getValue()}.
137    *
138    * @param value
139    *    The supplier of the header value.
140    *    <br>Can be <jk>null</jk>.
141    */
142   public ETag(Supplier<EntityTag> value) {
143      super(NAME, value);
144   }
145}