Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * The contents of this file are subject to the terms
   * of the Common Development and Distribution License
   * (the "License").  You may not use this file except
   * in compliance with the License.
   * 
   * You can obtain a copy of the license at
   * http://www.opensource.org/licenses/cddl1.php
   * See the License for the specific language governing
  * permissions and limitations under the License.
  */
 
 /*
  * CacheControl.java
  *
  * Created on March 5, 2007, 3:36 PM
  */
 
 package javax.ws.rs.core;
 
 import java.util.List;
 import java.util.Map;
An abstraction for the value of a HTTP Cache-Control response header.

See also:
HTTP/1.1 section 14.9
 
 public class CacheControl {
     private boolean _private;
     private List<StringprivateFields;
     private boolean noCache;
     private List<StringnoCacheFields;
     private boolean noStore;
     private boolean noTransform;
     private boolean mustRevalidate;
     private boolean proxyRevalidate;
     private int maxAge = -1;
     private int sMaxAge = -1;
     private Map<StringStringcacheExtension;
     
     private static final HeaderDelegate<CacheControldelegate = 
             RuntimeDelegate.getInstance().createHeaderDelegate(CacheControl.class);

    
    
Create a new instance of CacheControl. The new instance will have the following default settings:
  • private = false
  • noCache = false
  • noStore = false
  • noTransform = true
  • mustRevalidate = false
  • proxyRevalidate = false
  • An empty list of private fields
  • An empty list of no-cache fields
  • An empty map of cache extensions
 
     public CacheControl() {
          = false;
          = false;
          = false;
          = true;
          = false;
          = false;
     }

    
Creates a new instance of CacheControl by parsing the supplied string.

Parameters:
value the cache control string
Returns:
the newly created CacheControl
Throws:
java.lang.IllegalArgumentException if the supplied string cannot be parsed or is null
 
     public static CacheControl valueOf(String valuethrows IllegalArgumentException {
         return .fromString(value);
     }
    
    
Corresponds to the must-revalidate cache control directive.

Returns:
true if the must-revalidate cache control directive will be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.4
 
     public boolean isMustRevalidate() {
         return ;
     }

    
Corresponds to the must-revalidate cache control directive.

Parameters:
mustRevalidate true if the must-revalidate cache control directive should be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.4
    public void setMustRevalidate(boolean mustRevalidate) {
        this. = mustRevalidate;
    }

    
Corresponds to the proxy-revalidate cache control directive.

Returns:
true if the proxy-revalidate cache control directive will be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.4
    public boolean isProxyRevalidate() {
        return ;
    }

    
Corresponds to the must-revalidate cache control directive.

Parameters:
proxyRevalidate true if the proxy-revalidate cache control directive should be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.4
    public void setProxyRevalidate(boolean proxyRevalidate) {
        this. = proxyRevalidate;
    }

    
Corresponds to the max-age cache control directive.

Returns:
the value of the max-age cache control directive, -1 if the directive is disabled.
See also:
HTTP/1.1 section 14.9.3
    public int getMaxAge() {
        return ;
    }

    
Corresponds to the max-age cache control directive.

Parameters:
maxAge the value of the max-age cache control directive, a value of -1 will disable the directive.
See also:
HTTP/1.1 section 14.9.3
    public void setMaxAge(int maxAge) {
        this. = maxAge;
    }

    
Corresponds to the s-maxage cache control directive.

Returns:
the value of the s-maxage cache control directive, -1 if the directive is disabled.
See also:
HTTP/1.1 section 14.9.3
    public int getSMaxAge() {
        return ;
    }

    
Corresponds to the s-maxage cache control directive.

Parameters:
sMaxAge the value of the s-maxage cache control directive, a value of -1 will disable the directive.
See also:
HTTP/1.1 section 14.9.3
    public void setSMaxAge(int sMaxAge) {
        this. = sMaxAge;
    }

    
Corresponds to the value of the no-cache cache control directive.

Returns:
a mutable list of field-names that will form the value of the no-cache cache control directive. An empty list results in a bare no-cache directive.
See also:
isNoCache()
setNoCache(boolean)
HTTP/1.1 section 14.9.1
    public List<StringgetNoCacheFields() {
        if ( == null)
             = new ArrayList<String>();
        return ;
    }

    
Corresponds to the no-cache cache control directive.

Parameters:
noCache true if the no-cache cache control directive should be included in the response, false otherwise.
See also:
getNoCacheFields()
HTTP/1.1 section 14.9.1
    public void setNoCache(boolean noCache) {
        this. = noCache;
    }

    
Corresponds to the no-cache cache control directive.

Returns:
true if the no-cache cache control directive will be included in the response, false otherwise.
See also:
getNoCacheFields()
HTTP/1.1 section 14.9.1
    public boolean isNoCache() {
        return ;
    }

    
Corresponds to the private cache control directive.

Returns:
true if the private cache control directive will be included in the response, false otherwise.
See also:
getPrivateFields()
HTTP/1.1 section 14.9.1
    public boolean isPrivate() {
        return ;
    }

    
Corresponds to the value of the private cache control directive.

Returns:
a mutable list of field-names that will form the value of the private cache control directive. An empty list results in a bare no-cache directive.
See also:
isPrivate()
setPrivate(boolean)
HTTP/1.1 section 14.9.1
    public List<StringgetPrivateFields() {
        if ( == null)
             = new ArrayList<String>();
        return ;
    }

    
Corresponds to the private cache control directive.

Parameters:
_private true if the private cache control directive should be included in the response, false otherwise.
See also:
getPrivateFields()
HTTP/1.1 section 14.9.1
    public void setPrivate(boolean _private) {
        this. = _private;
    }

    
Corresponds to the no-transform cache control directive.

Returns:
true if the no-transform cache control directive will be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.5
    public boolean isNoTransform() {
        return ;
    }

    
Corresponds to the no-transform cache control directive.

Parameters:
noTransform true if the no-transform cache control directive should be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.5
    public void setNoTransform(boolean noTransform) {
        this. = noTransform;
    }

    
Corresponds to the no-store cache control directive.

Returns:
true if the no-store cache control directive will be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.2
    public boolean isNoStore() {
        return ;
    }

    
Corresponds to the no-store cache control directive.

Parameters:
noStore true if the no-store cache control directive should be included in the response, false otherwise.
See also:
HTTP/1.1 section 14.9.2
    public void setNoStore(boolean noStore) {
        this. = noStore;
    }

    
Corresponds to a set of extension cache control directives.

Returns:
a mutable map of cache control extension names and their values. If a key has a null value, it will appear as a bare directive. If a key has a value that contains no whitespace then the directive will appear as a simple name=value pair. If a key has a value that contains whitespace then the directive will appear as a quoted name="value" pair.
See also:
HTTP/1.1 section 14.9.6
    public Map<StringStringgetCacheExtension() {
        if ( == null)
             = new HashMap<StringString>();
        return ;
    }

    
Convert the cache control to a string suitable for use as the value of the corresponding HTTP header.

Returns:
a stringified cache control
    @Override
    public String toString() {
        return .toString(this);
    }

    
Generate hash code from cache control properties.

Returns:
the hashCode
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + (this. ? 1 : 0);
        hash = 41 * hash + (this. != null ? this..hashCode() : 0);
        hash = 41 * hash + (this. ? 1 : 0);
        hash = 41 * hash + (this. != null ? this..hashCode() : 0);
        hash = 41 * hash + (this. ? 1 : 0);
        hash = 41 * hash + (this. ? 1 : 0);
        hash = 41 * hash + (this. ? 1 : 0);
        hash = 41 * hash + (this. ? 1 : 0);
        hash = 41 * hash + this.;
        hash = 41 * hash + this.;
        hash = 41 * hash + (this. != null ? this..hashCode() : 0);
        return hash;
    }

    
Compares obj to this cache control to see if they are the same considering all property values.

Parameters:
obj the object to compare to
Returns:
true if the two cache controls are the same, false otherwise.
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CacheControl other = (CacheControlobj;
        if (this. != other._private) {
            return false;
        }
        if (this. != other.privateFields && (this. == null || !this..equals(other.privateFields))) {
            return false;
        }
        if (this. != other.noCache) {
            return false;
        }
        if (this. != other.noCacheFields && (this. == null || !this..equals(other.noCacheFields))) {
            return false;
        }
        if (this. != other.noStore) {
            return false;
        }
        if (this. != other.noTransform) {
            return false;
        }
        if (this. != other.mustRevalidate) {
            return false;
        }
        if (this. != other.proxyRevalidate) {
            return false;
        }
        if (this. != other.maxAge) {
            return false;
        }
        if (this. != other.sMaxAge) {
            return false;
        }
        if (this. != other.cacheExtension && (this. == null || !this..equals(other.cacheExtension))) {
            return false;
        }
        return true;
    }
    
New to GrepCode? Check out our FAQ X