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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:58:04+00:00 2026-05-17T01:58:04+00:00

I have a range in java implemented as a class which is divided into

  • 0

I have a range in java implemented as a class which is divided into sub-ranges. The implementation is roughly as follows:

public class Range
{
   static public class Key implements Comparable<Key>
   {
      public int start;
      public int end;
      ...
   }

   Key range;
   SortedMap<Key, Range> subRange;
}

I want to make a function that makes sure that no subrange overlaps each other and the combined range of the subrange covers total range completely. Start and end of each range may be equal.

Example of a valid object:

Range: start 1, end 10
  subrange 1: start 1, end 2
  subrange 2: start 3, end 9
  subrange 3: start 10, end 10

What would be the best way to implement this?

EDIT:

To anyone interested in the implementation:

In my validation code I do these steps:

  1. Convert the sorted map to an Array
  2. Force the first and last element to cover the beginning and end of total range
  3. Iterate array elements and fix gaps or overlap between them

Code for step 3:

for (int i=0; i < (rangeArray.length - 1); i++)
{
    if (rangeArray[i].range.end < (rangeArray[i+1].range.start - 1) ||
        rangeArray[i].range.end >= rangeArray[i+1].range.start)
    {
        // Alternatively, lose the if and just force subrange to behave this way
        rangeArray[i].range.end = rangeArray[i+1].range.start - 1; 
    }
}
  • 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-05-17T01:58:05+00:00Added an answer on May 17, 2026 at 1:58 am

    Since your subRange map is sorted, you can iterate over it and check that there is no gap in the sequence of end to the next start. And of course from your total starting point to the first start and your last end to your total ending point. Apply this check recursively to all subRanges, too.

    For this your map has to be sorted by start, which is the case in your example.

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

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you can use find method (if the input.foo is deep… May 17, 2026 at 2:53 am
  • Editorial Team
    Editorial Team added an answer GeoServer's "Dynamic Symbolizer" extension to SLD does allow you to… May 17, 2026 at 2:53 am
  • Editorial Team
    Editorial Team added an answer I used LinqToTwitter library. It is quite scenarios complete and… May 17, 2026 at 2:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Let's say I have an existing application written in Java which I wish to
Personally, I find the range of functionality provided by java.util.Iterator to be fairly pathetic.
So if I have a range of numbers '0 - 1024' and I want
I have been considering a range of options to move away form using scriptlets
I have a range of parameters that are passed via jQuery Ajax to an
I have a range in excel named ValuesRange located at Cell B5. I have
everyone, I've started working yesterday on the Euler Project in Clojure and I have
Ada , Pascal and many other languages support ranges, a way to subtype integers.
I support a legacy Java application that uses flat files (plain text) for persistence.
How would you implement a capacity-limited, generic MruList in C# or Java? I want

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.