Java Code Examples for edu.emory.mathcs.backport.java.util.Collections#sort()

The following examples show how to use edu.emory.mathcs.backport.java.util.Collections#sort() . 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: SprintBacklogLogic.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 根據 story column 的值來排序
 * 
 * @param stories
 * @param sortedColumn
 * @return sorted stories
 */
private ArrayList<StoryObject> sort(ArrayList<StoryObject> stories,
		String sortedColumn) {
	if (sortedColumn.equals("EST")) {
		Collections.sort(stories, new StoryComparator(
				StoryComparator.TYPE_EST));
	} else if (sortedColumn.equals("IMP")) {
		Collections.sort(stories, new StoryComparator(
				StoryComparator.TYPE_IMP));
	} else if (sortedColumn.equals("VAL")) {
		Collections.sort(stories, new StoryComparator(
				StoryComparator.TYPE_VAL));
	} else {
		Collections.sort(stories, new StoryComparator(
				StoryComparator.TYPE_ID));
	}
	return stories;
}
 
Example 2
Source File: PlantRenderer.java    From Java2PlantUML with Apache License 2.0 6 votes vote down vote up
private void renderClassMembers(StringBuilder sb, Class<?> aClass) {
    List<String> fields = new ArrayList<>();
    List<String> methods = new ArrayList<>();
    List<String> constructors = new ArrayList<>();

    addMembers(aClass.getDeclaredFields(), fields);
    addMembers(aClass.getDeclaredConstructors(), constructors);
    addMembers(aClass.getDeclaredMethods(), methods);

    Collections.sort(fields);
    Collections.sort(methods);
    Collections.sort(constructors);

    for (String field : fields) {
        sb.append(field + "\n");
    }
    sb.append("--\n");
    for (String constructor : constructors) {
        sb.append(constructor + "\n");
    }
    for (String method : methods) {
        sb.append(method + "\n");
    }
}
 
Example 3
Source File: PostProcessorFactory.java    From beanmother with Apache License 2.0 6 votes vote down vote up
/**
 * Get a sorted PostProcessors by generic type
 * @param targetType the generic type of a registered PostProcessor.
 * @param <T> the type.
 * @return the List of PostProcessor
 */
@SuppressWarnings("unchecked")
public <T> List<PostProcessor<T>> get(Class<T> targetType) {
    List<PostProcessor<T>> selected = new ArrayList<>();

    for (PostProcessor postProcessor : postProcessors) {
        Type type = postProcessor.getTargetClass();
        if (TypeToken.of(targetType).isSubtypeOf(TypeToken.of(type))) {
            selected.add(postProcessor);
        }
    }

    Collections.sort(selected);

    return selected;
}
 
Example 4
Source File: Issue.java    From onedev with MIT License 6 votes vote down vote up
public List<RevCommit> getCommits() {
	if (commits == null) {
		commits = new ArrayList<>();
		CommitInfoManager commitInfoManager = OneDev.getInstance(CommitInfoManager.class); 
		for (ObjectId commitId: commitInfoManager.getFixCommits(getProject(), getNumber())) {
			RevCommit commit = getProject().getRevCommit(commitId, false);
			if (commit != null)
				commits.add(commit);
		}
		Collections.sort(commits, new Comparator<RevCommit>() {

			@Override
			public int compare(RevCommit o1, RevCommit o2) {
				return o2.getCommitTime() - o1.getCommitTime();
			}
			
		});
	}
	return commits;		
}
 
Example 5
Source File: AssociationStringSimilarity.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
public Collection<String> getAssociationsAsStrings(Topic t) throws TopicMapException {
    Collection<Association> as = t.getAssociations();
    ArrayList<String> asStr = new ArrayList();
    
    for(Association a : as) {
        StringBuilder sb = new StringBuilder("");
        sb.append(getAsString(a.getType()));
        sb.append(TOPIC_DELIMITER);
        Collection<Topic> roles = a.getRoles();
        ArrayList<Topic> sortedRoles = new ArrayList();
        sortedRoles.addAll(roles);
        Collections.sort(sortedRoles, new TopicStringComparator());
        
        boolean found = false;
        for(Topic r : sortedRoles) {
            Topic p = a.getPlayer(r);
            if(!found && p.mergesWithTopic(t)) {
                found = true;
                continue;
            }
            sb.append(getAsString(r));
            sb.append(TOPIC_DELIMITER);
            sb.append(getAsString(p));
            sb.append(TOPIC_DELIMITER);
        }
        asStr.add(sb.toString());
    }
    Collections.sort(asStr);
    
    return asStr;
}
 
Example 6
Source File: DefaultEditSupportRegistry.java    From onedev with MIT License 5 votes vote down vote up
@Inject
public DefaultEditSupportRegistry(Set<EditSupport> editSupports) {
	this.editSupports = new ArrayList<EditSupport>(editSupports);
	Collections.sort(this.editSupports, new Comparator<EditSupport>() {

		@Override
		public int compare(EditSupport o1, EditSupport o2) {
			return o1.getPriority() - o2.getPriority();
		}
		
	});
}
 
Example 7
Source File: RepositoryEntriesConfirmationEmailBuilder.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the mail body by using for each type different translation key, and passing the variables into the translated string. <br/>
 * The variables is an array of parameters specific to each type. Please use exactly this order while defining new translation keys. <br/>
 * <p>
 * variables[0] //number of months to filter inactive repository entries <br/>
 * variables[1] //number of days till when inactive repository entries will be deleted <br/>
 */
@Override
protected ConfirmationMailBody getMailBody(Locale recipientsLocale, RepositoryEntriesConfirmationInfo repositoryEntriesConfirmationInfo) {
    String content;
    String greeting;
    String greetingFrom;
    String footer;

    Translator translator = mailBuilderCommons.getEmailTranslator(ConfirmationMailBody.class, recipientsLocale);

    String[] variables = new String[] { String.valueOf(repositoryEntriesConfirmationInfo.getNumberOfMonths()),
            String.valueOf(repositoryEntriesConfirmationInfo.getNumberOfDays()) };

    // choose the right translation key, the variables are the same for each template
    if (RepositoryEntriesConfirmationInfo.REPOSITORY_ENTRIES_CONFIRMATION_TYPE.DELETE_REPOSITORY_ENTRIES.equals(repositoryEntriesConfirmationInfo
            .getRepositoryEntriesConfirmationType())) {
        content = translator.translate("mail.body.confirmation.delete.repository.entries", variables);
    } else {
        content = "INVALID CONFIRMATION CONTENT"; // UNKNOWN CONFIRMATION TYPE
    }

    greeting = translator.translate("mail.body.greeting");
    greetingFrom = translator.translate("mail.body.greeting.from");

    String olatUrlAsHtmlHref = mailBuilderCommons.getOlatUrlAsHtmlHref();
    footer = translator.translate("mail.footer.confirmation", getStringArray(olatUrlAsHtmlHref));
    List<String> repositoryEntries = getRepositoryEntries(repositoryEntriesConfirmationInfo.getRepositoryEntries(), translator);
    Collections.sort(repositoryEntries);
    return new ResourceEntriesConfirmationMailBody(content, greeting, greetingFrom, footer, repositoryEntries);
}
 
Example 8
Source File: GroupsConfirmationEmailBuilder.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the mail body by using for each type different translation key, and passing the variables into the translated string. <br/>
 * The variables is an array of parameters specific to each type. Please use exactly this order while defining new translation keys. <br/>
 * <p>
 * variables[0] //number of months to filter inactive groups <br/>
 * variables[1] //number of days till when inactive groups will be deleted <br/>
 */
@Override
protected ResourceEntriesConfirmationMailBody getMailBody(Locale recipientsLocale, GroupsConfirmationInfo groupsConfirmationInfo) {
    String content;
    String greeting;
    String greetingFrom;
    String footer;

    Translator translator = mailBuilderCommons.getEmailTranslator(ConfirmationMailBody.class, recipientsLocale);

    String[] variables = new String[] { String.valueOf(groupsConfirmationInfo.getNumberOfMonths()), String.valueOf(groupsConfirmationInfo.getNumberOfDays()) };

    // choose the right translation key, the variables are the same for each template
    if (GroupsConfirmationInfo.GROUPS_CONFIRMATION_TYPE.DELETE_GROUPS.equals(groupsConfirmationInfo.getGroupsConfirmationType())) {
        content = translator.translate("mail.body.confirmation.delete.groups", variables);
    } else {
        content = "INVALID CONFIRMATION CONTENT"; // UNKNOWN CONFIRMATION TYPE
    }

    greeting = translator.translate("mail.body.greeting");
    greetingFrom = translator.translate("mail.body.greeting.from");

    String olatUrlAsHtmlHref = mailBuilderCommons.getOlatUrlAsHtmlHref();
    footer = translator.translate("mail.footer.confirmation", getStringArray(olatUrlAsHtmlHref));
    List<String> groupEntries = getGroupEntries(groupsConfirmationInfo.getGroups(), translator);
    Collections.sort(groupEntries);
    return new ResourceEntriesConfirmationMailBody(content, greeting, greetingFrom, footer, groupEntries);
}
 
