org.apache.commons.lang3.builder.CompareToBuilder Java Examples

The following examples show how to use org.apache.commons.lang3.builder.CompareToBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GbGradebookData.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private List<String[]> courseGrades() {
	final List<String[]> result = new ArrayList<>();

	final Map<String, Double> gradeMap = this.settings.getSelectedGradingScaleBottomPercents();
	final List<String> ascendingGrades = new ArrayList<>(gradeMap.keySet());
	ascendingGrades.sort(new Comparator<String>() {
		@Override
		public int compare(final String a, final String b) {
			return new CompareToBuilder()
					.append(gradeMap.get(a), gradeMap.get(b))
					.toComparison();
		}
	});

	for (final GbStudentGradeInfo studentGradeInfo : studentGradeInfoList) {
		result.add(getCourseGradeData(studentGradeInfo.getCourseGrade(), courseGradeMap));
	}

	return result;
}
 
Example #2
Source File: CourseGradeComparator.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) {
	final CourseGrade cg1 = g1.getCourseGrade().getCourseGrade();
	final CourseGrade cg2 = g2.getCourseGrade().getCourseGrade();

	String letterGrade1 = cg1.getMappedGrade();
	if (cg1.getEnteredGrade() != null) {
		letterGrade1 = cg1.getEnteredGrade();
	}
	String letterGrade2 = cg2.getMappedGrade();
	if (cg2.getEnteredGrade() != null) {
		letterGrade2 = cg2.getEnteredGrade();
	}

	final int gradeIndex1 = this.ascendingGrades.indexOf(letterGrade1);
	final int gradeIndex2 = this.ascendingGrades.indexOf(letterGrade2);

	final Double calculatedGrade1 = cg1.getCalculatedGrade() == null ? null : Double.valueOf(cg1.getCalculatedGrade());
	final Double calculatedGrade2 = cg2.getCalculatedGrade() == null ? null : Double.valueOf(cg2.getCalculatedGrade());

	return new CompareToBuilder()
			.append(gradeIndex1, gradeIndex2)
			.append(calculatedGrade1, calculatedGrade2)
			.toComparison();
}
 
Example #3
Source File: FirstNameComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compare(final User u1, final User u2) {
	this.collator.setStrength(Collator.PRIMARY);
	return new CompareToBuilder()
			.append(u1.getFirstName(), u2.getFirstName(), this.collator)
			.append(u1.getLastName(), u2.getLastName(), this.collator)
			.toComparison();
}
 
Example #4
Source File: ConfigurationManager.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
static Map<ConfigurationKeys.SettingCategory, List<Configuration>> union(ConfigurationPathLevel... levels) {
    List<Configuration> configurations = Arrays.stream(levels)
        .sorted(ConfigurationPathLevel.COMPARATOR.reversed())
        .flatMap(l -> ConfigurationKeys.byPathLevel(l).stream().map(mapEmptyKeys(l)))
        .sorted((c1, c2) -> new CompareToBuilder().append(c2.getConfigurationPathLevel(), c1.getConfigurationPathLevel()).append(c1.getConfigurationKey(), c2.getConfigurationKey()).toComparison())
        .collect(ArrayList::new, (List<Configuration> list, Configuration conf) -> {
            int existing = (int) list.stream().filter(c -> c.getConfigurationKey() == conf.getConfigurationKey()).count();
            if (existing == 0) {
                list.add(conf);
            }
        }, (l1, l2) -> {
        });
    return configurations.stream().collect(groupByCategory());
}
 
Example #5
Source File: ProcessedGradeItem.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compareTo(final Object o) {
	// sort by title then type order as above
	final ProcessedGradeItem other = (ProcessedGradeItem) o;
	return new CompareToBuilder()
			.append(this.itemTitle, other.itemTitle)
			.append(this.type.ordinal(), other.type.ordinal())
			.toComparison();
}
 
Example #6
Source File: GbGroup.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compareTo(final GbGroup other) {
	return new CompareToBuilder()
			.append(this.title, other.getTitle())
			.append(this.type, other.getType())
			.toComparison();

}
 
Example #7
Source File: ContainerID.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(final ContainerID that) {
  Preconditions.checkNotNull(that);
  return new CompareToBuilder()
      .append(this.getId(), that.getId())
      .build();
}
 
Example #8
Source File: LastNameComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compare(final User u1, final User u2) {
	this.collator.setStrength(Collator.PRIMARY);
	return new CompareToBuilder()
			.append(u1.getLastName(), u2.getLastName(), this.collator)
			.append(u1.getFirstName(), u2.getFirstName(), this.collator)
			.toComparison();
}
 
