private CopyContextMap removeBelowSeven()

in servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/CopyOnWriteContextMap.java [2719:2843]


        private CopyContextMap removeBelowSeven(final GrowableIntArray indexesToRemove) {
            switch (size() - indexesToRemove.count()) {
                case 1:
                    for (int i = 0; i < this.context.length; i += 2) {
                        if (indexesToRemove.isValueAbsent(i)) {
                            return new OneContextMap((Key<?>) context[i], context[i + 1]);
                        }
                    }
                    break;
                case 2: {
                    int keepI1 = -1;
                    for (int i = 0; i < this.context.length; i += 2) {
                        if (indexesToRemove.isValueAbsent(i)) {
                            if (keepI1 < 0) {
                                keepI1 = i;
                            } else {
                                return new TwoContextMap((Key<?>) context[keepI1], context[keepI1 + 1],
                                        (Key<?>) context[i], context[i + 1]);
                            }
                        }
                    }
                    break;
                }
                case 3: {
                    int keepI1 = -1;
                    int keepI2 = -1;
                    for (int i = 0; i < this.context.length; i += 2) {
                        if (indexesToRemove.isValueAbsent(i)) {
                            if (keepI1 < 0) {
                                keepI1 = i;
                            } else if (keepI2 < 0) {
                                keepI2 = i;
                            } else {
                                return new ThreeContextMap((Key<?>) context[keepI1], context[keepI1 + 1],
                                        (Key<?>) context[keepI2], context[keepI2 + 1],
                                        (Key<?>) context[i], context[i + 1]);
                            }
                        }
                    }
                    break;
                }
                case 4: {
                    int keepI1 = -1;
                    int keepI2 = -1;
                    int keepI3 = -1;
                    for (int i = 0; i < this.context.length; i += 2) {
                        if (indexesToRemove.isValueAbsent(i)) {
                            if (keepI1 < 0) {
                                keepI1 = i;
                            } else if (keepI2 < 0) {
                                keepI2 = i;
                            } else if (keepI3 < 0) {
                                keepI3 = i;
                            } else {
                                return new FourContextMap((Key<?>) context[keepI1], context[keepI1 + 1],
                                        (Key<?>) context[keepI2], context[keepI2 + 1],
                                        (Key<?>) context[keepI3], context[keepI3 + 1],
                                        (Key<?>) context[i], context[i + 1]);
                            }
                        }
                    }
                    break;
                }
                case 5: {
                    int keepI1 = -1;
                    int keepI2 = -1;
                    int keepI3 = -1;
                    int keepI4 = -1;
                    for (int i = 0; i < this.context.length; i += 2) {
                        if (indexesToRemove.isValueAbsent(i)) {
                            if (keepI1 < 0) {
                                keepI1 = i;
                            } else if (keepI2 < 0) {
                                keepI2 = i;
                            } else if (keepI3 < 0) {
                                keepI3 = i;
                            } else if (keepI4 < 0) {
                                keepI4 = i;
                            } else {
                                return new FiveContextMap((Key<?>) context[keepI1], context[keepI1 + 1],
                                        (Key<?>) context[keepI2], context[keepI2 + 1],
                                        (Key<?>) context[keepI3], context[keepI3 + 1],
                                        (Key<?>) context[keepI4], context[keepI4 + 1],
                                        (Key<?>) context[i], context[i + 1]);
                            }
                        }
                    }
                    break;
                }
                case 6: {
                    int keepI1 = -1;
                    int keepI2 = -1;
                    int keepI3 = -1;
                    int keepI4 = -1;
                    int keepI5 = -1;
                    for (int i = 0; i < this.context.length; i += 2) {
                        if (indexesToRemove.isValueAbsent(i)) {
                            if (keepI1 < 0) {
                                keepI1 = i;
                            } else if (keepI2 < 0) {
                                keepI2 = i;
                            } else if (keepI3 < 0) {
                                keepI3 = i;
                            } else if (keepI4 < 0) {
                                keepI4 = i;
                            } else if (keepI5 < 0) {
                                keepI5 = i;
                            } else {
                                return new SixContextMap((Key<?>) context[keepI1], context[keepI1 + 1],
                                        (Key<?>) context[keepI2], context[keepI2 + 1],
                                        (Key<?>) context[keepI3], context[keepI3 + 1],
                                        (Key<?>) context[keepI4], context[keepI4 + 1],
                                        (Key<?>) context[keepI5], context[keepI5 + 1],
                                        (Key<?>) context[i], context[i + 1]);
                            }
                        }
                    }
                    break;
                }
                default:
                    break;
            }
            throw new RuntimeException("Programming error, unable to reduce from " + size() + " to " +
                    (size() - indexesToRemove.count()));
        }