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

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

There is a newer version: 1.6.6
Show newest version
/*
 * Copyright (c) 2016 Villu Ruusmann
 */
package org.jpmml.model.visitors;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.dmg.pmml.IntSparseArray;
import org.dmg.pmml.RealSparseArray;
import org.dmg.pmml.VisitorAction;

/**
 * 

* A Visitor that interns {@link Integer} attribute values. *

*/ public class IntegerInterner extends NumberInterner { public IntegerInterner(){ super(Integer.class, IntegerInterner.CACHE_PROVIDER.get()); } @Override public Integer canonicalize(Integer value){ return Integer.valueOf(value.intValue()); } @Override public VisitorAction visit(IntSparseArray intSparseArray){ if(intSparseArray.hasEntries()){ internAll(intSparseArray.getEntries()); } // End if if(intSparseArray.hasIndices()){ internAll(intSparseArray.getIndices()); } return super.visit(intSparseArray); } @Override public VisitorAction visit(RealSparseArray realSparseArray){ if(realSparseArray.hasIndices()){ internAll(realSparseArray.getIndices()); } return super.visit(realSparseArray); } static public void clear(){ IntegerInterner.cache.clear(); } private static final ConcurrentMap cache = new ConcurrentHashMap<>(); public static final ThreadLocal> CACHE_PROVIDER = new ThreadLocal>(){ @Override public ConcurrentMap initialValue(){ return IntegerInterner.cache; } }; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy