@@ -0,0 +1,3261 @@
+package run.chronicle.wire.demo;%0A%0Aimport net.openhft.chronicle.core.util.CharSequenceComparator;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Comparator;%0Aimport java.util.List;%0Aimport java.util.function.Function;%0A%0Aimport static java.util.Comparator.comparing;%0A%0A/**%0A * This example shows how a List can be sorted and used for looking up keys%0A * so that no Maps need to be created. The standard Map implementations create%0A * a lot of extra objects when values are put into the Map.%0A * %3Cp%3E%0A * The sorted List can be reused over and over again.%0A */%0Apublic class ListLookup %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        // These can be reused%0A        final Data d0 = new Data(%22XYZ%22, 45, 2);%0A        final Data d1 = new Data(%22ABC%22, 100, 42);%0A        final Data d2 = new Data(%22DEF%22, 200, 13);%0A%0A        // This can be reused%0A        final List%3CData%3E dataList = new ArrayList%3C%3E();%0A%0A        dataList.add(d0);%0A        dataList.add(d1);%0A        dataList.add(d2);%0A%0A        // do this once all elements has been added and before marshalling%0A        dataList.sort(comparing(Data::getId, CharSequenceComparator.INSTANCE));%0A%0A        // Do this in the application%0A        int index = binarySearch(dataList, Data::getId, %22DEF%22, CharSequenceComparator.INSTANCE);%0A%0A        // Use the result%0A        if (index %3E 0) %7B%0A            System.out.println(dataList.get(index));%0A        %7D else %7B%0A            System.out.println(%22Not found!%22);%0A        %7D%0A%0A    %7D%0A%0A%0A    private static final class Data %7B%0A%0A        // Ids can be reused/internalized%0A        private CharSequence id;%0A        private long price;%0A        private long count;%0A%0A        public Data(CharSequence id, long price, long count) %7B%0A            this.id = id;%0A            this.price = price;%0A            this.count = count;%0A        %7D%0A%0A        public CharSequence getId() %7B%0A            return id;%0A        %7D%0A%0A        public void setId(CharSequence id) %7B%0A            this.id = id;%0A        %7D%0A%0A        public long getPrice() %7B%0A            return price;%0A        %7D%0A%0A        public void setPrice(long price) %7B%0A            this.price = price;%0A        %7D%0A%0A        public long getCount() %7B%0A            return count;%0A        %7D%0A%0A        public void setCount(long count) %7B%0A            this.count = count;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return %22Data%7B%22 +%0A                    %22id=%22 + id +%0A                    %22, price=%22 + price +%0A                    %22, count=%22 + count +%0A                    '%7D';%0A        %7D%0A    %7D%0A%0A%0A    public static %3CT, U%3E int binarySearch(final List%3CT%3E list,%0A                                          final Function%3C? super T, ? extends U%3E extractor,%0A                                          final U key,%0A                                          final Comparator%3CU%3E comparator) %7B%0A        int low = 0;%0A        int high = list.size() - 1;%0A%0A        while (low %3C= high) %7B%0A            final int mid = (low + high) %3E%3E%3E 1;%0A            final T midVal = list.get(mid);%0A            int cmp = comparator.compare(extractor.apply(midVal), key);%0A%0A            if (cmp %3C 0)%0A                low = mid + 1;%0A            else if (cmp %3E 0)%0A                high = mid - 1;%0A            else%0A                return mid; // key found%0A        %7D%0A        return -(low + 1);  // key not found%0A    %7D%0A%0A%7D%0A

Add an example of a map-like usage of reusable Lists, Fix #317