Yaniv Bronhaim has posted comments on this change.
Change subject: core: Adding RpmVersion utils
......................................................................
Patch Set 8:
(7 comments)
....................................................
File
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/RpmVersionUtils.java
Line 16: * 0 - if two parts are equals
Line 17: * 1 - if the 1st argument is bigger than the 2nd
Line 18: * -1 - if the 1st argument is smaller than the 2nd
Line 19: */
Line 20: public static int compareRpmPart(String part1, String part2) {
parts
Line 21: // The method takes the two strings, and for each one of them -
Line 22: // Calculates segments of numeric or letters (for each segment
- will try
Line 23: // to get its maximum possible length)
Line 24: // Then it will take two segments from both strings that are
located in the same
Line 33: while (comps1[counter] != null && comps2[counter] != null
Line 34: &&
comps1[counter].toString().equals(comps2[counter].toString())) {
Line 35: counter++;
Line 36: }
Line 37: // part1 has more parts
you should first check if both comps' length are equal to counter, and return 0
if so, no?
Line 38: if (counter == comps2.length) {
Line 39: return 1;
Line 40: }
Line 41: // part2 has more parts
Line 89: int arrayIndex = 0;
Line 90: int index = 0;
Line 91: int state = 0; //0 - start , 1 - alphabetic, 2 - numeric - 3
other
Line 92: StringBuilder current = new StringBuilder();
Line 93: // The maximum number of segments is the number of charactgers
in the string
s/charactgers/characters
Line 94: while (index < part.length()) {
Line 95: // The current character is letter
Line 96: if (isLetter(chars[index])) {
Line 97: if (state == 2) {
Line 90: int index = 0;
Line 91: int state = 0; //0 - start , 1 - alphabetic, 2 - numeric - 3
other
Line 92: StringBuilder current = new StringBuilder();
Line 93: // The maximum number of segments is the number of charactgers
in the string
Line 94: while (index < part.length()) {
make it for loop
for (index=0; index < part.length(); index++)
Line 95: // The current character is letter
Line 96: if (isLetter(chars[index])) {
Line 97: if (state == 2) {
Line 98: // in case the current state is "numeric"
Line 104: }
Line 105: // change state to "alphabetic"
Line 106: state = 1;
Line 107: current.append(chars[index]);
Line 108: } else
elif
Line 109: // The current character is numeric
Line 110: if (Character.isDigit(chars[index])) {
Line 111: if (state == 1) {
Line 112: // in case the current state is "alphabetic"
Line 123: // The character is not a number nor a letter
Line 124: // This means a segment has ended
Line 125: // The segment should be added to the array
Line 126: // and a new buffer should be created
Line 127: if (state == 2 || state == 1 || state == 3) {
you can just check if (state != 0)
Line 128: comps[arrayIndex++] = current;
Line 129: current = new StringBuilder();
Line 130: }
Line 131: state = 3;
....................................................
File
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/RpmVersionUtilsTest.java
Line 35: assertEquals("20130820.fc18.x86_64", parts[2]);
Line 36: }
Line 37:
Line 38: @Test
Line 39: public void testFillCompsArray() {
you can add bunch of tests here. I recommend to test also edge cases as -
1.1.1g1 , #$?# , 1, #, null and inc..
Line 40: StringBuilder[] result =
RpmVersionUtils.fillCompsArray("20130820.1.3.fc18.x86_64");
Line 41: String[] expected =
{"20130820","1","3","fc","18","x","86","64"};
Line 42: int counter = 0;
Line 43: while (true) {
--
To view, visit http://gerrit.ovirt.org/18370
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Ia82d09e755b767f254224c84abd16516592715ac
Gerrit-PatchSet: 8
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yair Zaslavsky <[email protected]>
Gerrit-Reviewer: Daniel Erez <[email protected]>
Gerrit-Reviewer: Douglas Schilling Landgraf <[email protected]>
Gerrit-Reviewer: Vojtech Szocs <[email protected]>
Gerrit-Reviewer: Yair Zaslavsky <[email protected]>
Gerrit-Reviewer: Yaniv Bronhaim <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches