Example usage for java.util Comparator Comparator

List of usage examples for java.util Comparator Comparator

Introduction

In this page you can find the example usage for java.util Comparator Comparator.

Prototype

Comparator

Source Link

Usage

From source file:com.github.qwazer.markdown.confluence.gradle.plugin.ConfluenceGradleTask.java

protected static void validateNoDuplicates(Collection<ConfluenceConfig.Page> pages) {

    Set<ConfluenceConfig.Page> set = new TreeSet<>(new Comparator<ConfluenceConfig.Page>() {
        @Override/*from ww w  . j  a  va  2 s .  c o  m*/
        public int compare(ConfluenceConfig.Page o1, ConfluenceConfig.Page o2) {
            return o1.getTitle().compareTo(o2.getTitle());
        }
    });

    set.addAll(pages);

    if (set.size() < pages.size()) {
        throw new IllegalArgumentException("Found duplicate pageTitle in confluence pages");
    }
}

From source file:AnimationTester.java

public void run() {
    Comparator<Double> comp = new Comparator<Double>() {
        public int compare(Double d1, Double d2) {
            try {
                Thread.sleep(100);
            } catch (Exception exception) {
                System.out.println(exception);
            }/*from   w  ww.  j a  v  a 2 s.com*/
            panel.setValues(values, d1, d2);
            return d1.compareTo(d2);
        }
    };
    Collections.sort(Arrays.asList(values), comp);
    panel.setValues(values, null, null);
}

From source file:net.chrissearle.flickrvote.web.common.ChallengeListAction.java

public void prepare() throws Exception {
    challenges = new ArrayList<Challenge>();

    for (ChallengeSummary challenge : challengeService.getChallengesByType(ChallengeType.CLOSED)) {
        challenges.add(new DisplayChallengeSummary(challenge));
    }//from w  w w  . j a  v  a2 s  . c o m

    Collections.sort(challenges, new Comparator<Challenge>() {
        public int compare(Challenge o1, Challenge o2) {
            return o2.getChallengeTag().compareTo(o1.getChallengeTag());
        }
    });
}

From source file:com.shaie.browze.model.Tree.java

public Tree(PathAndNode pathAndNode, List<Tree> children, Stat stat) {
    if (Strings.isNullOrEmpty(pathAndNode.getNode())) {
        // root node
        this.label = pathAndNode.getPath();
        this.parent = null;
    } else {/*from  ww w . j a va 2  s .c o  m*/
        this.label = pathAndNode.getNode();
        this.parent = pathAndNode.getPath();
    }
    this.children = Lists.newArrayList(children);
    Collections.sort(this.children, new Comparator<Tree>() {
        @Override
        public int compare(Tree o1, Tree o2) {
            // if one of the nodes is a leaf and one isn't, favor 'directories' first
            if (o1.isLeaf != o2.isLeaf) {
                return o1.isLeaf ? 1 : -1;
            }

            // both nodes are either leaves or directories, sort by nodeName
            return o1.label.compareTo(o2.label);
        }
    });
    this.isLeaf = children.isEmpty() && stat.getNumChildren() == 0;
}

From source file:com.manydesigns.elements.reflection.CommonsConfigurationAccessor.java

