/*
* -------------------------------------------------------------------------
* Copyright 2014
* Centre for Information Modeling - Austrian Centre for Digital Humanities
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
* -------------------------------------------------------------------------
*/
package org.emile.cirilo.gui.jtable;
import java.util.Comparator;
import java.util.Vector;
public class ColumnComparator
implements Comparator {
protected int index;
protected boolean ascending;
public ColumnComparator(int index, boolean ascending) {
this.index = index;
this.ascending = ascending;
}
public int compare(Object one, Object two) {
if (one instanceof Vector && two instanceof Vector) {
Vector vOne = (Vector) one;
Vector vTwo = (Vector) two;
Object oOne = vOne.elementAt(index);
Object oTwo = vTwo.elementAt(index);
if (oOne instanceof Comparable && oTwo instanceof Comparable) {
Comparable cOne = (Comparable) oOne;
Comparable cTwo = (Comparable) oTwo;
if (ascending) {
return cOne.compareTo(cTwo);
} else {
return cTwo.compareTo(cOne);
}
}
}
return 1;
}
}