//# 0 errors, 71 messages
//#
/*
    //#ExpiringCacheEntry.java:1:1: class: org.apache.roller.weblogger.util.cache.ExpiringCacheEntry
    //#ExpiringCacheEntry.java:1:1: method: org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.util.cache;

import java.io.Serializable;


/**
 * A cache entry that expires.
 *
 * We use this class to wrap objects being cached and associate a timestamp
 * and timeout period with them so we can know when they expire.
 */
public class ExpiringCacheEntry implements Serializable {
    
    private Object value;
    private long timeCached = -1;
    private long timeout = 0;
    
    
    public ExpiringCacheEntry(Object value, long timeout) {
    //#ExpiringCacheEntry.java:37: method: void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)
    //#input(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this
    //#input(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): timeout
    //#input(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): value
    //#output(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this.timeCached
    //#output(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this.timeout
    //#output(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this.value
    //#post(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): init'ed(this.timeCached)
    //#post(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this.timeout == One-of{0, timeout}
    //#post(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this.timeout >= 0
    //#post(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): this.value == value
    //#post(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): init'ed(this.value)
    //#test_vector(void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)): timeout: {-9_223_372_036_854_775_808..0}, {1..18_446_744_073_709_551_615}
        this.value = value;
        
        // make sure that we don't support negative values
        if(timeout > 0) {
            this.timeout = timeout;
        }
        
        this.timeCached = System.currentTimeMillis();
    }
    //#ExpiringCacheEntry.java:46: end of method: void org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.org.apache.roller.weblogger.util.cache.ExpiringCacheEntry(Object, long)
    
    
    public long getTimeCached() {
        return this.timeCached;
    //#ExpiringCacheEntry.java:50: method: long org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.getTimeCached()
    //#input(long getTimeCached()): this
    //#input(long getTimeCached()): this.timeCached
    //#output(long getTimeCached()): return_value
    //#pre[2] (long getTimeCached()): init'ed(this.timeCached)
    //#post(long getTimeCached()): return_value == this.timeCached
    //#post(long getTimeCached()): init'ed(return_value)
    //#ExpiringCacheEntry.java:50: end of method: long org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.getTimeCached()
    }
    
    
    public long getTimeout() {
        return this.timeout;
    //#ExpiringCacheEntry.java:55: method: long org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.getTimeout()
    //#input(long getTimeout()): this
    //#input(long getTimeout()): this.timeout
    //#output(long getTimeout()): return_value
    //#pre[2] (long getTimeout()): init'ed(this.timeout)
    //#post(long getTimeout()): return_value == this.timeout
    //#post(long getTimeout()): init'ed(return_value)
    //#ExpiringCacheEntry.java:55: end of method: long org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.getTimeout()
    }
    
    
    /**
     * Retrieve the value of this cache entry.
     *
     * If the value has expired then we return null.
     */
    public Object getValue() {
        if(this.hasExpired()) {
    //#ExpiringCacheEntry.java:65: method: Object org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.getValue()
    //#input(Object getValue()): __Descendant_Table[org/apache/roller/weblogger/util/cache/ExpiringCacheEntry]
    //#input(Object getValue()): __Descendant_Table[others]
    //#input(Object getValue()): __Dispatch_Table.hasExpired()Z
    //#input(Object getValue()): this
    //#input(Object getValue()): this.__Tag
    //#input(Object getValue()): this.timeCached
    //#input(Object getValue()): this.timeout
    //#input(Object getValue()): this.value
    //#output(Object getValue()): return_value
    //#pre[2] (Object getValue()): this.__Tag == org/apache/roller/weblogger/util/cache/ExpiringCacheEntry
    //#pre[3] (Object getValue()): init'ed(this.timeCached)
    //#pre[5] (Object getValue()): init'ed(this.timeout)
    //#pre[6] (Object getValue()): (soft) init'ed(this.value)
    //#post(Object getValue()): return_value == One-of{null, this.value}
    //#post(Object getValue()): (soft) init'ed(return_value)
    //#unanalyzed(Object getValue()): Effects-of-calling:java.lang.System:currentTimeMillis
            return null;
        } else {
            return this.value;
    //#ExpiringCacheEntry.java:68: end of method: Object org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.getValue()
        }
    }
    
    
    /**
     * Determine if this cache entry has expired.
     */
    public boolean hasExpired() {
        
        long now = System.currentTimeMillis();
    //#ExpiringCacheEntry.java:78: method: bool org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.hasExpired()
    //#input(bool hasExpired()): this
    //#input(bool hasExpired()): this.timeCached
    //#input(bool hasExpired()): this.timeout
    //#output(bool hasExpired()): return_value
    //#pre[2] (bool hasExpired()): init'ed(this.timeCached)
    //#pre[4] (bool hasExpired()): init'ed(this.timeout)
    //#post(bool hasExpired()): init'ed(return_value)
        
        return ((this.timeCached + this.timeout) < now);
    //#ExpiringCacheEntry.java:80: end of method: bool org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.hasExpired()
    }
    
}
    //#output(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Descendant_Table[org/apache/roller/weblogger/util/cache/ExpiringCacheEntry]
    //#output(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.getTimeCached()J
    //#output(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.getTimeout()J
    //#output(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.getValue()Ljava/lang/Object;
    //#output(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.hasExpired()Z
    //#post(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Descendant_Table[org/apache/roller/weblogger/util/cache/ExpiringCacheEntry] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.getTimeCached()J == &getTimeCached
    //#post(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.getTimeout()J == &getTimeout
    //#post(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.getValue()Ljava/lang/Object; == &getValue
    //#post(org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init): __Dispatch_Table.hasExpired()Z == &hasExpired
    //#ExpiringCacheEntry.java:: end of method: org.apache.roller.weblogger.util.cache.ExpiringCacheEntry.org.apache.roller.weblogger.util.cache.ExpiringCacheEntry__static_init
    //#ExpiringCacheEntry.java:: end of class: org.apache.roller.weblogger.util.cache.ExpiringCacheEntry
