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

org.semanticweb.elk.reasoner.saturation.MapSaturationState Maven / Gradle / Ivy

There is a newer version: 0.29.0
Show newest version
package org.semanticweb.elk.reasoner.saturation;

/*
 * #%L
 * ELK Reasoner
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2014 Department of Computer Science, University of Oxford
 * %%
 * 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.
 * #L%
 */

import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;

import org.semanticweb.elk.reasoner.indexing.model.IndexedClassExpression;
import org.semanticweb.elk.reasoner.indexing.model.IndexedContextRoot;
import org.semanticweb.elk.reasoner.indexing.model.OntologyIndex;

/**
 * A {@link SaturationState} backed by a map from {@link IndexedClassExpression}
 * s to {@link ExtendedContext}s
 * 
 * @author "Yevgeny Kazakov"
 * 
 * @param 
 *            the type of contexts maintained by this {@link MapSaturationState}
 */
public class MapSaturationState
		extends AbstractSaturationState {

	private final ConcurrentHashMap contextAssignment_;

	public MapSaturationState(OntologyIndex index, ContextFactory factory,
			int expectedSize) {
		super(index, factory);
		this.contextAssignment_ = new ConcurrentHashMap(
				expectedSize);
	}

	public MapSaturationState(OntologyIndex index, ContextFactory factory) {
		super(index, factory);
		this.contextAssignment_ = new ConcurrentHashMap(
				index.getClassExpressions().size());
	}

	@Override
	public Collection getContexts() {
		return contextAssignment_.values();
	}

	@Override
	public EC getContext(IndexedContextRoot root) {
		return contextAssignment_.get(root);
	}

	@Override
	void resetContexts() {
		if (!contextAssignment_.isEmpty()) {
			contextAssignment_.clear();
			notifyContextsClear();
		}
	}

	@Override
	EC setIfAbsent(EC context) {
		EC previous = contextAssignment_.putIfAbsent(context.getRoot(),
				context);
		if (previous == null) {
			notifyContextAddition(context);
		}
		return previous;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy