/*
 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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.
 */

package com.hazelcast.map.record;

import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.DataSerializable;

import java.io.IOException;

/**
 *
 */
public class RecordInfo implements DataSerializable {
    protected RecordStatistics statistics;
    protected long version;
    protected long evictionCriteriaNumber;
    protected long ttl;
    protected long creationTime;
    protected long lastAccessTime;
    protected long lastUpdatedTime;

    public RecordInfo() {
    }

    public RecordInfo(RecordInfo recordInfo) {
        this.statistics = recordInfo.statistics;
        this.version = recordInfo.version;
        this.evictionCriteriaNumber = recordInfo.evictionCriteriaNumber;
        this.ttl = recordInfo.ttl;
        this.creationTime = recordInfo.creationTime;
        this.lastAccessTime = recordInfo.lastAccessTime;
        this.lastUpdatedTime = recordInfo.lastUpdatedTime;
    }

    public RecordStatistics getStatistics() {
        return statistics;
    }

    public void setStatistics(RecordStatistics statistics) {
        this.statistics = statistics;
    }

    public long getVersion() {
        return version;
    }

    public void setVersion(long version) {
        this.version = version;
    }

    public long getEvictionCriteriaNumber() {
        return evictionCriteriaNumber;
    }

    public void setEvictionCriteriaNumber(long evictionCriteriaNumber) {
        this.evictionCriteriaNumber = evictionCriteriaNumber;
    }

    public long getTtl() {
        return ttl;
    }

    public void setTtl(long ttl) {
        this.ttl = ttl;
    }

    public long getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(long creationTime) {
        this.creationTime = creationTime;
    }

    public long getLastAccessTime() {
        return lastAccessTime;
    }

    public void setLastAccessTime(long lastAccessTime) {
        this.lastAccessTime = lastAccessTime;
    }

    public long getLastUpdatedTime() {
        return lastUpdatedTime;
    }

    public void setLastUpdatedTime(long lastUpdatedTime) {
        this.lastUpdatedTime = lastUpdatedTime;
    }

    @Override
    public void writeData(ObjectDataOutput out) throws IOException {
        if (statistics != null) {
            out.writeBoolean(true);
            statistics.writeData(out);
        } else {
            out.writeBoolean(false);
        }
        out.writeLong(version);
        out.writeLong(evictionCriteriaNumber);
        out.writeLong(ttl);
        out.writeLong(creationTime);
        out.writeLong(lastAccessTime);
        out.writeLong(lastUpdatedTime);

    }

    @Override
    public void readData(ObjectDataInput in) throws IOException {
        boolean statsEnabled = in.readBoolean();
        if (statsEnabled) {
            statistics = new RecordStatistics();
            statistics.readData(in);
        }
        version = in.readLong();
        evictionCriteriaNumber = in.readLong();
        ttl = in.readLong();
        creationTime = in.readLong();
        lastAccessTime = in.readLong();
        lastUpdatedTime = in.readLong();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append("RecordInfo{");
        builder.append("statistics=");
        builder.append(statistics);
        builder.append(", version=");
        builder.append(version);
        builder.append(", evictionCriteriaNumber=");
        builder.append(evictionCriteriaNumber);
        builder.append(", ttl=");
        builder.append(ttl);
        builder.append(", creationTime=");
        builder.append(creationTime);
        builder.append(", lastAccessTime=");
        builder.append(lastAccessTime);
        builder.append(", lastUpdateTime=");
        builder.append(lastUpdatedTime);
        builder.append('}');
        return builder.toString();
    }
}

@@ -833,16 +833,30 @@
 %0A%0A/**%0A *
+  Record info.
 %0A */%0Apub
@@ -1137,25 +1137,24 @@
 g lastUpdate
-d
 Time;%0A%0A    p
@@ -1557,25 +1557,24 @@
 s.lastUpdate
-d
 Time = recor
@@ -1581,33 +1581,32 @@
 dInfo.lastUpdate
-d
 Time;%0A    %7D%0A%0A   
@@ -2671,25 +2671,24 @@
 etLastUpdate
-d
 Time() %7B%0A   
@@ -2701,33 +2701,32 @@
 eturn lastUpdate
-d
 Time;%0A    %7D%0A%0A   
@@ -2747,25 +2747,24 @@
 etLastUpdate
-d
 Time(long la
@@ -2767,25 +2767,24 @@
 g lastUpdate
-d
 Time) %7B%0A    
@@ -2798,25 +2798,24 @@
 s.lastUpdate
-d
 Time = lastU
@@ -2815,25 +2815,24 @@
 = lastUpdate
-d
 Time;%0A    %7D%0A
@@ -3299,25 +3299,24 @@
 g(lastUpdate
-d
 Time);%0A%0A    
@@ -3773,25 +3773,24 @@
   lastUpdate
-d
 Time = in.re
@@ -4503,17 +4503,16 @@
 stUpdate
-d
 Time);%0A 

remove lastUpdatedTime to lastUpdateTime