public CommonsConfigurationAccessor(Configuration configuration) {
    accessors = new ArrayList<CommonsConfigurationEntryAccessor>();
    int i = 0;/*from   w  w w .  j a va  2s .c o  m*/
    Iterator keys = configuration.getKeys();
    while (keys.hasNext()) {
        String name = (String) keys.next();
        accessors.add(new CommonsConfigurationEntryAccessor(name));
        i++;
    }

    // sort alphabetically
    Collections.sort(accessors, new Comparator<CommonsConfigurationEntryAccessor>() {
        public int compare(CommonsConfigurationEntryAccessor o1, CommonsConfigurationEntryAccessor o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
}

From source file:com.vsthost.rnd.jdeoptim.utils.Utils.java

/**
 * Returns the order of the values, ie. ordered indices sorted by comparing the elements of the array.
 *
 * @param values The vector of which the indices will be ordered.
 * @return The indices of the vector ordered according to sorted elements.
 */// w  ww . j a v  a2 s  .  c o m
public static int[] order(final double[] values) {
    // Initialize the return vector:
    Integer[] vector = Utils.toObject(Utils.sequence(values.length));

    // Order:
    Arrays.sort(vector, new Comparator<Integer>() {
        @Override
        public int compare(Integer o1, Integer o2) {
            return Double.compare(values[o1], values[o2]);
        }
    });

    // Done, return indices:
    return Utils.toPrimitive(vector);
}

From source file:net.chrissearle.flickrvote.service.DaoWinnerService.java

public String getFrontPageHtml() {
    List<ImageItem> images = new ArrayList<ImageItem>(getGoldWinners());

    Collections.sort(images, new Comparator<ImageItem>() {
        public int compare(ImageItem o1, ImageItem o2) {
            return o2.getChallenge().getTag().compareTo(o1.getChallenge().getTag());
        }//from ww w  .j a va 2  s  .  c om
    });

    return challengeMessageService.generateFrontPageHtml(images);
}

From source file:com.autburst.picture.Utilities.java

public static Comparator<File> getImageNameComparator() {
    return new Comparator<File>() {
        @Override// ww  w. jav  a2s  .c  o m
        public int compare(File arg0, File arg1) {
            String filename0 = arg0.getName();
            String filename1 = arg1.getName();
            return filename0.compareTo(filename1);
        }
    };
}

From source file:com.thoughtworks.go.server.service.support.ServerStatusService.java

@Autowired
public ServerStatusService(SecurityService securityService, ServerInfoProvider... providerArray)
        throws IOException {
    this.securityService = securityService;

    providers.addAll(Arrays.asList(providerArray));
    Collections.sort(providers, new Comparator<ServerInfoProvider>() {
        @Override/*from  w  w  w  .j  a  va2 s .  c  o m*/
        public int compare(ServerInfoProvider oneProvider, ServerInfoProvider anotherProvider) {
            return Double.compare(oneProvider.priority(), anotherProvider.priority());
        }
    });
}

From source file:edu.umn.cs.spatialHadoop.indexing.BTRPartitioner.java

@Override
public void createFromPoints(Rectangle mbr, Point[] points, int capacity) {
    // Apply the STR algorithm in two rounds
    // 1- First round, sort points by X and split into the given columns
    Arrays.sort(points, new Comparator<Point>() {
        @Override//from w w  w.j  a  v  a 2  s .  com
        public int compare(Point a, Point b) {
            return a.x < b.x ? -1 : (a.x > b.x ? 1 : 0);
        }
    });
    // Calculate partitioning numbers based on a grid
    int numSplits = (int) Math.ceil((double) points.length / capacity);
    GridInfo gridInfo = new GridInfo(mbr.x1, mbr.y1, mbr.x2, mbr.y2);
    gridInfo.calculateCellDimensions(numSplits);
    this.columns = gridInfo.columns;
    this.rows = gridInfo.rows;
    this.xSplits = new double[columns];
    this.ySplits = new double[rows * columns];
    int prev_quantile = 0;
    this.mbr.set(mbr);
    for (int column = 0; column < columns; column++) {
        int col_quantile = (column + 1) * points.length / columns;
        // Determine the x split for this column. Last column has a special handling
        this.xSplits[column] = col_quantile == points.length ? mbr.x2 : points[col_quantile - 1].x;
        // 2- Partition this column vertically in the same way
        Arrays.sort(points, prev_quantile, col_quantile, new Comparator<Point>() {
            @Override
            public int compare(Point a, Point b) {
                return a.y < b.y ? -1 : (a.y > b.y ? 1 : 0);
            }
        });
        // Compute y-splits for this column
        for (int row = 0; row < rows; row++) {
            int row_quantile = (prev_quantile * (rows - (row + 1)) + col_quantile * (row + 1)) / rows;
            // Determine y split for this row. Last row has a special handling
            this.ySplits[column * rows + row] = row_quantile == col_quantile ? mbr.y2 : points[row_quantile].y;
        }

        prev_quantile = col_quantile;
    }
}