Example 9
Source File: CampusCourseLearnServiceImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public List<SapCampusCourseTo> getCoursesWhichCouldBeOpened(Identity identity, SapOlatUser.SapUserType userType) {
    List<SapCampusCourseTo> courseList = new ArrayList<SapCampusCourseTo>();
    Set<Course> sapCampusCourses = campusCourseCoreService.getCampusCoursesWithResourceableId(identity, userType);
    for (Course sapCampusCourse : sapCampusCourses) {
        courseList.add(new SapCampusCourseTo(sapCampusCourse.getTitle(), sapCampusCourse.getId(), sapCampusCourse.getResourceableId()));
    }
    Collections.sort(courseList);
    return courseList;
}
 
Example 10
Source File: CampusCourseLearnServiceImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public List<SapCampusCourseTo> getCoursesWhichCouldBeCreated(Identity identity, SapOlatUser.SapUserType userType) {
    List<SapCampusCourseTo> courseList = new ArrayList<SapCampusCourseTo>();
    Set<Course> sapCampusCourses = campusCourseCoreService.getCampusCoursesWithoutResourceableId(identity, userType);
    for (Course sapCampusCourse : sapCampusCourses) {
        courseList.add(new SapCampusCourseTo(sapCampusCourse.getTitle(), sapCampusCourse.getId(), null));
    }
    Collections.sort(courseList);
    return courseList;
}
 
Example 11
Source File: PlantRenderer.java    From Java2PlantUML with Apache License 2.0 5 votes vote down vote up
private void sortRelations(ArrayList<Relation> relations) {
    Collections.sort(relations, new Comparator<Relation>() {
        @Override
        public int compare(Relation o1, Relation o2) {
            int result = o1.getClass().equals(o2.getClass())
                    ? o1.getFromType().getName().compareTo(o1.getFromType().getName())
                    : o1.getClass().getName().compareTo(o2.getClass().getName());
            return result;
        }
    });
}
 
Example 12
Source File: ProjectDependency.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
private static List<String> getProjectChoices() {
	List<String> choices = new ArrayList<>();
	Project project = ((ProjectPage)WicketUtils.getPage()).getProject();
	for (Project each: OneDev.getInstance(ProjectManager.class).getPermittedProjects(new AccessProject())) {
		if (!each.equals(project))
			choices.add(each.getName());
	}
	
	Collections.sort(choices);
	
	return choices;
}
 
Example 13
Source File: OrderBy.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResultIterator queryIterator(QueryContext context, ResultRow input) throws QueryException {
    ArrayList<ResultRow> res=directive.query(context, input);
    Collections.sort(res, new Comparator<ResultRow>(){
        public int compare(ResultRow o1, ResultRow o2) {
            Object v1=o1.getActiveValue();
            Object v2=o2.getActiveValue();
            return comparator.compare(v1, v2);
        }
    });
    return new ResultIterator.ListIterator(res);
}
 
Example 14
Source File: ScriptingValue.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<String> getValue() {
	Map<String, Object> variables = new HashMap<>();
	variables.put("build", Build.get());
	List<String> values = new ArrayList<>();
	Object result = GroovyUtils.evalScriptByName(scriptName, variables);
	if (result instanceof Collection) {
		values.addAll((Collection<? extends String>) result);
		Collections.sort(values);
	} else if (result != null) {
		values.add(result.toString());
	}
	return values;
}
 
Example 15
Source File: AllGroups.java    From onedev with MIT License 5 votes vote down vote up
@Override
public List<Group> getChoices(boolean allPossible) {
	List<Group> groups = OneDev.getInstance(GroupManager.class).query();
	Collections.sort(groups, new Comparator<Group>() {

		@Override
		public int compare(Group o1, Group o2) {
			return o1.getName().compareTo(o2.getName());
		}
		
	});
	return groups;
}
 
Example 16
Source File: ChoiceInput.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<String> convertToStrings(InputSpec inputSpec, Object value) {
	List<String> strings = new ArrayList<>();
	if (inputSpec.isAllowMultiple()) {
		if (inputSpec.checkListElements(value, String.class))
			strings.addAll((List<String>) value);
		Collections.sort(strings);
	} else if (value instanceof String) {
		strings.add((String) value);
	} 
	return strings;
}
 
Example 17
Source File: ServerStatistics.java    From iaf with Apache License 2.0 4 votes vote down vote up
@GET
@PermitAll
@Path("/server/info")
@Produces(MediaType.APPLICATION_JSON)
public Response getServerInformation() throws ApiException {
	Map<String, Object> returnMap = new HashMap<String, Object>();
	List<Object> configurations = new ArrayList<Object>();

	AppConstants appConstants = AppConstants.getInstance();

	for (Configuration configuration : getIbisManager().getConfigurations()) {
		Map<String, Object> cfg = new HashMap<String, Object>();
		cfg.put("name", configuration.getName());
		cfg.put("version", configuration.getVersion());
		cfg.put("stubbed", configuration.isStubbed());

		cfg.put("type", configuration.getClassLoaderType());
		if(configuration.getConfigurationException() != null) {
			cfg.put("exception", configuration.getConfigurationException().getMessage());
		}

		ClassLoader classLoader = configuration.getClassLoader();
		if(classLoader instanceof DatabaseClassLoader) {
			cfg.put("filename", ((DatabaseClassLoader) classLoader).getFileName());
			cfg.put("created", ((DatabaseClassLoader) classLoader).getCreationDate());
			cfg.put("user", ((DatabaseClassLoader) classLoader).getUser());
		}

		String parentConfig = AppConstants.getInstance().getString("configurations." + configuration.getName() + ".parentConfig", null);
		if(parentConfig != null)
			cfg.put("parent", parentConfig);

			configurations.add(cfg);
	}

	//TODO Replace this with java.util.Collections!
	Collections.sort(configurations, new Comparator<Map<String, String>>() {
		@Override
		public int compare(Map<String, String> lhs, Map<String, String> rhs) {
			String name1 = lhs.get("name");
			String name2 = rhs.get("name");
			return name1.startsWith("IAF_") ? -1 : name2.startsWith("IAF_") ? 1 : name1.compareTo(name2);
		}
	});

	returnMap.put("configurations", configurations);

	Map<String, Object> framework = new HashMap<String, Object>(2);
	framework.put("name", "FF!");
	framework.put("version", appConstants.getProperty("application.version"));
	returnMap.put("framework", framework);

	Map<String, Object> instance = new HashMap<String, Object>(2);
	instance.put("version", appConstants.getProperty("instance.version"));
	instance.put("name", getIbisContext().getApplicationName());
	returnMap.put("instance", instance);

	String dtapStage = appConstants.getProperty("dtap.stage");
	returnMap.put("dtap.stage", dtapStage);
	String dtapSide = appConstants.getProperty("dtap.side");
	returnMap.put("dtap.side", dtapSide);

	returnMap.put("applicationServer", servletConfig.getServletContext().getServerInfo());
	returnMap.put("javaVersion", System.getProperty("java.runtime.name") + " (" + System.getProperty("java.runtime.version") + ")");
	Map<String, Object> fileSystem = new HashMap<String, Object>(2);
	fileSystem.put("totalSpace", Misc.getFileSystemTotalSpace());
	fileSystem.put("freeSpace", Misc.getFileSystemFreeSpace());
	returnMap.put("fileSystem", fileSystem);
	returnMap.put("processMetrics", ProcessMetrics.toMap());
	Date date = new Date();
	returnMap.put("serverTime", date.getTime());
	returnMap.put("machineName" , Misc.getHostname());
	returnMap.put("uptime", getIbisContext().getUptimeDate());

	return Response.status(Response.Status.OK).entity(returnMap).build();
}
 
Example 18
Source File: JobExecutor.java    From onedev with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
private static List<InputSuggestion> suggestJobNames(String matchWith) {
	List<String> jobNames = new ArrayList<>(OneDev.getInstance(BuildManager.class).getJobNames(null));
	Collections.sort(jobNames);
	return SuggestionUtils.suggest(jobNames, matchWith);
}
 
Example 19
Source File: JobPrivilege.java    From onedev with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
private static List<InputSuggestion> suggestJobNames(String matchWith) {
	List<String> jobNames = new ArrayList<>(OneDev.getInstance(BuildManager.class).getJobNames(null));
	Collections.sort(jobNames);
	return SuggestionUtils.suggest(jobNames, matchWith);
}
 
Example 20
Source File: SuggestionUtils.java    From onedev with MIT License 4 votes vote down vote up
public static List<InputSuggestion> suggestJobs(Project project, String matchWith) {
	List<String> jobNames = new ArrayList<>(OneDev.getInstance(BuildManager.class)
			.getAccessibleJobNames(project).get(project));
	Collections.sort(jobNames);
	return suggest(jobNames, matchWith);
}