List of usage examples for java.lang Boolean compareTo
public int compareTo(Boolean b)
From source file:org.etudes.mneme.impl.SubmissionServiceImpl.java
/** * Get the submissions to the assessment made by all users. * //from w ww. j a va 2s. c om * @param assessment * The assessment. * @param sort * The sort. * @param question * An optional question, to use for sort-by-score (the score would be for this question in the submission, not the overall). * @param filterByPermission * if true, return submissions only from users who are currently permitted to submit, otherwise return any submissions found. * @return A List<Submission> of the submissions for the assessment. */ protected List<SubmissionImpl> getAssessmentSubmissions(Assessment assessment, final FindAssessmentSubmissionsSort sort, final Question question, boolean filterByPermission) { // collect the submissions to this assessment List<SubmissionImpl> rv = this.storage.getAssessmentSubmissions(assessment); // get all possible users who can submit Set<String> userIds = this.securityService.getUsersIsAllowed(MnemeService.SUBMIT_PERMISSION, assessment.getContext()); // filter out any userIds that are not currently defined List<User> users = this.userDirectoryService.getUsers(userIds); userIds.clear(); for (User user : users) { userIds.add(user.getId()); } // if any user is not represented in the submissions we found, add an empty submission for (String userId : userIds) { boolean found = false; for (Submission s : rv) { if (s.getUserId().equals(userId)) { found = true; break; } } if (!found) { SubmissionImpl s = this.getPhantomSubmission(userId, assessment); rv.add(s); } } // filter out any submissions found that are not for one of the users in the userIds list (they may have lost permission) if (filterByPermission) { for (Iterator<SubmissionImpl> i = rv.iterator(); i.hasNext();) { SubmissionImpl submission = i.next(); if (!userIds.contains(submission.getUserId())) { i.remove(); } } } // for all but user name & status sorts, separate out the completed, not-started, in-progress List<SubmissionImpl> inProgress = new ArrayList<SubmissionImpl>(); List<SubmissionImpl> notStarted = new ArrayList<SubmissionImpl>(); if ((sort != FindAssessmentSubmissionsSort.userName_a) && (sort != FindAssessmentSubmissionsSort.userName_d) && (sort != FindAssessmentSubmissionsSort.status_a) && (sort != FindAssessmentSubmissionsSort.status_d)) { for (Iterator i = rv.iterator(); i.hasNext();) { SubmissionImpl submission = (SubmissionImpl) i.next(); if (!submission.getIsStarted().booleanValue()) { notStarted.add(submission); i.remove(); } else if (!submission.getIsComplete().booleanValue()) { inProgress.add(submission); i.remove(); } } } // sort - secondary sort of user name, or if primary is title, on submit date Collections.sort(rv, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; FindAssessmentSubmissionsSort secondary = null; switch (sort) { case userName_a: case userName_d: case status_a: case status_d: { String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); // Note: leave status sort ascending if (sort == FindAssessmentSubmissionsSort.userName_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.sdate_a; break; } case final_a: case final_d: { Float final0 = null; Float final1 = null; if (question != null) { Answer a0 = ((Submission) arg0).getAnswer(question); Answer a1 = ((Submission) arg1).getAnswer(question); final0 = ((a0 == null) ? Float.valueOf(0f) : a0.getTotalScore()); final1 = ((a1 == null) ? Float.valueOf(0f) : a1.getTotalScore()); } else { final0 = ((Submission) arg0).getTotalScore(); final1 = ((Submission) arg1).getTotalScore(); } // null sorts small if ((final0 == null) && (final1 == null)) { rv = 0; } else if (final0 == null) { rv = -1; } else if (final1 == null) { rv = 1; } else { rv = final0.compareTo(final1); } if (sort == FindAssessmentSubmissionsSort.final_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } case sdate_a: case sdate_d: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = date0.compareTo(date1); } if (sort == FindAssessmentSubmissionsSort.sdate_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } case evaluated_a: case evaluated_d: { Boolean evaluated0 = ((Submission) arg0).getEvaluation().getEvaluated(); Boolean evaluated1 = ((Submission) arg1).getEvaluation().getEvaluated(); rv = evaluated0.compareTo(evaluated1); if (sort == FindAssessmentSubmissionsSort.evaluated_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } case released_a: case released_d: { Boolean released0 = ((Submission) arg0).getIsReleased(); Boolean released1 = ((Submission) arg1).getIsReleased(); rv = released0.compareTo(released1); if (sort == FindAssessmentSubmissionsSort.released_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } } // secondary sort FindAssessmentSubmissionsSort third = null; if ((rv == 0) && (secondary != null)) { switch (secondary) { case userName_a: { String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); third = FindAssessmentSubmissionsSort.sdate_a; break; } case sdate_a: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } break; } } } // third sort if ((rv == 0) && (third != null)) { switch (third) { case sdate_a: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } break; } } } return rv; } }); // if we have in-progress and not-started to deal with if (!inProgress.isEmpty()) { // sort them by user name asc Collections.sort(inProgress, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); return rv; } }); rv.addAll(inProgress); } if (!notStarted.isEmpty()) { // sort them by user name asc Collections.sort(notStarted, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); return rv; } }); rv.addAll(notStarted); } return rv; }
From source file:org.kuali.rice.kew.rule.bo.RuleTemplateBo.java
/** * Returns the rule template attribute on this instance whose name matches the name of the rule template attribute * passed as a parameter, qualified by it's active state, or null if a match was not found. *//*w w w .j a v a 2s .c o m*/ private RuleTemplateAttributeBo getRuleTemplateAttribute(RuleTemplateAttributeBo ruleTemplateAttribute, Boolean active) { for (RuleTemplateAttributeBo currentRuleTemplateAttribute : getRuleTemplateAttributes()) { if (currentRuleTemplateAttribute.getRuleAttribute().getName() .equals(ruleTemplateAttribute.getRuleAttribute().getName())) { if (active == null) { return currentRuleTemplateAttribute; } else if (active.compareTo(currentRuleTemplateAttribute.getActive()) == 0) { return currentRuleTemplateAttribute; } } } return null; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.UserProfile.java
/** * Returns <code>true</code> if data to save, <code>false</code> * otherwise.//from w w w . ja va 2 s . com * * @return See above. */ boolean hasDataToSave() { saveButton.setEnabled(false); String text = loginArea.getText(); if (StringUtils.isBlank(text)) return false; text = text.trim(); ExperimenterData original = (ExperimenterData) model.getRefObject(); if (!text.equals(original.getUserName())) { saveButton.setEnabled(true); return true; } //if (selectedIndex != originalIndex) return true; if (details == null) return false; Entry<String, String> entry; Iterator<Entry<String, String>> i = details.entrySet().iterator(); String key; String value; JTextField field; String v; if (items.size() > 0) { i = details.entrySet().iterator(); while (i.hasNext()) { entry = i.next(); key = entry.getKey(); field = items.get(key); if (field != null) { v = field.getText(); if (StringUtils.isBlank(v)) { if (EditorUtil.FIRST_NAME.equals(key) || EditorUtil.LAST_NAME.equals(key)) { return false; } } } } i = details.entrySet().iterator(); while (i.hasNext()) { entry = i.next(); key = entry.getKey(); field = items.get(key); if (field != null) { v = field.getText(); if (v != null) { v = v.trim(); value = (String) entry.getValue(); if (value == null) value = ""; if (!v.equals(value)) { saveButton.setEnabled(true); return true; } } } } } Boolean b = ownerBox.isSelected(); if (b.compareTo(groupOwner) != 0) { saveButton.setEnabled(true); return true; } if (adminBox.isVisible()) { b = adminBox.isSelected(); if (b.compareTo(admin) != 0) { saveButton.setEnabled(true); return true; } } if (activeBox.isVisible()) { b = activeBox.isSelected(); if (b.compareTo(active) != 0) { saveButton.setEnabled(true); return true; } } return false; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.UserProfile.java
/** * Returns the experimenter to save./*from w ww . j av a 2s. c o m*/ * * @return See above. */ Object getExperimenterToSave() { ExperimenterData original = (ExperimenterData) model.getRefObject(); //Required fields first String v = loginArea.getText(); if (v == null || v.trim().length() == 0) showRequiredField(); JTextField f = items.get(EditorUtil.EMAIL); v = f.getText(); if (v == null || v.trim().length() == 0) v = ""; original.setEmail(v); f = items.get(EditorUtil.INSTITUTION); v = f.getText(); if (v == null) v = ""; original.setInstitution(v.trim()); f = items.get(EditorUtil.LAST_NAME); v = f.getText(); if (v == null) v = ""; original.setLastName(v.trim()); f = items.get(EditorUtil.FIRST_NAME); v = f.getText(); if (v == null) v = ""; original.setFirstName(v.trim()); f = items.get(EditorUtil.MIDDLE_NAME); v = f.getText(); if (v == null) v = ""; original.setMiddleName(v.trim()); //set the groups GroupData g = null; String value = loginArea.getText().trim(); UserCredentials uc = new UserCredentials(value, ""); Boolean b = ownerBox.isSelected(); boolean a = false; if (b.compareTo(groupOwner) != 0) { a = true; uc.setOwner(b); Object parent = model.getParentRootObject(); if (parent instanceof GroupData) { Map<GroupData, Boolean> map = new HashMap<GroupData, Boolean>(); map.put((GroupData) parent, b); uc.setGroupsOwner(map); } } if (adminBox.isVisible()) { b = adminBox.isSelected(); if (b.compareTo(admin) != 0) { a = true; uc.setAdministrator(b); } } if (activeBox.isVisible()) { b = activeBox.isSelected(); if (b.compareTo(active) != 0) { a = true; uc.setActive(b); } } if (!original.getUserName().equals(value)) a = true; //if admin if (MetadataViewerAgent.isAdministrator()) a = true; if (a) { Map<ExperimenterData, UserCredentials> m = new HashMap<ExperimenterData, UserCredentials>(); m.put(original, uc); AdminObject object = new AdminObject(g, m, AdminObject.UPDATE_EXPERIMENTER); return object; } return original;//newOne; }
From source file:org.pentaho.metadata.query.model.util.BooleanComparator.java
public int compare(Object o1, Object o2) { Boolean b1 = toBoolean(o1); Boolean b2 = toBoolean(o2);//from ww w. j a va2 s . com return b1.compareTo(b2); }
From source file:org.structr.schema.action.Function.java
private int compareBooleanBoolean(final Object o1, final Object o2) { final Boolean value1 = (Boolean) o1; final Boolean value2 = (Boolean) o2; return value1.compareTo(value2); }
From source file:org.structr.schema.action.Function.java
private int compareBooleanString(final Boolean o1, final String o2) { return o1.compareTo(Boolean.valueOf(o2)); }
From source file:org.tinymediamanager.ui.movies.MovieExtendedComparator.java
@Override public int compare(Movie movie1, Movie movie2) { int sortOrder = 0; try {/*from www. j a va2s.com*/ // try to sort the chosen column switch (sortColumn) { case TITLE: sortOrder = stringCollator.compare(movie1.getTitleSortable().toLowerCase(Locale.ROOT), movie2.getTitleSortable().toLowerCase(Locale.ROOT)); break; case SORT_TITLE: String title1 = StringUtils.isNotBlank(movie1.getSortTitle()) ? movie1.getSortTitle() : movie1.getTitleSortable(); String title2 = StringUtils.isNotBlank(movie2.getSortTitle()) ? movie2.getSortTitle() : movie2.getTitleSortable(); sortOrder = stringCollator.compare(title1.toLowerCase(Locale.ROOT), title2.toLowerCase(Locale.ROOT)); break; case YEAR: sortOrder = stringCollator.compare(movie1.getYear(), movie2.getYear()); break; case DATE_ADDED: sortOrder = movie1.getDateAdded().compareTo(movie2.getDateAdded()); break; case WATCHED: Boolean watched1 = movie1.isWatched(); Boolean watched2 = movie2.isWatched(); sortOrder = watched1.compareTo(watched2); break; case RATING: sortOrder = Float.compare(movie1.getRating(), movie2.getRating()); break; case RUNTIME: Integer runtime1 = movie1.getRuntime(); Integer runtime2 = movie2.getRuntime(); sortOrder = runtime1.compareTo(runtime2); break; case VIDEO_BITRATE: Integer videoBitrate1 = movie1.getMediaInfoVideoBitrate(); Integer videoBitrate2 = movie2.getMediaInfoVideoBitrate(); sortOrder = videoBitrate1.compareTo(videoBitrate2); break; } } catch (NullPointerException e) { // do nothing here. there could be } catch (Exception e) { LOGGER.warn(e.getMessage()); } // sort ascending or descending if (sortAscending) { return sortOrder; } else { return sortOrder * -1; } }