org.snapscript.parse.LengthComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.parse;
import java.util.Comparator;
public class LengthComparator implements Comparator{
private boolean reverse;
public LengthComparator() {
this(false);
}
public LengthComparator(boolean reverse) {
this.reverse = reverse;
}
@Override
public int compare(String left, String right) {
Integer leftLength = left.length();
Integer rightLength = right.length();
if(reverse) {
return leftLength.compareTo(rightLength);
}
return rightLength.compareTo(leftLength);
}
}