• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Comparing Consecutive versions

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,
has anyone come across the need to compare the versions of a file and see if they are consecutive?
eg: Rev 1.1 <-> Rev 1.2 =>true
Rev 1.2 <-> Rev 1.3 =>true
Rev 1.3 <-> Rev 1.4 =>true
Rev 1.3 <-> Rev branch 1.3.1.1 =>true
Rev 1.3.1.1 <-> Rev 1.3.1.2 =>true
Rev 1.1<-> Rev 1.4 => false
Rev 1.2.1.2 <-> Rev 1.2.1.2.1.1 =>true

i was thinking to tokenize the string containing the version number with '.' as delimiter and then comparing each each digit to see if they are consecutive versions.

what do you think??
 
lowercase baba
Posts: 13069
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does that work if you get to:

Rev 1.9 <-> 1.10

And what about

1.2 <-> 1.3.1

I think the first thing you need to do is nail down how versions are numbered. Can a number be skipped, i.e. you have a 1.1 and a 1.3, but not a 1.2?

are you guaranteed to have a 1.3 before you have a 1.3.1?

Then you need to look at things and forget about java, but write down in English (or French, or German or whatever) how exactly YOU would do it without a computer.
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rev 1.9 <-> 1.10

Should return true

1.2 <-> 1.3.1

returns false.

it should return true only when the versions are consecutive.

Can a number be skipped, i.e. you have a 1.1 and a 1.3, but not a 1.2?

are you guaranteed to have a 1.3 before you have a 1.3.1?

: My understanding was versioning is done in a series, not that one version of the file is 1.2 and then comes 1.4.
Correct me if I am wrong.
 
fred rosenberger
lowercase baba
Posts: 13069
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My understanding was versioning is done in a series, not that one version of the file is 1.2 and then comes 1.4. Correct me if I am wrong.


How are we supposed to do that? it is YOUR data. We don't know what it does or how it is generated. Part of being a programmer is analyzing your data set and finding out what can and can't be done. You are free to assume that versions will be sequential, but you should realize that you are making that assumption - and I would suggest you document all your assumptions.


Yes, I know that. But does the algorithm you describe handle it? You specifically say "compar(e) each each digit to see if they are consecutive versions". does that mean you are going to compare the 9 and the 1 - as those are digits? What do you do with the '0'?

or are you going to compare the TOKENS - i.e. "9" and "10"?

Can versions be lettered - i.e. version 1.4A, 1.4B, etc? If you assume they will not be, then that is another assumption to document.

Are you guaranteed that there can't be a 1.9.1 made after 1.10 (another assumption here...) Many companies will support two versions and will make new releases of older products. Maybe you don't care for this particular task.

My larger point is that there is usually a LOT of thinking that has to go on before you ever consider writing a line of code. I'm asking these questions to get you to think about all this, and possibly come up with other ideas.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1.2.1.2 <-> Rev 1.2.1.2.1.1 =>true


Is that really consecutive? Surely it should be:
1.2.1.2 <-> Rev 1.2.1.2.1
1.2.1.2.1 <-> Rev 1.2.1.2.1.1

I suggest you do as Fred has said. Specifying the exact rules is the key to coding this correctly.
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Fred and Tony.. I will do my homewok and get that clear and get back.
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I m so sorry for the late reply.. was sick and bedridden. Coming back to the thread..

Can versions be lettered

--> No

Are you guaranteed that there can't be a 1.9.1 made after 1.10 (

-> 1.9.1.1 can be made after 1.10 but when doing comparison, it is not needed to be compared. 1.10 will b e compared aganist 1.9 and 1.9.1.1 aganist 1.9.

I have attached the Versioning Structure.

Shine
Unbenannt.jpg
[Thumbnail for Unbenannt.jpg]
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shine Tom wrote:1.9.1.1 can be made after 1.10 but when doing comparison, it is not needed to be compared. 1.10 will b e compared aganist 1.9 and 1.9.1.1 aganist 1.9.


Yes, but that doesn't help us. What we need to know is HOW you want these comparisons done...exactly; and your examples are not conclusive.
For example, you cited:
Rev 1.3 <-> Rev 1.4 =>true
and
Rev 1.3 <-> Rev branch 1.3.1.1 =>true

What about:
Rev 1.3 <-> Rev branch 1.3.1
?
Or indeed:
Rev 1.3 <-> Rev 1.5
if there is NO Rev 1.4 ?

I have attached the Versioning Structure.


That's a help, but it doesn't answer all the questions you're going to need answered - particularly the ones Fred came up with.

The answers to those things are going to have a large bearing on how you go about your "consecutive" check, so you need to get ALL the rules written down before you write a single line of Java code.

And quite honestly, your problem is NOT going to be comparing increasing branch lengths; it's going to be decreasing ones. For example, from your diagram, I'd assume that:
Rev branch 1.2.1.2.1.1 <-> Rev branch 1.2.1.3
is true (and vice-versa); and that is going to be quite difficult to program without some master table of valid versions.

Winston
 
Tony Docherty
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some years ago I wrote some code for comparing 2 version numbers where the version numbers were dot separated numerical values ie the same basic format as your values. The code I wrote will not do what you want because it was just for sorting version numbers into ascending order but part of the solution was to convert the version number as a dot separated string into an array of ints. Once you have an array of ints for each version number it is relatively easy to compare the array elements numerically to see if they are consecutive etc. The reason I'm telling you this is so you don't get hung up on "how am I going to write the code to do ...", the code is simple but you can only start to write it when you a set of rules for every situation.
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was again sick.i m really sorry.

Rev branch 1.2.1.2.1.1 <-> Rev branch 1.2.1.3
is true (and vice-versa); and that is going to be quite difficult to program without some master table of valid versions.

true. I would need to implement 'something' to do that.

What about:
Rev 1.3 <-> Rev branch 1.3.1

: this versioning system doesnt have a version like 1.3.1.
1.3.1 will be considered as the base for 1.3.1.1

Rev 1.3 <-> Rev 1.5 if there is NO Rev 1.4 ?

: can this happen that a version is not there??
 
fred rosenberger
lowercase baba
Posts: 13069
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shine Tom wrote:I was again sick.i m really sorry.


No worries. We're happy to help whenever you need it.

Shine Tom wrote:

Rev 1.3 <-> Rev 1.5 if there is NO Rev 1.4 ?

: can this happen that a version is not there??


Why are you asking us? This is your problem. You know what the rules are - not us. We can guess or makes assumptions, but we really have no way to know what your situation is. If you don't know, then you need to ask someone who does.

Where did this problem come from? Is it homework? Is it something you just made up? Is it for work? If it is any of those, then go to the person who gave it to you and ask them (teacher, yourself, your boss).

The hardest part of writing code is nailing down the specs.
 
Shine Tom
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Fred for replying

Rev 1.3 <-> Rev 1.5 if there is NO Rev 1.4 ?

:> i'll get it cleared. the people in charge have already left..
 
Run away! Run away! Here, take this tiny ad with you:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic