<commit_before>package org.commcare.session;

import org.commcare.suite.model.Detail;
import org.commcare.suite.model.FormEntry;
import org.commcare.suite.model.Entry;
import org.commcare.suite.model.Menu;
import org.commcare.suite.model.SessionDatum;
import org.commcare.suite.model.StackFrameStep;
import org.commcare.suite.model.StackOperation;
import org.commcare.suite.model.Suite;
import org.commcare.util.CommCarePlatform;
import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.core.model.data.UncastData;
import org.javarosa.core.model.instance.DataInstance;
import org.javarosa.core.model.instance.FormInstance;
import org.javarosa.core.model.instance.InstanceInitializationFactory;
import org.javarosa.core.model.instance.TreeElement;
import org.javarosa.core.services.locale.Localizer;
import org.javarosa.core.util.OrderedHashtable;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.xpath.XPathException;
import org.javarosa.xpath.XPathParseTool;
import org.javarosa.xpath.expr.XPathExpression;
import org.javarosa.xpath.expr.XPathFuncExpr;
import org.javarosa.xpath.parser.XPathSyntaxException;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Stack;
import java.util.Vector;

/**
 * Before arriving at the Form Entry phase, CommCare applications
 * need to determine what form to enter, and with what pre-requisites.
 *
 * A CommCare Session helps to encapsulate this information by identifying
 * the set of possible entry operations (Every piece of data needed to begin
 * entry) and specifying the operation which would most quickly filter our
 * the set of operations.
 *
 * NOTE: Currently horribly coupled to the platform.
 *
 * @author ctsims
 */
public class CommCareSession {

    private final CommCarePlatform platform;
    private StackFrameStep popped;
    private String currentCmd;

    /**
     * A table of all datums (id --> value) that are currently on the session stack
     */
    private final OrderedHashtable<String, String> collectedDatums;
    private String currentXmlns;

    /**
     * The current session frame data
     */
    private SessionFrame frame;

    /**
     * The stack of pending Frames
     */
    private final Stack<SessionFrame> frameStack;

    public CommCareSession(CommCarePlatform platform) {
        this.platform = platform;
        collectedDatums = new OrderedHashtable<String, String>();
        this.frame = new SessionFrame();
        this.frameStack = new Stack<SessionFrame>();
    }

    /**
     *  Copy constructor
     */
    public CommCareSession(CommCareSession oldCommCareSession) {
        this.platform = oldCommCareSession.platform;
        collectedDatums = new OrderedHashtable<String, String>();

        for (Enumeration e = oldCommCareSession.collectedDatums.keys(); e.hasMoreElements(); ) {
            String key = (String)e.nextElement();
            collectedDatums.put(key, oldCommCareSession.collectedDatums.get(key));
        }

        this.frame = new SessionFrame(oldCommCareSession.frame);
        this.frameStack = new Stack<SessionFrame>();

        // NOTE: can't use for/each due to J2ME build issues w/ Stack
        for (int i = 0; i < oldCommCareSession.frameStack.size(); i++) {<commit_msg>Add missing fields from copy constructor<commit_after>package org.commcare.session;

import org.commcare.suite.model.Detail;
import org.commcare.suite.model.FormEntry;
import org.commcare.suite.model.Entry;
import org.commcare.suite.model.Menu;
import org.commcare.suite.model.SessionDatum;
import org.commcare.suite.model.StackFrameStep;
import org.commcare.suite.model.StackOperation;
import org.commcare.suite.model.Suite;
import org.commcare.util.CommCarePlatform;
import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.core.model.data.UncastData;
import org.javarosa.core.model.instance.DataInstance;
import org.javarosa.core.model.instance.FormInstance;
import org.javarosa.core.model.instance.InstanceInitializationFactory;
import org.javarosa.core.model.instance.TreeElement;
import org.javarosa.core.services.locale.Localizer;
import org.javarosa.core.util.OrderedHashtable;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.xpath.XPathException;
import org.javarosa.xpath.XPathParseTool;
import org.javarosa.xpath.expr.XPathExpression;
import org.javarosa.xpath.expr.XPathFuncExpr;
import org.javarosa.xpath.parser.XPathSyntaxException;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Stack;
import java.util.Vector;

/**
 * Before arriving at the Form Entry phase, CommCare applications
 * need to determine what form to enter, and with what pre-requisites.
 *
 * A CommCare Session helps to encapsulate this information by identifying
 * the set of possible entry operations (Every piece of data needed to begin
 * entry) and specifying the operation which would most quickly filter our
 * the set of operations.
 *
 * NOTE: Currently horribly coupled to the platform.
 *
 * @author ctsims
 */
public class CommCareSession {

    private final CommCarePlatform platform;
    private StackFrameStep popped;
    private String currentCmd;

    /**
     * A table of all datums (id --> value) that are currently on the session stack
     */
    private final OrderedHashtable<String, String> collectedDatums;
    private String currentXmlns;

    /**
     * The current session frame data
     */
    private SessionFrame frame;

    /**
     * The stack of pending Frames
     */
    private final Stack<SessionFrame> frameStack;

    public CommCareSession(CommCarePlatform platform) {
        this.platform = platform;
        collectedDatums = new OrderedHashtable<String, String>();
        this.frame = new SessionFrame();
        this.frameStack = new Stack<SessionFrame>();
    }

    /**
     *  Copy constructor
     */
    public CommCareSession(CommCareSession oldCommCareSession) {
        this.platform = oldCommCareSession.platform;
        this.popped = new StackFrameStep(oldCommCareSession.popped);
        this.currentCmd = oldCommCareSession.currentCmd;
        this.currentXmlns = oldCommCareSession.currentXmlns;
        this.frame = new SessionFrame(oldCommCareSession.frame);

        collectedDatums = new OrderedHashtable<String, String>();
        for (Enumeration e = oldCommCareSession.collectedDatums.keys(); e.hasMoreElements(); ) {
            String key = (String)e.nextElement();
            collectedDatums.put(key, oldCommCareSession.collectedDatums.get(key));
        }

        this.frameStack = new Stack<SessionFrame>();
        // NOTE: can't use for/each due to J2ME build issues w/ Stack
        for (int i = 0; i < oldCommCareSession.frameStack.size(); i++) {
{'fraction_non_alphanumeric': 0.09304948540814888, 'fraction_numerical': 0.0005639362752009023, 'mean_word_length': 4.013427561837456, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '1081914', 'n_tokens_mistral': 2066, 'n_tokens_neox': 2009, 'n_words': 498}