Example #9
Source File: GroupBy.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WiFiDetail lhs, WiFiDetail rhs) {
    Locale locale = Locale.getDefault();
    return new CompareToBuilder()
        .append(lhs.getSSID().toUpperCase(locale), rhs.getSSID().toUpperCase(locale))
        .toComparison();
}
 
Example #10
Source File: GroupBy.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WiFiDetail lhs, WiFiDetail rhs) {
    Locale locale = Locale.getDefault();
    return new CompareToBuilder()
        .append(lhs.getWiFiSignal().getPrimaryWiFiChannel().getChannel(), rhs.getWiFiSignal().getPrimaryWiFiChannel().getChannel())
        .append(rhs.getWiFiSignal().getLevel(), lhs.getWiFiSignal().getLevel())
        .append(lhs.getSSID().toUpperCase(locale), rhs.getSSID().toUpperCase(locale))
        .append(lhs.getBSSID().toUpperCase(locale), rhs.getBSSID().toUpperCase(locale))
        .toComparison();
}
 
Example #11
Source File: WiFiDetail.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(@NonNull WiFiDetail another) {
    return new CompareToBuilder()
        .append(getSSID(), another.getSSID())
        .append(getBSSID(), another.getBSSID())
        .toComparison();
}
 
Example #12
Source File: SortBy.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WiFiDetail lhs, WiFiDetail rhs) {
    Locale locale = Locale.getDefault();
    return new CompareToBuilder()
        .append(rhs.getWiFiSignal().getLevel(), lhs.getWiFiSignal().getLevel())
        .append(lhs.getSSID().toUpperCase(locale), rhs.getSSID().toUpperCase(locale))
        .append(lhs.getBSSID().toUpperCase(locale), rhs.getBSSID().toUpperCase(locale))
        .toComparison();
}
 
Example #13
Source File: SortBy.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WiFiDetail lhs, WiFiDetail rhs) {
    Locale locale = Locale.getDefault();
    return new CompareToBuilder()
        .append(lhs.getSSID().toUpperCase(locale), rhs.getSSID().toUpperCase(locale))
        .append(rhs.getWiFiSignal().getLevel(), lhs.getWiFiSignal().getLevel())
        .append(lhs.getBSSID().toUpperCase(locale), rhs.getBSSID().toUpperCase(locale))
        .toComparison();
}
 
Example #14
Source File: SortBy.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WiFiDetail lhs, WiFiDetail rhs) {
    Locale locale = Locale.getDefault();
    return new CompareToBuilder()
        .append(lhs.getWiFiSignal().getPrimaryWiFiChannel().getChannel(), rhs.getWiFiSignal().getPrimaryWiFiChannel().getChannel())
        .append(rhs.getWiFiSignal().getLevel(), lhs.getWiFiSignal().getLevel())
        .append(lhs.getSSID().toUpperCase(locale), rhs.getSSID().toUpperCase(locale))
        .append(lhs.getBSSID().toUpperCase(locale), rhs.getBSSID().toUpperCase(locale))
        .toComparison();
}
 
Example #15
Source File: CourseGradeComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public CourseGradeComparator(final GradebookInformation gradebookInformation) {
	final Map<String, Double> gradeMap = gradebookInformation.getSelectedGradingScaleBottomPercents();
	this.ascendingGrades = new ArrayList<>(gradeMap.keySet());
	this.ascendingGrades.sort(new Comparator<String>() {
		@Override
		public int compare(final String a, final String b) {
			return new CompareToBuilder()
					.append(gradeMap.get(a), gradeMap.get(b))
					.toComparison();
		}
	});
}
 
Example #16
Source File: GroupBy.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WiFiDetail lhs, WiFiDetail rhs) {
    Locale locale = Locale.getDefault();
    return new CompareToBuilder()
        .append(lhs.getSSID().toUpperCase(locale), rhs.getSSID().toUpperCase(locale))
        .append(rhs.getWiFiSignal().getLevel(), lhs.getWiFiSignal().getLevel())
        .append(lhs.getBSSID().toUpperCase(locale), rhs.getBSSID().toUpperCase(locale))
        .toComparison();
}
 
Example #17
Source File: CategorySubtotalComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) {

	final Double subtotal1 = g1.getCategoryAverages().get(this.categoryId);
	final Double subtotal2 = g2.getCategoryAverages().get(this.categoryId);

	return new CompareToBuilder().append(subtotal1, subtotal2).toComparison();
}
 
Example #18
Source File: GbGroup.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compareTo(final GbGroup other) {
	return new CompareToBuilder()
			.append(this.title, other.getTitle())
			.append(this.type, other.getType())
			.toComparison();

}
 
Example #19
Source File: FeedEntryStatusDAO.java    From commafeed with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(FeedEntryStatus o1, FeedEntryStatus o2) {
	CompareToBuilder builder = new CompareToBuilder();
	builder.append(o2.getEntryUpdated(), o1.getEntryUpdated());
	builder.append(o2.getId(), o1.getId());
	return builder.toComparison();
}
 
Example #20
Source File: EnrollmentDecorator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static final Comparator<EnrollmentDecorator> getNameComparator(final boolean sortAscending) {
    return new Comparator<EnrollmentDecorator>() {
        private final Collator collator = Collator.getInstance();        	
        private int compareUsers(final User u1, final User u2) {
    	    this.collator.setStrength(Collator.PRIMARY);
    	    return new CompareToBuilder()
    		        .append(u1.getSortName(), u2.getSortName(), this.collator)        				
    		        .toComparison();
        }
        public int compare(EnrollmentDecorator enr1, EnrollmentDecorator enr2) {
            int comparison = compareUsers(enr1.getUser(), enr2.getUser());
            return sortAscending ? comparison : (-1 * comparison);
        }
    };
}
 
Example #21
Source File: EnrollmentDecorator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static final Comparator<EnrollmentDecorator> getNameComparator(final boolean sortAscending) {
    return new Comparator<EnrollmentDecorator>() {
        private final Collator collator = Collator.getInstance();        	
        private int compareUsers(final User u1, final User u2) {
    	    this.collator.setStrength(Collator.PRIMARY);
    	    return new CompareToBuilder()
    		        .append(u1.getSortName(), u2.getSortName(), this.collator)        				
    		        .toComparison();
        }
        public int compare(EnrollmentDecorator enr1, EnrollmentDecorator enr2) {
            int comparison = compareUsers(enr1.getUser(), enr2.getUser());
            return sortAscending ? comparison : (-1 * comparison);
        }
    };
}
 
Example #22
Source File: AnnotationSidebarRegistryImpl.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a comparator that sorts first by the order, if specified, then by the display
 * name to break ties. It is assumed that the compared elements are all non-null
 * @return The comparator
 */
private Comparator<AnnotationSidebarFactory> buildComparator()
{
    return (asf1, asf2) -> new CompareToBuilder()
            .appendSuper(AnnotationAwareOrderComparator.INSTANCE.compare(asf1, asf2))
            .append(asf1.getDisplayName(), asf2.getDisplayName())
            .toComparison();
}
 
Example #23
Source File: RowIdImpl.java    From jackcess with Apache License 2.0 5 votes vote down vote up
public int compareTo(RowIdImpl other) {
  return new CompareToBuilder()
    .append(getType(), other.getType())
    .append(getPageNumber(), other.getPageNumber())
    .append(getRowNumber(), other.getRowNumber())
    .toComparison();
}
 
Example #24
Source File: LastNameComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compare(final User u1, final User u2) {
	this.collator.setStrength(Collator.PRIMARY);
	return new CompareToBuilder()
			.append(u1.getLastName(), u2.getLastName(), this.collator)
			.append(u1.getFirstName(), u2.getFirstName(), this.collator)
			.toComparison();
}
 
Example #25
Source File: ObjectDiffUtil.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(Change change) {
    return new CompareToBuilder()
        .append(propertyName, change.propertyName)
        .append(state.ordinal(), change.state.ordinal())
        .append(oldValue, change.oldValue)
        .append(newValue, change.newValue).toComparison();
}
 
Example #26
Source File: DefaultValidationNotificationService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int compareTo( @NotNull MessagePair other )
{
    return new CompareToBuilder()
        .append( this.result, other.result )
        .append( this.template, other.template )
        .build();
}
 
Example #27
Source File: TimeSumsHolder.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(TimeSumsHolder another) {
	if (another == null) {
		return 1;
	}
	return new CompareToBuilder()
		.append(getMonth(), another.getMonth())
		.append(getWeek(), another.getWeek())
		.append(getDay(), another.getDay())
		.append(getTask(), another.getTask())
		.toComparison();
}
 
Example #28
Source File: RatingService.java    From ACManager with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(Team o) {
    return new CompareToBuilder()
            .append(rank, o.rank)
            .append(score, o.score)
            .toComparison();
}
 
Example #29
Source File: Contest.java    From ACManager with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(Contest o) {
    return new CompareToBuilder()
            .append(endTime, o.endTime)
            .append(startTime, o.startTime)
            .append(id, o.id)
            .toComparison();
}
 
Example #30
Source File: GbGradeInfo.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Only compares grades
 */
@Override
public int compareTo(final GbGradeInfo o) {
	return new CompareToBuilder()
			.append(this.grade, o.getGrade())
			.toComparison();

}