<commit_before>package metricapp.service.repository;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import javax.annotation.Nonnull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;

import metricapp.entity.Element;
import metricapp.entity.Entity;
import metricapp.entity.State;
import metricapp.entity.external.PointerBus;
import metricapp.entity.external.RichPointerBus;
import metricapp.entity.measurementGoal.MeasurementGoal;
import metricapp.entity.metric.Metric;
import metricapp.entity.question.Question;
import metricapp.exception.BadInputException;
import metricapp.exception.BusException;
import metricapp.service.spec.repository.BusApprovedElementInterface;
import metricapp.service.spec.repository.BusInterface;
import metricapp.utility.JacksonMapper;

/**
 * This repository offers method to send and grab our Elements to and from BUS.
 * <p>
 * Supported items:
 * <ul>
 * <li>Metric
 * <li>Question
 * <li>MeasurementGoal
 * </ul>
 * 
 * Bus Storage contains only Approved Elements, and only Approved Elements can
 * be sent to Bus.
 *
 */
@Service
public class BusApprovedElementRepository implements BusApprovedElementInterface {

	@Autowired
	private BusInterface busRepository;

	@Autowired
	private JacksonMapper mapper;
	
	@Autowired
	static private BusApprovedElementRepository instance;
	
	
	/**
	 * Spring implementation of Singleton Pattern
	 */
	public BusApprovedElementRepository(){
		instance = this;
	}
	
	public static BusApprovedElementRepository getInstance(){
		return instance;
	}

	/**
	 * This function send an approved Element like to Bus.
	 * There's a check for the state (must be Approved). It returns the updated Element.
	 * If the element has null busversion the element is created on bus, otherwise is updated.<commit_msg>added javadoc to method getInstance<commit_after>package metricapp.service.repository;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import javax.annotation.Nonnull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;

import metricapp.entity.Element;
import metricapp.entity.Entity;
import metricapp.entity.State;
import metricapp.entity.external.PointerBus;
import metricapp.entity.external.RichPointerBus;
import metricapp.entity.measurementGoal.MeasurementGoal;
import metricapp.entity.metric.Metric;
import metricapp.entity.question.Question;
import metricapp.exception.BadInputException;
import metricapp.exception.BusException;
import metricapp.service.spec.repository.BusApprovedElementInterface;
import metricapp.service.spec.repository.BusInterface;
import metricapp.utility.JacksonMapper;

/**
 * This repository offers method to send and grab our Elements to and from BUS.
 * <p>
 * Supported items:
 * <ul>
 * <li>Metric
 * <li>Question
 * <li>MeasurementGoal
 * </ul>
 * 
 * Bus Storage contains only Approved Elements, and only Approved Elements can
 * be sent to Bus.
 *
 */
@Service
public class BusApprovedElementRepository implements BusApprovedElementInterface {

	@Autowired
	private BusInterface busRepository;

	@Autowired
	private JacksonMapper mapper;
	
	@Autowired
	static private BusApprovedElementRepository instance;
	
	
	/**
	 * Spring implementation of Singleton Pattern
	 */
	public BusApprovedElementRepository(){
		instance = this;
	}
	
	/**
	 * this getter has to be used only when is not possible the IoD of Spring, like commands of State Transition Utils.
	 * @return
	 */
	public static BusApprovedElementRepository getInstance(){
		return instance;
	}

	/**
	 * This function send an approved Element like to Bus.
	 * There's a check for the state (must be Approved). It returns the updated Element.
	 * If the element has null busversion the element is created on bus, otherwise is updated.
{'fraction_non_alphanumeric': 0.07978594016054488, 'fraction_numerical': 0.0, 'mean_word_length': 5.2778625954198475, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2146349', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1092, 'n_words': 331}