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>Age</l> HTTP response header.
021 *
022 * <p>
023 * The age the object has been in a proxy cache in seconds.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode'>
027 *    Age: 12
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The Age response-header field conveys the sender's estimate of the amount of time since the response (or its
033 * revalidation) was generated at the origin server.
034 * A cached response is "fresh" if its age does not exceed its freshness lifetime.
035 * Age values are calculated as specified in section 13.2.3.
036 *
037 * <p class='bcode'>
038 *    Age = "Age" ":" age-value
039 *    age-value = delta-seconds
040 * </p>
041 *
042 * <p>
043 * Age values are non-negative decimal integers, representing time in seconds.
044 *
045 * <p>
046 * If a cache receives a value larger than the largest positive integer it can represent, or if any of its age
047 * calculations overflows, it MUST transmit an Age header with a value of 2147483648 (2^31).
048 *
049 * <p>
050 * An HTTP/1.1 server that includes a cache MUST include an Age header field in every response generated from its own
051 * cache.
052 *
053 * <p>
054 * Caches SHOULD use an arithmetic type of at least 31 bits of range.
055 *
056 * <h5 class='section'>See Also:</h5><ul>
057 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
058 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
059 * </ul>
060 *
061 * @serial exclude
062 */
063@Header("Age")
064public class Age extends BasicIntegerHeader {
065
066   //-----------------------------------------------------------------------------------------------------------------
067   // Static
068   //-----------------------------------------------------------------------------------------------------------------
069
070   private static final long serialVersionUID = 1L;
071   private static final String NAME = "Age";
072
073   /**
074    * Static creator.
075    *
076    * @param value
077    *    The header value.
078    *    <br>Must be parsable using {@link Integer#parseInt(String)}.
079    *    <br>Can be <jk>null</jk>.
080    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
081    */
082   public static Age of(String value) {
083      return value == null ? null : new Age(value);
084   }
085
086   /**
087    * Static creator.
088    *
089    * @param value
090    *    The header value.
091    *    <br>Can be <jk>null</jk>.
092    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
093    */
094   public static Age of(Integer value) {
095      return value == null ? null : new Age(value);
096   }
097
098   /**
099    * Static creator with delayed value.
100    *
101    * <p>
102    * Header value is re-evaluated on each call to {@link #getValue()}.
103    *
104    * @param value
105    *    The supplier of the header value.
106    *    <br>Can be <jk>null</jk>.
107    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
108    */
109   public static Age of(Supplier<Integer> value) {
110      return value == null ? null : new Age(value);
111   }
112
113   //-----------------------------------------------------------------------------------------------------------------
114   // Instance
115   //-----------------------------------------------------------------------------------------------------------------
116
117   /**
118    * Constructor.
119    *
120    * @param value
121    *    The header value.
122    *    <br>Must be parsable using {@link Integer#parseInt(String)}.
123    *    <br>Can be <jk>null</jk>.
124    */
125   public Age(String value) {
126      super(NAME, value);
127   }
128
129   /**
130    * Constructor.
131    *
132    * @param value
133    *    The header value.
134    *    <br>Can be <jk>null</jk>.
135    */
136   public Age(Integer value) {
137      super(NAME, value);
138   }
139
140   /**
141    * Constructor with delayed value.
142    *
143    * <p>
144    * Header value is re-evaluated on each call to {@link #getValue()}.
145    *
146    * @param value
147    *    The supplier of the header value.
148    *    <br>Can be <jk>null</jk>.
149    */
150   public Age(Supplier<Integer> value) {
151      super(NAME, value);
152   }
153}