Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:53:04+00:00 2026-06-16T03:53:04+00:00

The issue with my code is that when I call generateCSV() below, the output

  • 0

The issue with my code is that when I call generateCSV() below, the output of the ArrayList is not correct. It is replacing all of the instances with only the last instance to be instantiated, i.e. the last instance is replacing all previous incidences.

My base class, PausePred, takes a string and an ArrayList

public class PausePred {

    private String predString;  // the keys preceding the pause
    private ArrayList<KSE> kseArr;  // the arraylist of KSEs comprising the PausePred

    public PausePred(String predStr) { 
        this.predString = predStr;
        kseArr = new ArrayList<KSE>();
    } 

    public void setKseArr(ArrayList<KSE> kseArr) {
        this.kseArr.addAll(kseArr);
    }

Within PausePred, I have a static method to create an array of PausePreds.

public static Collection<PausePred> parseKseArray(KSE[] kArr) {

    Collection<PausePred> pausePredArray = new ArrayList<PausePred>();

    String pausePredStr = "";       // to store incrementally appended events preceding pause
    int pauseDur = 0;               // to store pause duration
    boolean startPosSet = false;    // checks if startPos has been set
    ArrayList<KSE> pausePredKseArr = new ArrayList<KSE>();;


    for (int kseArrIdx = 0; kseArrIdx < kArr.length; kseArrIdx++) {
        if (kArr[kseArrIdx].isKeyPress()) { // only down-keys
            // if start positio"n has not been set, set it, and update flag
            // set time stamp, as well
            if (startPosSet == false) {
                startPosSet = true;
                // get first char of PredStr by going back one index
                if (kseArrIdx > 0) {
                    pausePredStr = VisualCharStream.vkCodetoString(kArr[kseArrIdx-1].getKeyCode());
                    pausePredKseArr.add(kArr[kseArrIdx-1]);
                }
            }

            if (kArr[kseArrIdx].getM_pauseMs() < PauseBursts.PAUSE) {   // is not a pause
                //append vkCode (to string) to pausePred
                pausePredStr += VisualCharStream.vkCodetoString(kArr[kseArrIdx].getKeyCode());
                pausePredKseArr.add(kArr[kseArrIdx]);
            }

            else {  // is a pause

                //start incrementing pause duration, until a non-pause is reached
                while (kArr[kseArrIdx].getM_pauseMs() >= PauseBursts.PAUSE) {
                    pauseDur = (int) kArr[kseArrIdx].getM_pauseMs();
                    kseArrIdx++;
                }

                //add to pausePred array
                PausePred pp = new PausePred(pausePredStr);
                pp.setKseArr(pausePredKseArr);
                pausePredArray.add(pp);

                //reset variables
                pausePredStr = "";
                startPosSet = false;
                pausePredKseArr.clear();
                //need to take one step back from above while loop
                kseArrIdx--;
            }
        } // close outer if loop
    } // close for loop
    return pausePredArray;
} // close parseKseArray()

When I call this method below, the first part gives each instance, but the second part gives only the kseArr of the last instance in the array.

    public static void generateCSV(String fileName,ArrayList<PausePred> pausePredArr) {
        for (PausePred pp : pausePredArr)
System.out.println(pp.getPredString()+"\t"+pp.kseArr.get(pp.kseArr.size()-1).getKeyCode()); 
}

This is the extraction method that calls the parse method above. I’m not sure if it’s germane to this issue.

public class ExtractPausePred implements ExtractionModule {

    private static ArrayList<PausePred> pausePredArray = new ArrayList<PausePred>();

    @Override
    public void extract(DataNode data) {

        for (Answer a : data) {
            //create KSE array
            KSE[] kseArr = parseSessionToKSE(a.getKeyStrokes());

            //from above KSE array, extract Pause Predecessors
            pausePredArray.addAll(PausePred.parseKseArray(kseArr));
            PausePred.generateCSV("testing123",pausePredArray);
        }

        return null;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:53:05+00:00Added an answer on June 16, 2026 at 3:53 am

    The problem is your attempt to prematurely optimize by reusing the same objects:

    pausePredKseArr.clear();

    Create a new ArrayList instead of clearing the old one and you’ll be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My issue is that the code is not changing my Alarm tone, or the
Below is code to an inherited ComboBox. The issue is that the ComboBox is
My issue is with a certain style of code that very much resembles recursion,
I'm trying to track down an issue in our MFC code that looks like
I have a quite strange issue. Please, look at these screenshots: Code of that
The issue is that VS2010 Code Analysis is returning two CA2000 warnings for a
In following code the issue is, that I cannot test dao.add() without using dao.list().size()
Okay, of course it is possible, that's no issue. In my code I have
I'm running a weird issue here. I have code that makes jquery ajax calls
My code has a class in it (let's call it myRefLib) that inherits from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.