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 7928757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:50:18+00:00 2026-06-03T19:50:18+00:00

I need to store a set of data structures that are defined by period

  • 0

I need to store a set of data structures that are defined by period of time (start, end) and counter for this period that holds some complex calculation results. The simplified definition of the data structure is as follows:

public class CounterBag {
    private Period period;   // collection key
    private Counter counter;
    // accessors
    // ...
}

the Period is as simple as:

public class Period {
    public DateTime start;
    public DateTime end;
    // accessors
    // ...
}

I need to have a collection that holds CounterBag objects defined by distinct Periods.
The collection needs to provide efficient lookup (here is the catch!) by long timeInMillis , so HashMap is not really an option, since I do not want to overwrite equals and hashcode of CounterBag (i need them both). The collection needs to be sorted by Period (by end date). Periods are of flexible duration which is not known to the part that would perform the lookup.

I wonder is there an out-of-the-box collection in java standard API or in some open source library that can help me to solve it? Some kind of sorted set or sorted map that enables implementing an efficient lookup by date. The lookup by date would return a CounterBag with Period the date falls within.

Appreciate your suggestions.

  • 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-03T19:50:20+00:00Added an answer on June 3, 2026 at 7:50 pm

    You could use TreeMap as its a Sorted collection (which makes the lookup efficient)

    If your periods have regular intervals (which is the simplest form) you don’t need such a collection. You can just have a counter for each interval. e.g. a int[]

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

Sidebar

Related Questions

I have a set of information that I need to store in some kind
I have a set of string that I need to store in a set,
I really need a second set of eyes on this so I'm hoping some
I need to make a stored procedure or function that returns a set of
I have id values for products that I need store. Right now they are
I need to store GPS coordinates in a database. I've heard that floats are
I need to store locally on android devices some images I get from the
I need an efficient data structure to store a list of integers. The amount
I have a relatively large set of data that lends itself very naturally to
We are in evaluating technologies that we'll use to store data that we gather

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.