EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.data.impl]

COVERAGE SUMMARY FOR SOURCE FILE [MetaData.java]

nameclass, %method, %block, %line, %
MetaData.java100% (2/2)82%  (18/22)68%  (161/236)69%  (40.4/59)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MetaData$1100% (1/1)50%  (1/2)21%  (3/14)25%  (1/4)
convert (DataInput): MetaData 0%   (0/1)0%   (0/11)0%   (0/3)
MetaData$1 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class MetaData100% (1/1)85%  (17/20)71%  (158/222)72%  (39.4/55)
MetaData (DataInput): void 0%   (0/1)0%   (0/47)0%   (0/12)
isBefore (MetaData): boolean 0%   (0/1)0%   (0/7)0%   (0/1)
setValue (Object): Object 0%   (0/1)0%   (0/4)0%   (0/1)
getCost (): long 100% (1/1)77%  (10/13)33%  (1/3)
isValid (): boolean 100% (1/1)86%  (6/7)85%  (0.8/1)
writeData (DataOutput): void 100% (1/1)95%  (39/41)99%  (9/9)
<static initializer> 100% (1/1)100% (6/6)100% (2/2)
MetaData (long, long, int, Object, String, long, Object): void 100% (1/1)100% (32/32)100% (11/11)
getCreationTime (): long 100% (1/1)100% (3/3)100% (1/1)
getExpirationTime (): long 100% (1/1)100% (3/3)100% (1/1)
getHits (): int 100% (1/1)100% (3/3)100% (1/1)
getKey (): Object 100% (1/1)100% (3/3)100% (1/1)
getLastAccessTime (): long 100% (1/1)100% (3/3)100% (1/1)
getLastUpdateTime (): long 100% (1/1)100% (3/3)100% (1/1)
getModifiedSource (): String 100% (1/1)100% (3/3)100% (1/1)
getModifiedTimeMS (): long 100% (1/1)100% (3/3)100% (1/1)
getValue (): Object 100% (1/1)100% (3/3)100% (1/1)
getVersion (): long 100% (1/1)100% (3/3)100% (1/1)
isBefore (String, long, MetaData): boolean 100% (1/1)100% (25/25)100% (3/3)
touchRead (long): void 100% (1/1)100% (10/10)100% (3/3)

1package org.jtoolkit.essence.data.impl;
2/*
3   Copyright 2006 Peter Lawrey
4 
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8 
9       http://www.apache.org/licenses/LICENSE-2.0
10 
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16*/
17 
18import org.jetbrains.annotations.NotNull;
19import org.jtoolkit.essence.app.pojo.DataValue;
20import org.jtoolkit.essence.app.pojo.Datable;
21import org.jtoolkit.essence.app.pojo.DatableUtils;
22import org.jtoolkit.essence.concurrency.Immutable;
23import org.jtoolkit.essence.data.Mapping;
24 
25import javax.cache.CacheEntry;
26import java.io.DataInput;
27import java.io.DataOutput;
28import java.io.IOException;
29 
30/**
31 * This class represents MetaData for CacheEntry.
32 */
33@Immutable(false)
34@SuppressWarnings({"unchecked"})
35public class MetaData<K, V> extends DataValue implements CacheEntry<K, V>, Datable {
36    private final long creationTimeMS;
37    @Immutable(false)
38    private long expirationTime = Long.MAX_VALUE;
39    @Immutable(false)
40    private int hits;
41    @Immutable(false)
42    private long lastAccessTimeUS;
43    private final String modifiedSource;
44    private final long modifiedTimeMS;
45 
46    private final K key;
47    private final V value;
48 
49    public MetaData(long creationTimeMS, long expirationTime, int hits, K key, String modifiedSource, long modifiedTimeMS, V value) {
50        this.creationTimeMS = creationTimeMS;
51        this.expirationTime = expirationTime;
52        this.hits = hits;
53        this.key = key;
54        this.modifiedSource = modifiedSource;
55        this.modifiedTimeMS = modifiedTimeMS;
56        lastAccessTimeUS = modifiedTimeMS * 1000;
57        this.value = value;
58    }
59 
60    public static boolean isBefore(String source, long timeMS, MetaData metaData) {
61        if (metaData == null) return false;
62        //noinspection SimplifiableIfStatement
63        if (timeMS < metaData.modifiedTimeMS) return true;
64        return timeMS == metaData.modifiedTimeMS && metaData.modifiedSource.compareTo(source) > 0;
65    }
66 
67    public K getKey() {
68        return key;
69    }
70 
71    public V getValue() {
72        return value;
73    }
74 
75    public V setValue(V value) {
76        throw new UnsupportedOperationException();
77    }
78 
79    public long getCost() {
80        try {
81            return DatableUtils.toBytes(this).length;
82        } catch (IOException ignored) {
83            return ~0;
84        }
85    }
86 
87    public long getCreationTime() {
88        return creationTimeMS;
89    }
90 
91    public long getExpirationTime() {
92        return expirationTime;
93    }
94 
95    public int getHits() {
96        return hits;
97    }
98 
99    public void touchRead(long time) {
100        hits++;
101        lastAccessTimeUS = time;
102    }
103 
104    public long getLastAccessTime() {
105        return lastAccessTimeUS;
106    }
107 
108    public long getLastUpdateTime() {
109        return modifiedTimeMS;
110    }
111 
112    public String getModifiedSource() {
113        return modifiedSource;
114    }
115 
116    public long getModifiedTimeMS() {
117        return modifiedTimeMS;
118    }
119 
120    public long getVersion() {
121        return modifiedTimeMS;
122    }
123 
124    public boolean isValid() {
125        return value != null;
126    }
127 
128    // must define a constructor.
129    static {
130        DatableUtils.registerBuilder(MetaData.class, new Mapping<DataInput, MetaData>() {
131            public MetaData convert(DataInput in) {
132                try {
133                    return new MetaData(in);
134                } catch (IOException e) {
135                    throw new IllegalArgumentException(e);
136                }
137            }
138        });
139    }
140 
141    public MetaData(@NotNull DataInput in) throws IOException {
142        creationTimeMS = in.readLong();
143        long time = DatableUtils.readBER(in);
144        expirationTime = time == ~0 ? Long.MAX_VALUE : time;
145        hits = (int) DatableUtils.readBER(in);
146        lastAccessTimeUS = in.readLong();
147        modifiedSource = in.readUTF();
148        modifiedTimeMS = in.readLong();
149        key = (K) DatableUtils.readObject(in);
150        value = (V) DatableUtils.readObject(in);
151    }
152 
153    public void writeData(@NotNull DataOutput out) throws IOException {
154        out.writeLong(creationTimeMS);
155        DatableUtils.writeBER(out, expirationTime == Long.MAX_VALUE ? ~0 : expirationTime);
156        DatableUtils.writeBER(out, hits);
157        out.writeLong(lastAccessTimeUS);
158        out.writeUTF(modifiedSource);
159        out.writeLong(modifiedTimeMS);
160        DatableUtils.writeObject(out, key);
161        DatableUtils.writeObject(out, value);
162    }
163 
164    public boolean isBefore(MetaData md) {
165        return isBefore(modifiedSource, modifiedTimeMS, md);
166    }
167}

[all classes][org.jtoolkit.essence.data.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov