• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to merge consecutive values into a range?

 
Saloon Keeper
Posts: 6469
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:

Carey Brown wrote:I don't understand how P, R, S is a sequence when it is missing the 'Q'.


I asked a question about that. The answer was (if I recall corretly) that these letters are always consecutive. Otherwise I guess it will be even more complex....


I was expecting an output of
201/21P
201/21[R-S]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Piet Souris wrote:

Carey Brown wrote:I don't understand how P, R, S is a sequence when it is missing the 'Q'.


I asked a question about that. The answer was (if I recall corretly) that these letters are always consecutive. Otherwise I guess it will be even more complex....


I was expecting an output of
201/21P
201/21[R-S]



Since Q is in the English alphabet, it's like you wrote it.It is true
 
kiraz cevik
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

kiraz cevik wrote:

Piet Souris wrote:hi Kiraz,
the map that I created was only meant to be an intermediate result. It was my intention to go on processing. My further ideas were:

create an enum

and have new new Class:


Now, I would have a method that processes my intermediate results in the map, and creates a List<FinalToken>. Supose you have this entry in the map:

Because of the empty char at the start of the list (coming from the Token 300 without any chars) I create two FinalTokens: with 300 and type JUST_A_NUMBER, and 300 with list [A, B, C], with type NUMBER_WITH_ChAR.
The last one will output the toString result: 300[A-C].
So I have a List<FinalToken>. My last step is to go from top to bottom, and when I encounter type JUST_A_NUMBER, I will check if the next couple of elements are also of type JUST_A_NUMBER and have consecutive ints. Then I will output the [300 - 350] form.

Well, sounds more complicated than it is (I hope), but I have not yet had time (or courage) to implement all this (well, I do have the enum).

This was what I had in mind. Wondering if others have come up with someting more simple.
   


Thank you. Do I create an enum class separate from the code you originally wrote?Is the FinalToken class created separately



I am sorry.I'm a beginner in Java, I created the same enum class, but it didn't work.
 
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

kiraz cevik wrote:Since Q is in the English alphabet, it's like you wrote it.It is true


But that leads to problems. In your language the Q is missing, so you would interprete [P-S] as [P. R, S], but in the west we would interprete this as [P, Q, R, S]. To prevent problems like this, I suggest that you add the alphabet that is used here, in the correct order. For instance, with such a table and interpreting [P-S] as [P, Q, R, S] we can then see that the Q should not be there. Or maybe an alternative is to define a fixed alphabet that you will use, so that no misundertanding is possible. With one of those possibilities in mind, and suppuse A, B and C are allowed letters, is 1A, 1C possible, or can we rely on letters always being consecutive?
 
Piet Souris
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

kiraz cevik wrote:I am sorry.I'm a beginner in Java, I created the same enum class, but it didn't work.


Well, my enum was incomplete, I was only showing the idea. Since I only need that to simply see if a FinalToken is just a number (and so can check if we have a sequence of them in the List<FinalToken>, we only need for now just two enum values: JUST_A_NUMBER and OTHER. But if that is not enough, then we can always expand it as necessary. I hope to have time tomorrow to implement the rest of what I described.
 
kiraz cevik
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:

kiraz cevik wrote:Since Q is in the English alphabet, it's like you wrote it.It is true


But that leads to problems. In your language the Q is missing, so you would interprete [P-S] as [P. R, S], but in the west we would interprete this as [P, Q, R, S]. To prevent problems like this, I suggest that you add the alphabet that is used here, in the correct order. For instance, with such a table and interpreting [P-S] as [P, Q, R, S] we can then see that the Q should not be there. Or maybe an alternative is to define a fixed alphabet that you will use, so that no misundertanding is possible. With one of those possibilities in mind, and suppuse A, B and C are allowed letters, is 1A, 1C possible, or can we rely on letters always being consecutive?


Thanks
[P-Q-R-S]=[P-S] Must be shaped.
You can always rely consecutive letters.
300A, 301B, 302C =[300-302][A-C] no. This has not to be sorted.  Because it's not serial.
I wanted to remind you.
 
Piet Souris
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Had some time to work further on the problem. Almost there, one final thing to do. That is if we have the consecutive Toekns 2, 3, 4, 5 then it should display [2-5]. I also incorporatd that "100/50" comes before "100/100". Don't know if that is necessary, though, but I was busy anyway. It is still a raw version, hardly tested, but here goes:
 
Piet Souris
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just added the missing method. It's a bit messy, but up to you to give it a thorough test and to make the code a little more neat. If you find any errors, please let me know.
 
kiraz cevik
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quoted text removed]

Thank you very much for your help.
 
Piet Souris
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
Sheriff
Posts: 6456
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiraz cevik,

It is not necessary to quote the entire previous message when the context is clear.  Only quote as much text as needed to provide context.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!