1 19 20 package org.netbeans.lib.editor.codetemplates; 21 22 import java.util.Comparator ; 23 import org.netbeans.lib.editor.codetemplates.api.CodeTemplate; 24 25 30 public final class CodeTemplateComparator implements Comparator { 31 32 34 public static final Comparator BY_ABBREVIATION_IGNORE_CASE = new CodeTemplateComparator(true, true); 35 36 38 public static final Comparator BY_PARAMETRIZED_TEXT_IGNORE_CASE = new CodeTemplateComparator(false, true); 39 40 private final boolean byAbbreviation; 41 42 private final boolean ignoreCase; 43 44 private CodeTemplateComparator(boolean byAbbreviation, boolean ignoreCase) { 45 this.byAbbreviation = byAbbreviation; 46 this.ignoreCase = ignoreCase; 47 } 48 49 public int compare(Object o1, Object o2) { 50 CodeTemplate t1 = (CodeTemplate)o1; 51 CodeTemplate t2 = (CodeTemplate)o2; 52 String n1 = byAbbreviation ? t1.getAbbreviation() : t1.getParametrizedText(); 53 String n2 = byAbbreviation ? t2.getAbbreviation() : t2.getParametrizedText(); 54 return ignoreCase ? n1.compareToIgnoreCase(n2) : n1.compareTo(n2); 55 } 56 57 } 58 | Popular Tags |