public static Comparator<Descriptor> getPrimitiveComparator(
      boolean compressInt, boolean compressLong) {
    if (!compressInt && !compressLong) {
      return PRIMITIVE_COMPARATOR;
    }
    return (d1, d2) -> {
      Class<?> t1 = TypeUtils.unwrap(d1.getRawType());
      Class<?> t2 = TypeUtils.unwrap(d2.getRawType());
      boolean t1Compress = isCompressedType(t1, compressInt, compressLong);
      boolean t2Compress = isCompressedType(t2, compressInt, compressLong);
      if ((t1Compress && t2Compress) || (!t1Compress && !t2Compress)) {
        int c = getSizeOfPrimitiveType(t2) - getSizeOfPrimitiveType(t1);
        if (c == 0) {
          c = DescriptorGrouper.COMPARATOR_BY_TYPE_AND_NAME.compare(d1, d2);
        }
        return c;
      }
      if (t1Compress) {
        return 1;
      }
      // t2 compress
      return -1;
    };
  }
@Test
  public void testPrimitiveComparator() {
    List<Descriptor> descriptors = new ArrayList<>();
    int index = 0;
    for (Class<?> aClass : Primitives.allPrimitiveTypes()) {
      descriptors.add(new Descriptor(TypeRef.of(aClass), "f" + index++, -1, "TestClass"));
    }
    Collections.shuffle(descriptors, new Random(7));
    descriptors.sort(DescriptorGrouper.getPrimitiveComparator(false, false));
    List<? extends Class<?>> classes =
        descriptors.stream().map(Descriptor::getRawType).collect(Collectors.toList());
    List<Class<?>> expected =
        Arrays.asList(
            double.class,
            long.class,
            float.class,
            int.class,
            char.class,
            short.class,
            boolean.class,
            byte.class,
            void.class);
    assertEquals(classes, expected);
  }