Java Code Examples for com.intellij.openapi.util.text.StringUtil#compare()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#compare() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GotoActionModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public int compareWeights(@Nonnull ActionWrapper o) {
  int compared = myMode.compareTo(o.getMode());
  if (compared != 0) return compared;
  Presentation myPresentation = myAction.getTemplatePresentation();
  Presentation oPresentation = o.getAction().getTemplatePresentation();
  String myText = StringUtil.notNullize(myPresentation.getText());
  String oText = StringUtil.notNullize(oPresentation.getText());
  int byText = StringUtil.compare(StringUtil.trimEnd(myText, "..."), StringUtil.trimEnd(oText, "..."), true);
  if (byText != 0) return byText;
  int byTextLength = StringUtil.notNullize(myText).length() - StringUtil.notNullize(oText).length();
  if (byTextLength != 0) return byTextLength;
  int byGroup = Comparing.compare(myGroupMapping, o.myGroupMapping);
  if (byGroup != 0) return byGroup;
  int byDesc = StringUtil.compare(myPresentation.getDescription(), oPresentation.getDescription(), true);
  if (byDesc != 0) return byDesc;
  int byClassHashCode = Comparing.compare(myAction.getClass().hashCode(), o.myAction.getClass().hashCode());
  if (byClassHashCode != 0) return byClassHashCode;
  int byInstanceHashCode = Comparing.compare(myAction.hashCode(), o.myAction.hashCode());
  if (byInstanceHashCode != 0) return byInstanceHashCode;
  return 0;
}
 
Example 2
Source File: InspectionResultsViewComparator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int compareEntity(final RefEntity entity, final PsiElement element) {
  if (entity instanceof RefElement) {
    final PsiElement psiElement = ((RefElement)entity).getElement();
    if (psiElement != null && element != null) {
      return PsiUtilCore.compareElementsByPosition(psiElement, element);
    }
    if (element == null) return psiElement == null ? 0 : 1;
  }
  if (element instanceof PsiQualifiedNamedElement) {
    return StringUtil.compare(entity.getQualifiedName(), ((PsiQualifiedNamedElement)element).getQualifiedName(), true);
  }
  if (element instanceof PsiNamedElement) {
    return StringUtil.compare(entity.getName(), ((PsiNamedElement)element).getName(), true);
  }
  return -1;
}
 
Example 3
Source File: StdArrangementMatchRule.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull StdArrangementMatchRule o) {
  final Set<ArrangementSettingsToken> tokens = ArrangementUtil.extractTokens(getMatcher().getCondition()).keySet();
  final Set<ArrangementSettingsToken> tokens1 = ArrangementUtil.extractTokens(o.getMatcher().getCondition()).keySet();
  if (tokens1.containsAll(tokens)) {
    return tokens.containsAll(tokens1) ? 0 : 1;
  }
  else {
    if (tokens.containsAll(tokens1)) {
      return -1;
    }

    final String entryType = getEntryType(tokens);
    final String entryType1 = getEntryType(tokens1);
    final int compare = StringUtil.compare(entryType, entryType1, false);
    if (compare != 0 || tokens.size() == tokens1.size()) {
      return compare;
    }
    return tokens.size() < tokens1.size() ? 1 : -1;
  }
}
 
Example 4
Source File: PhpStanValidatorConfiguration.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
public int compareTo(@NotNull QualityToolConfiguration o) {
    if (!(o instanceof PhpStanValidatorConfiguration)) {
        return 1;
    } else if (StringUtil.equals(this.getPresentableName(null), "Local")) {
        return -1;
    } else {
        return StringUtil.equals(o.getPresentableName(null), "Local") ? 1 : StringUtil.compare(this.getPresentableName(null), o.getPresentableName(null), false);
    }
}
 
Example 5
Source File: FileNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(FileNode o) {
  final int compare = StringUtil.compare(myVFile != null ? myVFile.getFileType().getDefaultExtension() : null,
                                         o.myVFile != null ? o.myVFile.getFileType().getDefaultExtension() : null,
                                         true);
  if (compare != 0) return compare;
  return StringUtil.compare(toString(), o.toString(), true);
}
 
Example 6
Source File: RunnerAndConfigurationSettingsImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(@Nonnull Element o1, @Nonnull Element o2) {
  String attributeValue1 = o1.getAttributeValue(RUNNER_ID);
  if (attributeValue1 == null) {
    return 1;
  }
  return StringUtil.compare(attributeValue1, o2.getAttributeValue(RUNNER_ID), false);
}
 
