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

The following examples show how to use com.intellij.openapi.util.Comparing#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: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(UsageNode c1, UsageNode c2) {
  if (c1 instanceof StringNode) return 1;
  if (c2 instanceof StringNode) return -1;
  Usage o1 = c1.getUsage();
  Usage o2 = c2.getUsage();
  if (o1 == MORE_USAGES_SEPARATOR) return 1;
  if (o2 == MORE_USAGES_SEPARATOR) return -1;

  VirtualFile v1 = UsageListCellRenderer.getVirtualFile(o1);
  VirtualFile v2 = UsageListCellRenderer.getVirtualFile(o2);
  String name1 = v1 == null ? null : v1.getName();
  String name2 = v2 == null ? null : v2.getName();
  int i = Comparing.compare(name1, name2);
  if (i != 0) return i;

  if (o1 instanceof Comparable && o2 instanceof Comparable) {
    return ((Comparable)o1).compareTo(o2);
  }

  FileEditorLocation loc1 = o1.getLocation();
  FileEditorLocation loc2 = o2.getLocation();
  return Comparing.compare(loc1, loc2);
}
 
Example 2
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(UsageNode c1, UsageNode c2) {
  if (c1 instanceof StringNode) return 1;
  if (c2 instanceof StringNode) return -1;
  Usage o1 = c1.getUsage();
  Usage o2 = c2.getUsage();
  if (o1 == MORE_USAGES_SEPARATOR) return 1;
  if (o2 == MORE_USAGES_SEPARATOR) return -1;

  VirtualFile v1 = UsageListCellRenderer.getVirtualFile(o1);
  VirtualFile v2 = UsageListCellRenderer.getVirtualFile(o2);
  String name1 = v1 == null ? null : v1.getName();
  String name2 = v2 == null ? null : v2.getName();
  int i = Comparing.compare(name1, name2);
  if (i != 0) return i;

  if (o1 instanceof Comparable && o2 instanceof Comparable) {
    return ((Comparable) o1).compareTo(o2);
  }

  FileEditorLocation loc1 = o1.getLocation();
  FileEditorLocation loc2 = o2.getLocation();
  return Comparing.compare(loc1, loc2);
}
 
Example 3
Source File: MultiLevelDiffTool.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Map<String, DiffRequest> discloseRequest(DiffRequest request) {
  final Map<String, DiffRequest> pairs = new TreeMap<String, DiffRequest>(new Comparator<String>() {
    @Override
    public int compare(String o1, String o2) {
      if (ourDefaultTab.equals(o1)) return -1;
      if (ourDefaultTab.equals(o2)) return 1;
      return Comparing.compare(o1, o2);
    }
  });
  final List<Pair<String, DiffRequest>> layers = request.getOtherLayers();
  for (Pair<String, DiffRequest> layer : layers) {
    pairs.put(layer.getFirst(), layer.getSecond());
  }
  pairs.put(ourDefaultTab, request);
  return pairs;
}
 
Example 4
Source File: PercentageCoverageColumnInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public PercentageCoverageColumnInfo(int columnIdx,
                             String name,
                             final CoverageSuitesBundle suitesBundle,
                             CoverageViewManager.StateBean stateBean) {
  super(name);
  this.myColumnIdx = columnIdx;
  myComparator = new Comparator<NodeDescriptor>() {
    @Override
    public int compare(NodeDescriptor o1, NodeDescriptor o2) {
      final String val1 = valueOf(o1);
      final String val2 = valueOf(o2);
      if (val1 != null && val2 != null) {
        final int percentageIndex1 = val1.indexOf('%');
        final int percentageIndex2 = val2.indexOf('%');
        if (percentageIndex1 > -1 && percentageIndex2 >-1) {
          final String percentage1 = val1.substring(0, percentageIndex1);
          final String percentage2 = val2.substring(0, percentageIndex2);
          final int compare = Comparing.compare(Integer.parseInt(percentage1), Integer.parseInt(percentage2));
          if (compare == 0) {
            final int total1 = val1.indexOf('/');
            final int total2 = val2.indexOf('/');
            if (total1 > -1 && total2 > -1) {
              final int r1 = val1.indexOf(')', total1);
              final int r2 = val2.indexOf(')', total2);
              if (r1 > -1 && r2 > -1) {
                return Integer.parseInt(val2.substring(total2 + 1, r2)) - Integer.parseInt(val1.substring(total1 + 1, r1)) ;
              }
            }
          }
          return compare;
        }
        if (percentageIndex1 > -1) return 1;
        if (percentageIndex2 > -1) return -1;
      }
      return Comparing.compare(val1, val2);
    }
  };
  mySuitesBundle = suitesBundle;
  myStateBean = stateBean;
}
 
