<commit_before>package edu.stanford.junction.provider;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;

import org.json.JSONObject;

import edu.stanford.junction.api.activity.JunctionExtra;
import edu.stanford.junction.api.messaging.MessageHeader;

public class ExtrasDirector extends JunctionExtra {
	
	Comparator<JunctionExtra>mComparator = new Comparator<JunctionExtra>() {
		@Override
		public int compare(JunctionExtra o1, JunctionExtra o2) {
			return o1.getPriority().compareTo(o2.getPriority());
		}
	};
	TreeSet<JunctionExtra>mExtras = new TreeSet<JunctionExtra>(mComparator);
	
	/**
	 * Returns true if onMessageReceived should be called in the usual way.
	 * @param header
	 * @param message
	 * @return
	 */
	@Override
	public boolean beforeOnMessageReceived(MessageHeader header, JSONObject message) {
		Iterator<JunctionExtra>iter = mExtras.descendingIterator();
		while (iter.hasNext()) {
			JunctionExtra ex = iter.next();
			if (!ex.beforeOnMessageReceived(header, message))
				return false;
		}
		return true;
	}
	
	@Override
	public void afterOnMessageReceived(MessageHeader header, JSONObject message) {
		Iterator<JunctionExtra>iter = mExtras.descendingIterator();
		while (iter.hasNext()) {
			JunctionExtra ex = iter.next();
			ex.afterOnMessageReceived(header, message);
		}
	}
	
	@Override
	public boolean beforeSendMessageToActor(String actorID, JSONObject message) {
		Iterator<JunctionExtra>iter = mExtras.iterator();
		while (iter.hasNext()) {
			JunctionExtra ex = iter.next();
			if (!ex.beforeSendMessageToActor(actorID, message))
				return false;
		}
		return true;
	}
	<commit_msg>descendingIterator not implemented on android<commit_after>package edu.stanford.junction.provider;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;

import org.json.JSONObject;

import edu.stanford.junction.api.activity.JunctionExtra;
import edu.stanford.junction.api.messaging.MessageHeader;

public class ExtrasDirector extends JunctionExtra {
	
	Comparator<JunctionExtra>mComparator = new Comparator<JunctionExtra>() {
		@Override
		public int compare(JunctionExtra o1, JunctionExtra o2) {
			return o1.getPriority().compareTo(o2.getPriority());
		}
	};
	TreeSet<JunctionExtra>mExtras = new TreeSet<JunctionExtra>(mComparator);
	
	/**
	 * Returns true if onMessageReceived should be called in the usual way.
	 * @param header
	 * @param message
	 * @return
	 */
	@Override
	public boolean beforeOnMessageReceived(MessageHeader header, JSONObject message) {
		// not available on android (API 4)
		/*
		Iterator<JunctionExtra>iter = mExtras.descendingIterator();
		while (iter.hasNext()) {
			JunctionExtra ex = iter.next();
			if (!ex.beforeOnMessageReceived(header, message))
				return false;
		}
		return true;
		*/
		
		Iterator<JunctionExtra>fwd = mExtras.iterator();
		ArrayList<JunctionExtra>list = new ArrayList<JunctionExtra>();
		while (fwd.hasNext()) {
			list.add(fwd.next());
		}
		for (int i=list.size()-1;i>=0;i--){
			JunctionExtra ex = list.get(i);
			if (!ex.beforeOnMessageReceived(header, message))
				return false;
		}
		
		return true;
	}
	
	@Override
	public void afterOnMessageReceived(MessageHeader header, JSONObject message) {
		// not available on android (API 4)
		/*
		Iterator<JunctionExtra>iter = mExtras.descendingIterator();
		while (iter.hasNext()) {
			JunctionExtra ex = iter.next();
			ex.afterOnMessageReceived(header, message);
		}
		*/
		
		Iterator<JunctionExtra>fwd = mExtras.iterator();
		ArrayList<JunctionExtra>list = new ArrayList<JunctionExtra>();
		while (fwd.hasNext()) {
			list.add(fwd.next());
		}
		for (int i=list.size()-1;i>=0;i--){
			JunctionExtra ex = list.get(i);
			ex.afterOnMessageReceived(header, message);
		}
	}
	
	@Override
	public boolean beforeSendMessageToActor(String actorID, JSONObject message) {
		Iterator<JunctionExtra>iter = mExtras.iterator();
		while (iter.hasNext()) {
			JunctionExtra ex = iter.next();
			if (!ex.beforeSendMessageToActor(actorID, message))
				return false;
		}
		return true;
	}
	
{'fraction_non_alphanumeric': 0.11854176726219218, 'fraction_numerical': 0.003380009657170449, 'mean_word_length': 4.730290456431535, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '374453', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1295, 'n_words': 275}