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

org.jpmml.model.visitors.NumberInterner Maven / Gradle / Ivy

/*
 * Copyright (c) 2016 Villu Ruusmann
 */
package org.jpmml.model.visitors;

import java.util.concurrent.ConcurrentMap;

abstract
public class NumberInterner extends Interner {

	private ConcurrentMap cache = null;


	protected NumberInterner(Class type, ConcurrentMap cache){
		super(type);

		setCache(cache);
	}

	abstract
	public V canonicalize(V value);

	@Override
	public V intern(V value){
		ConcurrentMap cache = getCache();

		if(value == null){
			return null;
		}

		V canonicalValue = cache.get(value);
		if(canonicalValue == null){
			canonicalValue = canonicalize(value);

			cache.putIfAbsent(value, canonicalValue);
		}

		return canonicalValue;
	}

	public ConcurrentMap getCache(){
		return this.cache;
	}

	private void setCache(ConcurrentMap cache){
		this.cache = cache;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy