int (Item item) { if (item == null) { if (size() == 0) { return 0; // 1-0 = 1- (normalize) = 1 } Item first = get(0); return first.compareTo(null); } return switch (item.getType()) { case INTEGER_ITEM -> -1; // 1-1 < 1.0.x case STRING_ITEM -> 1; // 1-1 > 1-sp case LIST_ITEM -> { Iterator<Item> left = iterator(); Iterator<Item> right = ((ListItem)item).iterator(); while (left.hasNext() || right.hasNext()) { Item l = left.hasNext() ? left.next() : null; Item r = right.hasNext() ? right.next() : null; // if this is shorter, then invert the compare and mul with -1 int result = l == null ? -1 * r.compareTo(l) : l.compareTo(r); if (result != 0) { yield result; } } yield 0; } default -> throw new RuntimeException("invalid item: " + item.getClass()); }; }