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

org.jpmml.manager.EntityUtil Maven / Gradle / Ivy

There is a newer version: 1.1.20
Show newest version
/*
 * Copyright (c) 2013 University of Tartu
 */
package org.jpmml.manager;

import java.util.*;

import org.dmg.pmml.*;

import com.google.common.collect.*;

public class EntityUtil {

	private EntityUtil(){
	}

	static
	public  void put(E entity, BiMap map){
		String id = entity.getId();
		if(id == null || map.containsKey(id)){
			throw new InvalidFeatureException(entity);
		}

		map.put(id, entity);
	}

	static
	public  void putAll(List entities, BiMap map){

		for(int i = 0, j = 1; i < entities.size(); i++, j++){
			E entity = entities.get(i);

			String id = entity.getId();

			// Generate an implicit identifier (ie. 1-based index) if the explicit identifier is missing
			if(id == null){
				id = String.valueOf(j);
			} // End if

			if(map.containsKey(id)){
				throw new InvalidFeatureException(entity);
			}

			map.put(id, entity);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy