UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21. Read more.
UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21.Read more.
Absent Member.
Absent Member.
1603 views

How to sort ViewMemberCollection using SortCompare

Jump to solution

To sort ViewMemberCollection, how can I using sort(SortCompare),

sortCompare is private method. default sort method is by VMID. But I want to sort by dot notation.

In bellow code, f is File object:

ViewMemberCollection history = f.getHistory();
history.getCache().populate(null);
ViewMember[] vms = history.sort();
File file = null;
int i = 0;
while (i < vms.length) {
file = (File)vms;
if (f.getDotNotation().equals(vms.getDotNotation())) {
//...
break;
}
}
i++;

}

0 Likes
2 Solutions

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

we haven't provided an api to do so. it didn't come up as a requirement.

you'll have to grab the underlying array, copy it into your own java.util.Collection, and then run SortCompare on that by dot notation.

View solution in original post

0 Likes
Micro Focus Expert
Micro Focus Expert

i've added this api to the 13.0 & 14.0 SDK code bases.

Since official release builds take time, I've made a private copy of the 13.0 build available to you on the forum

ftp://stsdkcust:LpeEFPwNMJ@emeaftp.microfocus.com/13.0/StarTeam130.zip (this is the unofficial build)

Fortunately, we had a scheduled 14.0 build today.

http://community.microfocus.com/borland/managetrack/starteam/w/wiki/620.starteam-sdk-topics-releases.aspx 

please take the one relevant to the release you use, and in case of 13.0, drop the .jar's into your sdk lib folder.

here's a small test i wrote to exercise the code and verify it's working.

Notice that I pre-populate the dot notation property, to avoid property fetch queries per CR.

Enjoy...

import com.starteam.*;

import com.starteam.ViewMember.Type.DotNotationProperty;

import com.starteam.util.DotNotation;

import com.starteam.util.SortCompare;

public static class DotNotationComparer implements SortCompare {

public int compare(Object a, Object b) {

ViewMember va = (ViewMember)a;

ViewMember vb = (ViewMember)b;

DotNotation dna = va.getDotNotation();

DotNotation dnb = vb.getDotNotation();

return dna.compareTo(dnb);

}

}

public void test() {

Server s = new Server("localhost", 49201);

s.logOn("Administrator", "Administrator");

ChangeRequest.Type crTyp = s.getTypes().CHANGE_REQUEST;

Project p = s.findProject("StarDraw");

View v = p.getDefaultView();

ViewMemberCollection vmc = v.getViewMembers(s.getTypes().CHANGE_REQUEST);

vmc.getCache().populate(new PropertyCollection(crTyp.getProperties().find(DotNotationProperty.NAME)));

ViewMember[] mm = vmc.sort(new DotNotationComparer());

for (int i = 0; i < mm.length; i++)

System.out.println(mm.getVMID() + " " + mm.getDotNotation());

s.disconnect();

}

}

View solution in original post

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

we haven't provided an api to do so. it didn't come up as a requirement.

you'll have to grab the underlying array, copy it into your own java.util.Collection, and then run SortCompare on that by dot notation.

View solution in original post

0 Likes
Micro Focus Expert
Micro Focus Expert

i've added this api to the 13.0 & 14.0 SDK code bases.

Since official release builds take time, I've made a private copy of the 13.0 build available to you on the forum

ftp://stsdkcust:LpeEFPwNMJ@emeaftp.microfocus.com/13.0/StarTeam130.zip (this is the unofficial build)

Fortunately, we had a scheduled 14.0 build today.

http://community.microfocus.com/borland/managetrack/starteam/w/wiki/620.starteam-sdk-topics-releases.aspx 

please take the one relevant to the release you use, and in case of 13.0, drop the .jar's into your sdk lib folder.

here's a small test i wrote to exercise the code and verify it's working.

Notice that I pre-populate the dot notation property, to avoid property fetch queries per CR.

Enjoy...

import com.starteam.*;

import com.starteam.ViewMember.Type.DotNotationProperty;

import com.starteam.util.DotNotation;

import com.starteam.util.SortCompare;

public static class DotNotationComparer implements SortCompare {

public int compare(Object a, Object b) {

ViewMember va = (ViewMember)a;

ViewMember vb = (ViewMember)b;

DotNotation dna = va.getDotNotation();

DotNotation dnb = vb.getDotNotation();

return dna.compareTo(dnb);

}

}

public void test() {

Server s = new Server("localhost", 49201);

s.logOn("Administrator", "Administrator");

ChangeRequest.Type crTyp = s.getTypes().CHANGE_REQUEST;

Project p = s.findProject("StarDraw");

View v = p.getDefaultView();

ViewMemberCollection vmc = v.getViewMembers(s.getTypes().CHANGE_REQUEST);

vmc.getCache().populate(new PropertyCollection(crTyp.getProperties().find(DotNotationProperty.NAME)));

ViewMember[] mm = vmc.sort(new DotNotationComparer());

for (int i = 0; i < mm.length; i++)

System.out.println(mm.getVMID() + " " + mm.getDotNotation());

s.disconnect();

}

}

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.