Example 5
Source File: PlatformTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Comparator<AbstractTreeNode> createComparator(final Queryable.PrintInfo printInfo) {
  return new Comparator<AbstractTreeNode>() {
    @Override
    public int compare(final AbstractTreeNode o1, final AbstractTreeNode o2) {
      String displayText1 = o1.toTestString(printInfo);
      String displayText2 = o2.toTestString(printInfo);
      return Comparing.compare(displayText1, displayText2);
    }
  };
}
 
Example 6
Source File: SdkTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public Sdk findMostRecentSdk(@Nonnull Condition<Sdk> condition) {
  Sdk found = null;
  for (Sdk each : getAllSdks()) {
    if (!condition.value(each)) continue;
    if (found == null) {
      found = each;
      continue;
    }
    if (Comparing.compare(each.getVersionString(), found.getVersionString()) > 0) found = each;
  }
  return found;
}
 
Example 7
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 8
Source File: ChangeListColumn.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Comparator<CommittedChangeList> getComparator() {
  return new Comparator<CommittedChangeList>() {
    public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
      return Comparing.compare((String) getValue(o1), (String) getValue(o2));
    }
  };
}
 
Example 9
Source File: FileModuleData.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public int compareTo(@NotNull FileModuleData o) {
    int comp = Comparing.compare(m_namespace, o.m_namespace);
    if (comp == 0) {
        comp = Comparing.compare(m_moduleName, o.m_moduleName);
        if (comp == 0) {
            comp = Comparing.compare(m_isInterface, o.m_isInterface);
        }
    }
    return comp;
}
 
Example 10
Source File: IntentionActionWithTextCaching.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull final MyIntentionAction other) {
  if (myAction instanceof Comparable) {
    //noinspection unchecked
    return ((Comparable)myAction).compareTo(other.getDelegate());
  }
  if (other.getDelegate() instanceof Comparable) {
    //noinspection unchecked
    return -((Comparable)other.getDelegate()).compareTo(myAction);
  }
  return Comparing.compare(getText(), other.getText());
}
 
Example 11
Source File: XVariablesView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Entry o) {
  if (myNode == o.myNode) return 0;
  int res = Comparing.compare(myOffset, o.myOffset);
  if (res == 0) {
    return XValueNodeImpl.COMPARATOR.compare(myNode, o.myNode);
  }
  return res;
}
 
Example 12
Source File: IntentionActionWithTextCaching.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull final IntentionActionWithTextCaching other) {
  if (myAction instanceof Comparable) {
    //noinspection unchecked
    return ((Comparable)myAction).compareTo(other.getAction());
  }
  if (other.getAction() instanceof Comparable) {
    //noinspection unchecked
    return -((Comparable)other.getAction()).compareTo(myAction);
  }
  return Comparing.compare(getText(), other.getText());
}
 
Example 13
Source File: VcsDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(VcsDescriptor o) {
  return Comparing.compare(myDisplayName, o.myDisplayName);
}
 
Example 14
Source File: PackageNodeUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(@Nonnull VirtualFile file1, @Nonnull VirtualFile file2) {
  final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(myModule).getFileIndex();
  return Comparing.compare(fileIndex.getOrderEntryForFile(file2), fileIndex.getOrderEntryForFile(file1));
}
 
Example 15
Source File: ReferenceProvidersRegistryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext> o1, ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext> o2) {
  return Comparing.compare(o2.priority, o1.priority);
}
 
Example 16
Source File: CommittedChangeListByDateComparator.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(CommittedChangeList o1, CommittedChangeList o2) {
  return Comparing.compare(o1.getCommitDate(), o2.getCommitDate());
}
 
Example 17
Source File: VcsTaskHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(TaskInfo o) {
  return Comparing.compare(myBranch, o.myBranch);
}
 
Example 18
Source File: TextRevisionNumber.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull final VcsRevisionNumber o) {
  return Comparing.compare(myFullRevisionNumber, ((TextRevisionNumber) o).myFullRevisionNumber);
}
 
Example 19
Source File: ExternalProjectSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull ExternalProjectSettings that) {
  return Comparing.compare(myExternalProjectPath, that.myExternalProjectPath);
}
 
Example 20
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public int compare(VcsFileRevision o1, VcsFileRevision o2) {
    return Comparing.compare(this.getDataOf(o1), this.getDataOf(o2));
}