All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bdeploy.common.util.SortOneAsLastComparator Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
package io.bdeploy.common.util;

import java.io.Serializable;
import java.util.Comparator;

/**
 * A comparator that ensures that a given string is put at the end. All others are sorted lexicographically.
 */
public class SortOneAsLastComparator implements Comparator, Serializable {

    private static final long serialVersionUID = 1L;

    private final String name;

    /**
     * Creates a new comparator that sorts the given string as last one
     */
    public SortOneAsLastComparator(String masterName) {
        this.name = masterName;
    }

    @Override
    public int compare(String a, String b) {
        if (name.equals(a)) {
            return 1;
        } else if (name.equals(b)) {
            return -1;
        }
        return a.compareTo(b);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy