public static <T> void assertOneOf(T value, T... values) {
   boolean found = false;
   for (T v : values) {
     if (value == v || value != null && value.equals(v)) {
       found = true;
     }
   }
   Assert.assertTrue(value + " should be equal to one of " + Arrays.toString(values), found);
 }
示例#2
0
  private static void removeIdFromParentList(
      final int parentId, final int id, @NotNull VirtualFile parent, VirtualFile file) {
    int[] childList = FSRecords.list(parentId);

    int index = ArrayUtil.indexOf(childList, id);
    if (index == -1) {
      throw new RuntimeException(
          "Cannot find child ("
              + id
              + ")"
              + file
              + "\n\tin ("
              + parentId
              + ")"
              + parent
              + "\n\tactual children:"
              + Arrays.toString(childList));
    }
    childList = ArrayUtil.remove(childList, index);
    FSRecords.updateList(parentId, childList);
  }
  private void assertConsistency(
      @NotNull VirtualFileSystemEntry[] array, boolean ignoreCase, @NotNull Object... details) {
    if (!CHECK) return;
    boolean allChildrenLoaded = allChildrenLoaded();
    for (int i = 0; i < array.length; i++) {
      VirtualFileSystemEntry file = array[i];
      boolean isAdopted = isAdoptedChild(file);
      assert !isAdopted || !allChildrenLoaded;
      if (isAdopted && i != array.length - 1) {
        assert isAdoptedChild(array[i + 1]);
      }
      if (i != 0) {
        VirtualFileSystemEntry prev = array[i - 1];
        String prevName = prev.getName();
        int cmp = file.compareNameTo(prevName, ignoreCase);
        if (cmp == 0) {
          Function<VirtualFileSystemEntry, String> verboseToString =
              new Function<VirtualFileSystemEntry, String>() {
                @Override
                public String fun(VirtualFileSystemEntry entry) {
                  return entry
                      + " (name: '"
                      + entry.getName()
                      + "', "
                      + entry.getClass()
                      + ", parent:"
                      + entry.getParent()
                      + "; id:"
                      + entry.getId()
                      + "; FS:"
                      + entry.getFileSystem()
                      + "; delegate.attrs:"
                      + entry.getFileSystem().getAttributes(entry)
                      + "; caseSensitive:"
                      + entry.getFileSystem().isCaseSensitive()
                      + "; canonical:"
                      + entry.getFileSystem().getCanonicallyCasedName(entry)
                      + ") ";
                }
              };
          String children = StringUtil.join(array, verboseToString, ",");
          throw new AssertionError(
              verboseToString.fun(prev)
                  + " equals to "
                  + verboseToString.fun(file)
                  + "; children: "
                  + children
                  + "\nDetails: "
                  + ContainerUtil.map(
                      details,
                      new Function<Object, Object>() {
                        @Override
                        public Object fun(Object o) {
                          return o instanceof Object[] ? Arrays.toString((Object[]) o) : o;
                        }
                      }));
        }

        if (isAdopted == isAdoptedChild(prev)) {
          assert cmp > 0 : "Not sorted. " + Arrays.toString(details);
        }
      }
    }
  }