Example 7
Source File: HierarchicalFilePathComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(@Nonnull FilePath filePath1, @Nonnull FilePath filePath2) {
  final String path1 = FileUtilRt.toSystemIndependentName(filePath1.getPath());
  final String path2 = FileUtilRt.toSystemIndependentName(filePath2.getPath());

  int index1 = 0;
  int index2 = 0;

  int start = 0;

  while (index1 < path1.length() && index2 < path2.length()) {
    char c1 = path1.charAt(index1);
    char c2 = path2.charAt(index2);

    if (StringUtil.compare(c1, c2, myIgnoreCase) != 0) break;

    if (c1 == '/') start = index1;

    index1++;
    index2++;
  }

  if (index1 == path1.length() && index2 == path2.length()) return 0;
  if (index1 == path1.length()) return -1;
  if (index2 == path2.length()) return 1;

  int end1 = path1.indexOf('/', start + 1);
  int end2 = path2.indexOf('/', start + 1);

  String name1 = end1 == -1 ? path1.substring(start) : path1.substring(start, end1);
  String name2 = end2 == -1 ? path2.substring(start) : path2.substring(start, end2);

  boolean isDirectory1 = end1 != -1 || filePath1.isDirectory();
  boolean isDirectory2 = end2 != -1 || filePath2.isDirectory();

  if (isDirectory1 && !isDirectory2) return -1;
  if (!isDirectory1 && isDirectory2) return 1;

  return StringUtil.compare(name1, name2, myIgnoreCase);
}
 
Example 8
Source File: PluginManagerColumnInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected Comparator<PluginDescriptor> getColumnComparator() {
  if (isSortByName()) {
    return (o1, o2) -> StringUtil.compare(o1.getName(), o2.getName(), true);
  }
  if (columnIdx == COLUMN_RATE) {
    return (o1, o2) -> {
      final String rating1 = ((PluginNode)o1).getRating();
      final String rating2 = ((PluginNode)o2).getRating();
      return Comparing.compare(rating1, rating2);
    };
  }
  if (isSortByDownloads()) {
    return (o1, o2) -> {
      String count1 = o1.getDownloads();
      String count2 = o2.getDownloads();
      if (count1 != null && count2 != null) {
        return Long.valueOf(count1).compareTo(Long.valueOf(count2));
      }
      else if (count1 != null) {
        return -1;
      }
      else {
        return 1;
      }
    };
  }
  if (isSortByDate()) {
    return (o1, o2) -> {
      long date1 = (o1 instanceof PluginNode) ? ((PluginNode)o1).getDate() : 0;
      long date2 = (o2 instanceof PluginNode) ? ((PluginNode)o2).getDate() : 0;
      if (date1 < date2) {
        return -1;
      }
      else if (date1 > date2) return 1;
      return 0;
    };
  }
  return (o1, o2) -> StringUtil.compare(o1.getCategory(), o2.getCategory(), true);
}
 
Example 9
Source File: VirtualDirectoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int compareNames(@Nonnull CharSequence name1, @Nonnull CharSequence name2, boolean caseSensitive) {
  int d = name1.length() - name2.length();
  if (d != 0) return d;
  for (int i = 0; i < name1.length(); i++) {
    // com.intellij.openapi.util.text.StringUtil.compare(String,String,boolean) inconsistent
    d = StringUtil.compare(name1.charAt(i), name2.charAt(i), !caseSensitive);
    if (d != 0) return d;
  }
  return 0;
}
 
Example 10
Source File: PsalmValidatorConfiguration.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
public int compareTo(@NotNull QualityToolConfiguration o) {
    if (!(o instanceof PsalmValidatorConfiguration)) {
        return 1;
    } else if (StringUtil.equals(this.getPresentableName(null), LOCAL)) {
        return -1;
    } else {
        return StringUtil.equals(o.getPresentableName(null), LOCAL) ? 1 : StringUtil.compare(this.getPresentableName(null), o.getPresentableName(null), false);
    }
}
 
Example 11
Source File: FileUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static int comparePaths(@Nullable String path1, @Nullable String path2) {
  path1 = path1 == null ? null : toSystemIndependentName(path1);
  path2 = path2 == null ? null : toSystemIndependentName(path2);
  return StringUtil.compare(path1, path2, !SystemInfo.isFileSystemCaseSensitive);
}
 
Example 12
Source File: PropertyTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(Property o1, Property o2) {
  return StringUtil.compare(o1.getName(), o2.getName(), true);
}
 
Example 13
Source File: ExtensionCheckedTreeNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(TreeNode o1, TreeNode o2) {
  final ModuleExtensionProviderEP i1 = ((ExtensionCheckedTreeNode)o1).myProviderEP;
  final ModuleExtensionProviderEP i2 = ((ExtensionCheckedTreeNode)o2).myProviderEP;
  return StringUtil.compare(i1.getName(), i2.getName(), true);
}
 
Example 14
Source File: PropertyTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(String o1, String o2) {
  return StringUtil.compare(o1, o2, true);
}
 
Example 15
Source File: TextFieldWithAutoCompletion.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(final String item1, final String item2) {
  return StringUtil.compare(item1, item2, false);
}
 
Example 16
Source File: DefaultTextCompletionValueDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(T item1, T item2) {
  return StringUtil.compare(getLookupString(item1), getLookupString(item2), false);
}
 
Example 17
Source File: WeightBasedComparator.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static int compareToString(final NodeDescriptor first, final NodeDescriptor second) {
  return StringUtil.compare(first.toString(), second.toString(), true);
}