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

com.jamonapi.utils.ArrayElementComparator Maven / Gradle / Ivy

There is a newer version: 2.82
Show newest version
package com.jamonapi.utils;

import java.util.Comparator;

/** Maps a Comparator to a column number of an array starting at position 0.  Used by JAMonArrayComparator */
class ArrayElementComparator implements Comparator {
    // Used to compare elements of an array that reside within the same column.  The Object[][] array itself
    // will be sorted according to this algorithm.

    private int sortCol;
    private Comparator comparator;

    /** Constructor that takes the position in array to be compared as well as it's comparator */
    public ArrayElementComparator(int sortCol, Comparator comparator) {
        this.comparator=comparator;
        this.sortCol=sortCol;
    }


    public ArrayElementComparator(int sortCol, boolean naturalOrder) {
        comparator=new JAMonComparator(naturalOrder);
        this.sortCol=sortCol;
    }


    /** Return col to be sorted/compared */
    public int getSortCol() {
        return sortCol;
    }

    /** Call the comparator on the column */
    public int compare(Object o1, Object o2) {
        return comparator.compare(o1, o2);
    }


    @Override
    public String toString() {
        return "sortCol="+sortCol+", comparator="+comparator;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy