001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.http.header;
018
019import java.util.function.*;
020
021import org.apache.juneau.http.annotation.*;
022
023/**
024 * Represents a parsed <l>Age</l> HTTP response header.
025 *
026 * <p>
027 * The age the object has been in a proxy cache in seconds.
028 *
029 * <h5 class='figure'>Example</h5>
030 * <p class='bcode'>
031 *    Age: 12
032 * </p>
033 *
034 * <h5 class='topic'>RFC2616 Specification</h5>
035 *
036 * The Age response-header field conveys the sender's estimate of the amount of time since the response (or its
037 * revalidation) was generated at the origin server.
038 * A cached response is "fresh" if its age does not exceed its freshness lifetime.
039 * Age values are calculated as specified in section 13.2.3.
040 *
041 * <p class='bcode'>
042 *    Age = "Age" ":" age-value
043 *    age-value = delta-seconds
044 * </p>
045 *
046 * <p>
047 * Age values are non-negative decimal integers, representing time in seconds.
048 *
049 * <p>
050 * If a cache receives a value larger than the largest positive integer it can represent, or if any of its age
051 * calculations overflows, it MUST transmit an Age header with a value of 2147483648 (2^31).
052 *
053 * <p>
054 * An HTTP/1.1 server that includes a cache MUST include an Age header field in every response generated from its own
055 * cache.
056 *
057 * <p>
058 * Caches SHOULD use an arithmetic type of at least 31 bits of range.
059 *
060 * <h5 class='section'>See Also:</h5><ul>
061 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
062 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
063 * </ul>
064 *
065 * @serial exclude
066 */
067@Header("Age")
068public class Age extends BasicIntegerHeader {
069   private static final long serialVersionUID = 1L;
070   private static final String NAME = "Age";
071
072   /**
073    * Static creator.
074    *
075    * @param value
076    *    The header value.
077    *    <br>Can be <jk>null</jk>.
078    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
079    */
080   public static Age of(Integer value) {
081      return value == null ? null : new Age(value);
082   }
083
084   /**
085    * Static creator.
086    *
087    * @param value
088    *    The header value.
089    *    <br>Must be parsable using {@link Integer#parseInt(String)}.
090    *    <br>Can be <jk>null</jk>.
091    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
092    */
093   public static Age of(String value) {
094      return value == null ? null : new Age(value);
095   }
096
097   /**
098    * Static creator with delayed value.
099    *
100    * <p>
101    * Header value is re-evaluated on each call to {@link #getValue()}.
102    *
103    * @param value
104    *    The supplier of the header value.
105    *    <br>Can be <jk>null</jk>.
106    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
107    */
108   public static Age of(Supplier<Integer> value) {
109      return value == null ? null : new Age(value);
110   }
111
112   /**
113    * Constructor.
114    *
115    * @param value
116    *    The header value.
117    *    <br>Can be <jk>null</jk>.
118    */
119   public Age(Integer value) {
120      super(NAME, value);
121   }
122
123   /**
124    * Constructor.
125    *
126    * @param value
127    *    The header value.
128    *    <br>Must be parsable using {@link Integer#parseInt(String)}.
129    *    <br>Can be <jk>null</jk>.
130    */
131   public Age(String value) {
132      super(NAME, value);
133   }
134
135   /**
136    * Constructor with delayed value.
137    *
138    * <p>
139    * Header value is re-evaluated on each call to {@link #getValue()}.
140    *
141    * @param value
142    *    The supplier of the header value.
143    *    <br>Can be <jk>null</jk>.
144    */
145   public Age(Supplier<Integer> value) {
146      super(NAME, value);
147   }
148}