<commit_before>package org.opennms.sms.reflector.smsservice;

import org.opennms.sms.reflector.smsservice.MobileMsgTransaction.SmsTransaction;
import org.opennms.sms.reflector.smsservice.MobileMsgTransaction.UssdTransaction;

public class MobileMsgSequenceBuilder {
	public static final int DEFAULT_RETRIES = 0;
	public static final long DEFAULT_TIMEOUT = 10000L;

	public static abstract class MobileMsgTransactionBuilder {
		private MobileMsgResponseMatcher m_matcher;
		private String m_label;
		private String m_gatewayId;
		private long m_timeout;
		private int m_retries;

		public MobileMsgTransactionBuilder(String label, String gatewayId, long timeout, int retries) {
			m_label = label;
			m_gatewayId = gatewayId;
			m_timeout = timeout;
			m_retries = retries;
		}

		public abstract MobileMsgTransaction getTransaction();

		public MobileMsgTransactionBuilder expects(MobileMsgResponseMatcher matcher) {
			m_matcher = matcher;
			return this;
		}
		
		public String getLabel() {
			return m_label;			
		}
		
		public String getGatewayId() {
			return m_gatewayId;
		}

		public long getTimeout() {
			return m_timeout;
		}

		public MobileMsgTransactionBuilder setTimeout(long timeout) {
			m_timeout = timeout;
			return this;
		}

		public int getRetries() {
			return m_retries;
		}
		
		public MobileMsgTransactionBuilder setRetries(int retries) {
			m_retries = retries;
			return this;
		}
		
		public MobileMsgTransactionBuilder setGatewayId(String gatewayId) {
			m_gatewayId = gatewayId;
			return this;
		}
		
		public MobileMsgResponseMatcher getMatcher() {
			return m_matcher;
		}
	}

	public static class SmsTransactionBuilder extends MobileMsgTransactionBuilder {
		private String m_recipient;
		private String m_text;

		public SmsTransactionBuilder(String label, String gatewayId, long timeout, int retries, String recipient, String text) {
			super(label, gatewayId, timeout, retries);
			m_recipient = recipient;
			m_text = text;
		}

		@Override
		public MobileMsgTransaction getTransaction() {
			return new SmsTransaction(
				getLabel(),
				getGatewayId(),
				getTimeout(),
				getRetries(),
				getRecipient(),
				getText(),
				getMatcher()
			);
		}

		private String getText() {
			return m_text;
		}

		private String getRecipient() {
			return m_recipient;
		}
	}

	public static class UssdTransactionBuilder extends MobileMsgTransactionBuilder {
		private String m_text;
		
		public UssdTransactionBuilder(String label, String gatewayId, long timeout, int retries, String text) {
			super(label, gatewayId, timeout, retries);
			m_text = text;
		}

		@Override
		public MobileMsgTransaction getTransaction() {
			return new UssdTransaction(getLabel(), getGatewayId(), getTimeout(), getRetries(), m_text, getMatcher());
		}
		
	}
	
	private MobileMsgSequence m_sequence = new MobileMsgSequence();
	private String m_gatewayId = "*";
	private MobileMsgTransactionBuilder m_currentBuilder;
	private long m_timeout = DEFAULT_TIMEOUT;
	private int m_retries = DEFAULT_RETRIES;
	
	public MobileMsgTransactionBuilder sendSms(String label, String gatewayId, String recipient, String text) {
		addCurrentBuilderToSequence();
		m_currentBuilder = new SmsTransactionBuilder(label, gatewayId == null? m_gatewayId : gatewayId, m_timeout, m_retries, recipient, text);
		return m_currentBuilder;
	}

	public MobileMsgTransactionBuilder sendUssd(String label, String gatewayId, String text) {
		addCurrentBuilderToSequence();
		m_currentBuilder = new UssdTransactionBuilder(label, gatewayId == null? m_gatewayId : gatewayId, m_timeout, m_retries, text);
		return m_currentBuilder;
	}

	public MobileMsgSequenceBuilder setDefaultGatewayId(String gatewayId) {
		m_gatewayId = gatewayId;
		if (m_currentBuilder != null) {
			m_currentBuilder.setGatewayId(gatewayId);
		}
		return this;
	}

	public long getDefaultTimeout() {
		return m_timeout;
	}

	public MobileMsgSequenceBuilder setDefaultTimeout(long timeout) {
		m_timeout = timeout;
		if (m_currentBuilder != null) {
			m_currentBuilder.setTimeout(timeout);
		}
		return this;
	}
	
	public int getDefaultRetries() {
		return m_retries;
	}

	public MobileMsgSequenceBuilder setDefaultRetries(int retries) {
		m_retries = retries;
		if (m_currentBuilder != null) {
			m_currentBuilder.setRetries(retries);
		}
		return this;
	}
	
	public MobileMsgSequence getSequence() {
		addCurrentBuilderToSequence();
		return m_sequence;
	}

