~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/store/DefaultElementValueComparator.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
4
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
5
 *  you may not use this file except in compliance with the License.
26
26
 */
27
27
public class DefaultElementValueComparator implements ElementValueComparator {
28
28
 
29
 
    private final ReadWriteCopyStrategy<Element> readWriteCopyStrategy;
30
 
    private final boolean doNoCopyForRead;
 
29
    private final CacheConfiguration cacheConfiguration;
31
30
 
32
31
    /**
33
32
     * Constructor
35
34
     * @param cacheConfiguration the cache configuration
36
35
     */
37
36
    public DefaultElementValueComparator(CacheConfiguration cacheConfiguration) {
38
 
        this.readWriteCopyStrategy = cacheConfiguration.getCopyStrategy();
39
 
        // only do a copy for read before comparing if both copy on read and copy on write are enabled
40
 
        this.doNoCopyForRead = !(cacheConfiguration.isCopyOnRead() && cacheConfiguration.isCopyOnWrite());
 
37
        this.cacheConfiguration = cacheConfiguration;
41
38
    }
42
39
 
43
40
    /**
70
67
    }
71
68
 
72
69
    private Element copyForReadIfNeeded(Element element) {
73
 
        if (readWriteCopyStrategy == null || doNoCopyForRead) {
 
70
        ReadWriteCopyStrategy<Element> readWriteCopyStrategy = cacheConfiguration.getCopyStrategy();
 
71
        if (readWriteCopyStrategy == null || skipCopyForRead()) {
74
72
            return element;
75
73
        }
76
74
        return readWriteCopyStrategy.copyForRead(element);
77
75
    }
78
76
 
 
77
    private boolean skipCopyForRead() {
 
78
        // only do a copy for read before comparing if both copy on read and copy on write are enabled
 
79
        return !(cacheConfiguration.isCopyOnRead() && cacheConfiguration.isCopyOnWrite());
 
80
    }
 
81
 
79
82
}