use of org.apache.commons.lang.builder.CompareToBuilder in project sonarqube by SonarSource.
the class ProjectsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String profileKey = request.mandatoryParam(PARAM_KEY);
DbSession session = dbClient.openSession(false);
try {
checkProfileExists(profileKey, session);
String selected = request.param(Param.SELECTED);
String query = request.param(PARAM_QUERY);
int pageSize = request.mandatoryParamAsInt(PARAM_PAGE_SIZE);
int page = request.mandatoryParamAsInt(PARAM_PAGE);
List<ProjectQprofileAssociationDto> projects = loadProjects(profileKey, session, selected, query);
Collections.sort(projects, new Comparator<ProjectQprofileAssociationDto>() {
@Override
public int compare(ProjectQprofileAssociationDto o1, ProjectQprofileAssociationDto o2) {
return new CompareToBuilder().append(o1.getProjectName(), o2.getProjectName()).append(o1.getProjectUuid(), o2.getProjectUuid()).toComparison();
}
});
Collection<Long> projectIds = Collections2.transform(projects, new NonNullInputFunction<ProjectQprofileAssociationDto, Long>() {
@Override
protected Long doApply(ProjectQprofileAssociationDto input) {
return input.getProjectId();
}
});
Collection<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(session, projectIds, userSession.getUserId(), UserRole.USER);
Iterable<ProjectQprofileAssociationDto> authorizedProjects = Iterables.filter(projects, new Predicate<ProjectQprofileAssociationDto>() {
@Override
public boolean apply(ProjectQprofileAssociationDto input) {
return authorizedProjectIds.contains(input.getProjectId());
}
});
Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(authorizedProjectIds.size());
List<ProjectQprofileAssociationDto> pagedAuthorizedProjects = Lists.newArrayList(authorizedProjects);
if (pagedAuthorizedProjects.size() <= paging.offset()) {
pagedAuthorizedProjects = Lists.newArrayList();
} else if (pagedAuthorizedProjects.size() > paging.pageSize()) {
int endIndex = Math.min(paging.offset() + pageSize, pagedAuthorizedProjects.size());
pagedAuthorizedProjects = pagedAuthorizedProjects.subList(paging.offset(), endIndex);
}
writeProjects(response.newJsonWriter(), pagedAuthorizedProjects, paging);
} finally {
session.close();
}
}
use of org.apache.commons.lang.builder.CompareToBuilder in project musiccabinet by hakko.
the class ArtistPlayCount method compareTo.
@Override
public int compareTo(ArtistPlayCount apc) {
CompareToBuilder ctb = new CompareToBuilder();
ctb.append(-playCount, -apc.playCount);
ctb.append(artist.getName(), apc.artist.getName());
return ctb.toComparison();
}
use of org.apache.commons.lang.builder.CompareToBuilder in project opennms by OpenNMS.
the class Service method compareTo.
public int compareTo(final ServiceTemplate obj) {
final CompareToBuilder builder = new CompareToBuilder().append(getName(), obj.getName()).append(getThreads(), obj.getThreads()).append(getPassiveServiceName(), obj.getPassiveServiceName()).append(getInterval(), obj.getInterval()).append(getStatus(), obj.getStatus());
if (obj instanceof Service) {
builder.append(getTemplateName(), ((Service) obj).getTemplateName());
}
builder.append(getParameters().toArray(OF_PARAMETERS), obj.getParameters().toArray(OF_PARAMETERS));
return builder.toComparison();
}
Aggregations