Context:
package protocol.xmpp;
import android.util.Log;;
import protocol.Contact;
import protocol.Protocol;
import ru.sawim.comm.Util;
import ru.sawim.io.RosterStorage;
import ru.sawim.listener.OnMoreMessagesLoaded;
import ru.sawim.roster.RosterHelper;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
/**
 * Created by gerc on 05.03.2015.
 */
public class MessageArchiveManagement {
    private static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
    public static final long MAX_CATCHUP = MILLISECONDS_IN_DAY * 7;
    public static final long MAX_MESSAGES = 20;
    private final HashSet<Query> queries = new HashSet<>();
    private String getQueryMessageArchiveManagement(Contact contact, Query query) {
        XmlNode xmlNode = new XmlNode(XmlConstants.S_IQ);
        xmlNode.putAttribute(XmlConstants.S_TYPE, XmlConstants.S_SET);
        if (contact != null && contact.isConference()) {
            xmlNode.putAttribute(XmlConstants.S_TO, Util.xmlEscape(contact.getUserId()));
        }
        xmlNode.putAttribute(XmlNode.S_ID, XmppConnection.generateId());
        XmlNode queryNode = new XmlNode(XmlConstants.S_QUERY);
        queryNode.putAttribute(XmlNode.S_XMLNS, "urn:xmpp:mam:0");
        queryNode.putAttribute("queryid", query.queryId);
        XmlNode xNode = new XmlNode("x");
        xNode.putAttribute(XmlNode.S_XMLNS, "jabber:x:data");
        xNode.putAttribute("type", "submit");
        XmlNode formTypeNode = new XmlNode("field");
        formTypeNode.putAttribute("var", "FORM_TYPE");
        formTypeNode.putAttribute("type", "hidden");
        formTypeNode.setValue("value", "urn:xmpp:mam:0");
        xNode.addNode(formTypeNode);
    /*    if (query.getStart() > 0) {
            XmlNode startNode = new XmlNode("field");
            startNode.putAttribute("var", "start");
            startNode.setValue("value", Util.getTimestamp(query.getStart()));
            xNode.addNode(startNode);
        }
        if (query.getEnd() > 0) {
            XmlNode endNode = new XmlNode("field");
            endNode.putAttribute("var", "end");
            endNode.setValue("value", Util.getTimestamp(query.getEnd()));
            xNode.addNode(endNode);
        }*/
        if (query.withJid != null && contact != null && !contact.isConference()) {
            XmlNode withNode = new XmlNode("field");
            withNode.putAttribute("var", "with");
            withNode.setValue("value", query.withJid);
            xNode.addNode(withNode);
        }
        XmlNode setNode = XmlNode.addXmlns("set", "http://jabber.org/protocol/rsm");
        setNode.setValue("max", String.valueOf(MAX_MESSAGES));
        if (query.getPagingOrder() == PagingOrder.REVERSE) {
            setNode.setValue("before", query.getReference());
        } else {
            setNode.setValue("after", query.getReference());
        }
        queryNode.addNode(setNode);
        queryNode.addNode(xNode);
        xmlNode.addNode(queryNode);
        return xmlNode.toString();
    }
    private void queryMessageArchiveManagement(XmppConnection connection, Query query) {
        Contact contact = null;
        if (query.getWith() != null) {
            contact = connection.getProtocol().getItemByUID(query.getWith());
        }
        connection.putPacketIntoQueue(getQueryMessageArchiveManagement(contact, query));
    }
    public void catchup(XmppConnection connection) {
        long startCatchup = getLastMessageTransmitted(connection);
        long endCatchup = connection.getLastSessionEstablished();
        if (startCatchup == 0) {
            return;
        } else {
            ConcurrentHashMap<String, Contact> contacts = connection.getProtocol().getContactItems();
            for (Contact contact : contacts.values()) {
                queryReverse(connection, contact, startCatchup);
            }
        }
        final Query query = new Query(connection.getXmpp().getUserId(), null, startCatchup, endCatchup);
        queries.add(query);
        queryMessageArchiveManagement(connection, query);
    }
    private long getLastMessageTransmitted(XmppConnection connection) {
        long timestamp = 0;
        for (Contact contact : connection.getProtocol().getContactItems().values()) {
            long lastMessageTransmitted = contact.getLastMessageTransmitted();
            if (lastMessageTransmitted > timestamp) {
                timestamp = lastMessageTransmitted;
            }
        }
        return timestamp;
    }
    public Query queryReverse(XmppConnection connection, final Contact contact) {
        return queryReverse(connection, contact, connection.getLastSessionEstablished());
    }
    public Query queryReverse(XmppConnection connection, final Contact contact, long end) {
        long lastMessageTransmitted = contact.getLastMessageTransmitted();
        return queryReverse(connection, contact, lastMessageTransmitted, end);
    }
    public Query queryReverse(XmppConnection connection, Contact contact, long start, long end) {
        synchronized (queries) {
            if (start > end) {
                return null;
            }
            final Query query = new Query(connection.getXmpp().getUserId(), contact.getUserId(),
                    start, end, PagingOrder.REVERSE);
            queries.add(query);
            queryMessageArchiveManagement(connection, query);
            return query;
        }
    }
    public Query prev(XmppConnection connection, Contact contact) {
        synchronized (queries) {
            Query query = new Query(connection.getXmpp().getUserId(), contact.getUserId(), 0, 0)
                        .prev(contact.firstServerMsgId);
            queries.add(query);
            queryMessageArchiveManagement(connection, query);
            return query;
        }
    }
    public void processFin(XmppConnection connection, XmlNode fin) {
        Query query = findQuery(fin.getAttribute("queryid"));
        if (query == null) {
            return;
        }
        boolean complete = XmppConnection.isTrue(fin.getAttribute("complete"));
        XmlNode set = fin.getFirstNode("set", "http://jabber.org/protocol/rsm");
        String last = set == null ? null : set.getFirstNodeValue("last");
        String first = set == null ? null : set.getFirstNodeValue("first");
        String relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
        String count = set == null ? null : set.getFirstNodeValue("count");
        if (count != null) {
            query.setAllMessageCount(Integer.valueOf(count));
        }
        if (relevant != null) {
            Contact contact = null;
            if (query.getWith() != null) {
                contact = connection.getProtocol().getItemByUID(query.getWith());
            }
            contact.firstServerMsgId = first;
            connection.getXmpp().getStorage().updateFirstServerMsgId(contact);
        }
        if (complete || relevant == null) {
            finalizeQuery(connection.getProtocol(), query);
            Log.d("MAM", "finished mam after " + query.getAllMessagesCount() + " messages");
        } else {
            final Query nextQuery;
            if (query.getPagingOrder() == PagingOrder.NORMAL) {
                nextQuery = query.next(last);
            } else {
                nextQuery = query.prev(first);
            }
        //    queryMessageArchiveManagement(connection, nextQuery);
            finalizeQuery(connection.getProtocol(), query);
            synchronized (queries) {
            //    queries.add(nextQuery);
            }
        }
    }
    public boolean queryInProgress(Contact contact, OnMoreMessagesLoaded moreMessagesLoadedListener) {
        synchronized (queries) {
            for (Query query : queries) {
                if (query.getWith().equals(contact.getUserId())) {
                    if (query.onMoreMessagesLoaded == null && moreMessagesLoadedListener != null) {
                        query.setOnMoreMessagesLoaded(moreMessagesLoadedListener);
                    }
                    return true;
                }
            }
            return false;
        }
    }
    private void finalizeQuery(Protocol protocol, Query query) {
        synchronized (queries) {
            queries.remove(query);
        }
        Contact contact = null;
        if (query.getWith() != null) {
            contact = protocol.getItemByUID(query.getWith());
        }
        if (contact != null) {

Answer: if (contact.setLastMessageTransmitted(query.getEnd())) {


Context:
//    <TMSEG: Prediction of Transmembrane Helices in Proteins.>
//    Copyright (C) 2014  Michael Bernhofer
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package predictors;
import io.ModelHandler;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import util.ErrorUtils;
import util.Globals;
import util.Mappings;
import weka.classifiers.Classifier;
import weka.classifiers.trees.RandomForest;
import weka.core.Attribute;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.SparseInstance;
import weka.core.converters.ArffSaver;
import data.Protein;
import data.Pssm;
/**
 * Class to predict transmembrane residues within a protein.
 */
public class HelixIndexer {

	public static final int 		indexNotTmh 	= 0;
	public static final int 		indexTmh 		= 1;
	public static final int 		indexSignal 	= 2;

	private ArrayList<Attribute> 	attributes 		= null;
	private Instances 				dataset 		= null;
	private Classifier 				classifier 		= null;
	private boolean 				isTrained 		= false;

	private double[] 				globalConsAa 	= null;
	private double[] 				globalNonConsAa = null;

	public HelixIndexer()
	{
		this.buildAttributes();
		this.initialize();
	}

	/**
	 * Initializes the attributes list for the Weka arff-format.
	 */
	private void buildAttributes()
	{
		this.attributes = new ArrayList<Attribute>();

		for (int i = 1; i <= ((2*Globals.INDEXER_WINDOW_SIZE)+1); ++i)
		{
			for (int j = 0; j < 21; ++j)
			{
				this.attributes.add(new Attribute(Mappings.intToAa(j)+"_"+i));
			}
		}

		this.attributes.add(new Attribute("conserved_hydrophobicity"));
		this.attributes.add(new Attribute("non-conserved_hydrophobicity"));

		this.attributes.add(new Attribute("conserved_hydrophobic"));
		this.attributes.add(new Attribute("non-conserved_hydrophobic"));

		this.attributes.add(new Attribute("conserved_pos_charged"));
		this.attributes.add(new Attribute("non-conserved_pos_charged"));

		this.attributes.add(new Attribute("conserved_neg_charged"));
		this.attributes.add(new Attribute("non-conserved_neg_charged"));

		this.attributes.add(new Attribute("conserved_polar"));
		this.attributes.add(new Attribute("non-conserved_polar"));

		ArrayList<String> lengths = new ArrayList<String>();

		lengths.add(String.valueOf("0"));
		lengths.add(String.valueOf("1"));
		lengths.add(String.valueOf("2"));
		lengths.add(String.valueOf("3"));
		lengths.add(String.valueOf("4"));

		this.attributes.add(new Attribute("n-term_distance", lengths));
		this.attributes.add(new Attribute("c-term_distance", lengths));
		this.attributes.add(new Attribute("global_length", lengths));

		for (int j = 0; j < 20; ++j)
		{
			this.attributes.add(new Attribute("global_conserved_"+Mappings.intToAa(j)));
			this.attributes.add(new Attribute("global_non-conserved_"+Mappings.intToAa(j)));
		}

		ArrayList<String> classes = new ArrayList<String>();

		classes.add(String.valueOf(HelixIndexer.indexNotTmh));
		classes.add(String.valueOf(HelixIndexer.indexTmh));
		classes.add(String.valueOf(HelixIndexer.indexSignal));

		this.attributes.add(new Attribute("class", classes));
	}

	/**
	 * Initializes the classifier and dataset.
	 */
	public void initialize()
	{
		this.isTrained 	= false;
		this.classifier = null;
		this.dataset 	= new Instances("HelixIndexer Model", this.attributes, 0);

		this.dataset.setClassIndex(this.attributes.size()-1);
	}

	/**
	 * Inputs a given list of proteins for the training data.
	 *
	 * @param proteins
	 */
	public void input(List<Protein> proteins)
	{
		for (Protein protein : proteins)
		{
			this.input(protein);
		}
	}

	/**
	 * Inputs a given protein for the training data.
	 *
	 * @param protein
	 */
	public void input(Protein protein)
	{
		if (protein == null) 				{return;}
		if (protein.getStructure() == null) {return;}
		if (protein.getPssm() == null) 		{return;}

		Pssm 	pssm 		= protein.getPssm();
		int 	length 		= pssm.getLength();
		char[] 	structure 	= protein.getStructure();

		if (pssm.getLength() != structure.length)
		{
			ErrorUtils.printError(HelixIndexer.class, "PSSM and structure annotation length do not match for " + protein.getName(), null);

			return;
		}

		this.globalComposition(pssm);

		for (int i = 0; i < length; ++i)
		{
			if (Mappings.ssToInt(structure[i]) != Mappings.indexUnknown)
			{
				this.addWindowToDatabase(pssm, i, structure);
			}
		}
	}

	/**
	 * Predicts transmembrane residues for a given list of proteins.
	 *
	 * @param proteins
	 */
	public void predict(List<Protein> proteins)
	{
		for (Protein protein : proteins)
		{
			this.predict(protein);
		}
	}

	/**
	 * Predicts transmembrane residues for a given protein.
	 *
	 * @param protein
	 */
	public void predict(Protein protein)
	{
		if (protein == null || protein.getPssm() == null) {return;}

		Pssm 		pssm 		= protein.getPssm();
		int 		length 		= pssm.getLength();
		int[] 		scoresSol 	= new int[length];

Answer: int[] 		scoresTmh 	= new int[length];