	private void addCurrentBuilderToSequence() {
		if (m_currentBuilder == null) {<commit_msg>don't retcon defaults when using setDefault* in the builder<commit_after>package org.opennms.sms.reflector.smsservice;

import org.opennms.sms.reflector.smsservice.MobileMsgTransaction.SmsTransaction;
import org.opennms.sms.reflector.smsservice.MobileMsgTransaction.UssdTransaction;

public class MobileMsgSequenceBuilder {
	public static final int DEFAULT_RETRIES = 0;
	public static final long DEFAULT_TIMEOUT = 10000L;

	public static abstract class MobileMsgTransactionBuilder {
		private MobileMsgResponseMatcher m_matcher;
		private String m_label;
		private String m_gatewayId;
		private long m_timeout;
		private int m_retries;

		public MobileMsgTransactionBuilder(String label, String gatewayId, long timeout, int retries) {
			m_label = label;
			m_gatewayId = gatewayId;
			m_timeout = timeout;
			m_retries = retries;
		}

		public abstract MobileMsgTransaction getTransaction();

		public MobileMsgTransactionBuilder expects(MobileMsgResponseMatcher matcher) {
			m_matcher = matcher;
			return this;
		}
		
		public String getLabel() {
			return m_label;			
		}
		
		public String getGatewayId() {
			return m_gatewayId;
		}

		public long getTimeout() {
			return m_timeout;
		}

		public MobileMsgTransactionBuilder setTimeout(long timeout) {
			m_timeout = timeout;
			return this;
		}

		public int getRetries() {
			return m_retries;
		}
		
		public MobileMsgTransactionBuilder setRetries(int retries) {
			m_retries = retries;
			return this;
		}
		
		public MobileMsgTransactionBuilder setGatewayId(String gatewayId) {
			m_gatewayId = gatewayId;
			return this;
		}
		
		public MobileMsgResponseMatcher getMatcher() {
			return m_matcher;
		}
	}

	public static class SmsTransactionBuilder extends MobileMsgTransactionBuilder {
		private String m_recipient;
		private String m_text;

		public SmsTransactionBuilder(String label, String gatewayId, long timeout, int retries, String recipient, String text) {
			super(label, gatewayId, timeout, retries);
			m_recipient = recipient;
			m_text = text;
		}

		@Override
		public MobileMsgTransaction getTransaction() {
			return new SmsTransaction(
				getLabel(),
				getGatewayId(),
				getTimeout(),
				getRetries(),
				getRecipient(),
				getText(),
				getMatcher()
			);
		}

		private String getText() {
			return m_text;
		}

		private String getRecipient() {
			return m_recipient;
		}
	}

	public static class UssdTransactionBuilder extends MobileMsgTransactionBuilder {
		private String m_text;
		
		public UssdTransactionBuilder(String label, String gatewayId, long timeout, int retries, String text) {
			super(label, gatewayId, timeout, retries);
			m_text = text;
		}

		@Override
		public MobileMsgTransaction getTransaction() {
			return new UssdTransaction(getLabel(), getGatewayId(), getTimeout(), getRetries(), m_text, getMatcher());
		}
		
	}
	
	private MobileMsgSequence m_sequence = new MobileMsgSequence();
	private String m_gatewayId = "*";
	private MobileMsgTransactionBuilder m_currentBuilder;
	private long m_timeout = DEFAULT_TIMEOUT;
	private int m_retries = DEFAULT_RETRIES;
	
	public MobileMsgTransactionBuilder sendSms(String label, String gatewayId, String recipient, String text) {
		addCurrentBuilderToSequence();
		m_currentBuilder = new SmsTransactionBuilder(label, gatewayId == null? m_gatewayId : gatewayId, m_timeout, m_retries, recipient, text);
		return m_currentBuilder;
	}

	public MobileMsgTransactionBuilder sendUssd(String label, String gatewayId, String text) {
		addCurrentBuilderToSequence();
		m_currentBuilder = new UssdTransactionBuilder(label, gatewayId == null? m_gatewayId : gatewayId, m_timeout, m_retries, text);
		return m_currentBuilder;
	}

	public MobileMsgSequenceBuilder setDefaultGatewayId(String gatewayId) {
		m_gatewayId = gatewayId;
		return this;
	}

	public long getDefaultTimeout() {
		return m_timeout;
	}

	public MobileMsgSequenceBuilder setDefaultTimeout(long timeout) {
		m_timeout = timeout;
		return this;
	}
	
	public int getDefaultRetries() {
		return m_retries;
	}

	public MobileMsgSequenceBuilder setDefaultRetries(int retries) {
		m_retries = retries;
		return this;
	}
	
	public MobileMsgSequence getSequence() {
		addCurrentBuilderToSequence();
		return m_sequence;
	}

	private void addCurrentBuilderToSequence() {
		if (m_currentBuilder == null) {
{'fraction_non_alphanumeric': 0.07513335603223244, 'fraction_numerical': 0.001361933946203609, 'mean_word_length': 4.7594771241830065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3639851', 'n_tokens_mistral': 3012, 'n_tokens_neox': 2591, 'n_words': 668}