All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.cqengine.resultset.common.CostCachingResultSet Maven / Gradle / Ivy

Go to download

Collection Query Engine: NoSQL indexing and query engine for Java collections with ultra-low latency

There is a newer version: 3.6.0
Show newest version
/**
 * Copyright 2012-2015 Niall Gallagher
 *
 * 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.googlecode.cqengine.resultset.common;

import com.googlecode.cqengine.query.option.QueryOptions;
import com.googlecode.cqengine.resultset.ResultSet;

/**
 * Caches the merge cost and retrieval costs of a wrapped result set.
 * 

* Specifically this is to prevent * java.lang.IllegalArgumentException: Comparison method violates its general contract! * on Java 7 and later, when the collection is modified concurrently (causing merge costs to change) * while ResultSets are being sorted. *

* @author niall.gallagher */ public class CostCachingResultSet extends WrappedResultSet { volatile int cachedMergeCost = -1; volatile int cachedRetrievalCost = -1; public CostCachingResultSet(ResultSet wrappedResultSet, QueryOptions queryOptions) { super(wrappedResultSet, queryOptions); } @Override public int getRetrievalCost() { return cachedRetrievalCost != -1 ? cachedRetrievalCost : (cachedRetrievalCost = super.getRetrievalCost()); } @Override public int getMergeCost() { return cachedMergeCost != -1 ? cachedMergeCost : (cachedMergeCost = super.getMergeCost()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy