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

org.snapscript.parse.LengthComparator Maven / Gradle / Ivy


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);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy