com.badlogic.gdx.utils.Sort Java Examples

The following examples show how to use com.badlogic.gdx.utils.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: FileUtils.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
/**
 * Sorts file list, using this rules: directories first, sorted using provided comparator, then files sorted using provided comparator.
 * @param files list to sort
 * @param comparator comparator used to sort files list
 * @param descending if true then sorted list will be in reversed order
 * @return sorted file list
 */
public static Array<FileHandle> sortFiles (FileHandle[] files, Comparator<FileHandle> comparator, boolean descending) {
	Array<FileHandle> directoriesList = new Array<FileHandle>();
	Array<FileHandle> filesList = new Array<FileHandle>();

	for (FileHandle f : files) {
		if (f.isDirectory()) {
			directoriesList.add(f);
		} else {
			filesList.add(f);
		}
	}

	Sort sorter = new Sort();
	sorter.sort(directoriesList, comparator);
	sorter.sort(filesList, comparator);

	if (descending) {
		directoriesList.reverse();
		filesList.reverse();
	}

	directoriesList.addAll(filesList); // combine lists
	return directoriesList;
}
 
Example #2
Source File: DialogDrawables.java    From skin-composer with MIT License 5 votes vote down vote up
/**
 * Sorts by modified date with oldest first.
 */
private void sortDrawablesOldest() {
    Sort.instance().sort(drawables, (DrawableData o1, DrawableData o2) -> {
        if (o1.file.lastModified() < o2.file.lastModified()) {
            return -1;
        } else if (o1.file.lastModified() > o2.file.lastModified()) {
            return 1;
        } else {
            return 0;
        }
    });
    refreshDrawableDisplay();
}
 
Example #3
Source File: DialogDrawables.java    From skin-composer with MIT License 5 votes vote down vote up
/**
 * Sorts by modified date with newest first.
 */
private void sortDrawablesNewest() {
    Sort.instance().sort(drawables, (DrawableData o1, DrawableData o2) -> {
        if (o1.file.lastModified() < o2.file.lastModified()) {
            return 1;
        } else if (o1.file.lastModified() > o2.file.lastModified()) {
            return -1;
        } else {
            return 0;
        }
    });
    refreshDrawableDisplay();
}
 
Example #4
Source File: DialogColors.java    From skin-composer with MIT License 5 votes vote down vote up
private void sortFontsAZ() {
    Sort.instance().sort(colors, new Comparator<ColorData>() {
        @Override
        public int compare(ColorData o1, ColorData o2) {
            return o1.toString().compareToIgnoreCase(o2.toString());
        }
    });
    refreshTable();
}
 
Example #5
Source File: DialogColors.java    From skin-composer with MIT License 5 votes vote down vote up
private void sortFontsZA() {
    Sort.instance().sort(colors, new Comparator<ColorData>() {
        @Override
        public int compare(ColorData o1, ColorData o2) {
            return o1.toString().compareToIgnoreCase(o2.toString()) * -1;
        }
    });
    refreshTable();
}
 
Example #6
Source File: DialogDrawables.java    From skin-composer with MIT License 4 votes vote down vote up
/**
 * Sorts alphabetically from A to Z.
 */
private void sortDrawablesAZ() {
    Sort.instance().sort(drawables, (DrawableData o1, DrawableData o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
    refreshDrawableDisplay();
}
 
Example #7
Source File: DialogDrawables.java    From skin-composer with MIT License 4 votes vote down vote up
/**
 * Sorts alphabetically from Z to A.
 */
private void sortDrawablesZA() {
    Sort.instance().sort(drawables, (DrawableData o1, DrawableData o2) -> o1.toString().compareToIgnoreCase(o2.toString()) * -1);
    refreshDrawableDisplay();
}
 
Example #8
Source File: CommonUtils.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
@Override
protected Sort newObjectInternal() {
    return new Sort();
}