<commit_before>package org.eclipse.scanning.api.database;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 
 * This class is a composite of serveral beans which
 * should be upserted/updated/inserted using the 
 * database service. It is used to create single requests
 * which do multiple actions. This allows queues of 
 * composite operations to be created with each one being
 * a single action in terms of what the ISPyB Client submits
 * to the database.
 * 
 * @author <NAME>
 *
 */
public class CompositeBean {

	private Map<Operation, Collection<Object>> data;
    
    public CompositeBean() {
    	data = new LinkedHashMap<>(); // Order matters in the collection of items
    }
    
    public CompositeBean(Operation type, Object... beans) {
    	this();
    	assertType(type);
     	data.put(type, new ArrayList<>(Arrays.asList(beans)));
    }
   
    private void assertType(Operation type) {
       	if (!Operation.ends().contains(type)) {
       		throw new IllegalArgumentException("Each operation set added to the composite must not be a composite. Allowed types are "+Operation.ends());
       	}
	}

	public void add(Operation type, Object bean) {
    	
    	assertType(type);
    	Collection<Object> beans = data.get(type);
    	if (beans==null) {
    		beans = new ArrayList<>(7); // Order matters in the collection of items
    		data.put(type, beans);
    	}
    	beans.add(bean);
    }
    
    public Collection<Object> set(Operation type, Object... beans) {
       	assertType(type);
    	return data.put(type, new ArrayList<>(Arrays.asList(beans)));
    }

	public Collection<?> get(Operation type) {
		return data.getOrDefault(type, Collections.emptyList());
	}
	

	public Map<Operation, Collection<Object>> getData() {
		return data;<commit_msg>Removed <?> which sonarqube dislikes so.<commit_after>package org.eclipse.scanning.api.database;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 
 * This class is a composite of serveral beans which
 * should be upserted/updated/inserted using the 
 * database service. It is used to create single requests
 * which do multiple actions. This allows queues of 
 * composite operations to be created with each one being
 * a single action in terms of what the ISPyB Client submits
 * to the database.
 * 
 * @author <NAME>
 *
 */
public class CompositeBean {

	/**
	 * IMPORTANT: Do not use generics here, the data
	 * is almost always heterogeneous.
	 */
	private Map<Operation, Collection<Object>> data;
    
    public CompositeBean() {
    	data = new LinkedHashMap<>(); // Order matters in the collection of items
    }
    
    public CompositeBean(Operation type, Object... beans) {
    	this();
    	assertType(type);
     	data.put(type, new ArrayList<>(Arrays.asList(beans)));
    }
   
    private void assertType(Operation type) {
       	if (!Operation.ends().contains(type)) {
       		throw new IllegalArgumentException("Each operation set added to the composite must not be a composite. Allowed types are "+Operation.ends());
       	}
	}

	public void add(Operation type, Object bean) {
    	
    	assertType(type);
    	Collection<Object> beans = data.get(type);
    	if (beans==null) {
    		beans = new ArrayList<>(7); // Order matters in the collection of items
    		data.put(type, beans);
    	}
    	beans.add(bean);
    }
    
    public Collection<Object> set(Operation type, Object... beans) {
       	assertType(type);
    	return data.put(type, new ArrayList<>(Arrays.asList(beans)));
    }

	public Collection<Object> get(Operation type) {
		return data.getOrDefault(type, Collections.emptyList());
	}
	

	public Map<Operation, Collection<Object>> getData() {
		return data;
{'fraction_non_alphanumeric': 0.10865139949109415, 'fraction_numerical': 0.0005089058524173028, 'mean_word_length': 3.3055859802847753, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7395196', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1127, 'n_words': 359}