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

  • Home
  • SEARCH
  • 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 8399973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:26:41+00:00 2026-06-09T21:26:41+00:00

I have an interesting problem Here is the object structure public class Testdata {

  • 0

I have an interesting problem

Here is the object structure

public class Testdata {
    //Which is a consecutive running number i.e 1,2,3..etc
    private int sequence;

    //classified based on this again any random numbers
    private int window; 

    //need to calculate
    private int windowposition; 

}

Now based on the sequence and window , i would need to derive windowposition in relation to the window

Test Data
So for testdata sequence/window

        1 / 2
        2 / 3
        3 / 2
        4 / 3
        5 / 3

Expected Output

    sequence/window :   window position would be (in the same order)

    1 / 2       :   1

    2 / 3       :   1

    3 / 2       :   2

    4 / 3       :   2

    5 / 3       :   3

Update:

yes indeed , I have already implemented comparable and sorted the list to below order

1 / 2
3 / 2
2 / 3        
4 / 3
5 / 3

Now how do I calculate the windowposition of each element in relation to its window

  • 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-09T21:26:42+00:00Added an answer on June 9, 2026 at 9:26 pm

    It would probably make sense to implement Comparable. That allows your objects to be sorted. You would implement compareTo(T) like so:

    int compareTo(Testdata o) {
      return ((Integer)this.sequence).compareTo(o.sequence);
    }
    

    That way your objects can be sorted by sequence.

    Now collect all the objects with window 1 into a List, objects with window 2 into another list etc.

    HashMap<Integer, ArrayList<Testdata>> map = new HashMap<Integer, ArrayList<Testdata>>();
    
    // Add all the objects like this
    while (...) { // While there are more objects
      Testdata td = ... // Get next object
    
      List<TestData> list = map.get(td.window);
      if (list == null) {
        list = new ArrayList<Testdata>();
        map.put(td.window, list);
      }
    
      list.add(td.sequence);
    }
    

    Sort all of the lists using Collections.sort(List):

    for (ArrayList<TestData> list : map) {
      Collections.sort(list);
    }
    

    You then have one list for each window, accessible via map.get(window). Each of these lists has the object with the lowest sequence as its first object, second lowest as second object etc. -> the window position is the index of the object + 1.

    EDIT:

    If your objects are already sorted by window and sequence (into a single list), you can do something like this to assign the window positions:

    int window = 1;
    int wp = 0;
    for (Testdata td : list) {
      if (td.window > window) {
        wp = 1;
        window = td.window;
      } else {
        wp++;
      }
    
      td.windowposition = wp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting problem. Consider this class hierachy: class Base { public: virtual
I have an interesting problem here I've been trying to solve for the last
Interesting problem I have here, usually I just round up/down respectively for my needs
I have an interesting SQL problem that I need help with. Here is the
I've got an interesting box-model problem here. I have a header full of links,
I have a problem with Menu button on Android 4.0. Here's the interesting part
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have an interesting problem. I have a page containing a Telerik chart which
This is an interesting problem that I have searched here and all over my
We have an interesting problem with WCF binding and streaming transfer mode that we

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.