// Path: src/main/java/net/itimothy/util/CollectionUtil.java
// public class CollectionUtil {
// 
//     /**
//      * Sorts the specified list according to the order induced by comparing the keys extracted by the given
//      * {keyExtractor}
//      *
//      * @param items        List of items to sort
//      * @param keyExtractor The function which produces the value to compare
//      */
//     public static <T, K extends Comparable> void sort(List<T> items, final Function<T, K> keyExtractor) {
//         if (items == null) {
//             return;
//         }
// 
//         java.util.Collections.sort(
//             items,
//             new Comparator<T>() {
//                 @Override
//                 public int compare(T o1, T o2) {
//                     K key1 = o1 != null ? keyExtractor.apply(o1) : null;
//                     K key2 = o2 != null ? keyExtractor.apply(o2) : null;
// 
//                     if (key1 == key2) {
//                         return 0;
//                     }
// 
//                     if (key1 == null) {
//                         return -1;
//                     }
// 
//                     if (key2 == null) {
//                         return 1;
//                     }
// 
//                     return key1.compareTo(key2);
//                 }
//             }
//         );
//     }
// }


import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.base.Function;
import net.itimothy.elasticsearch.routes.model.*;
import net.itimothy.util.CollectionUtil;
import net.itimothy.util.SimpleCache;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import static java.util.Arrays.asList;
                    );

                    Collections.sort(allIndices);

                    return allIndices;
                }
            }
        );
    }

    protected List<String> getAllAliases() {
        return cache.getOrResolve("getAllAliases",
            new Callable<List<String>>() {
                @Override
                public List<String> call() throws Exception {
                    List<String> allAliases = new ArrayList<String>();

                    ImmutableOpenMap<String, List<AliasMetaData>> indexAliasesMap = client.admin().indices()
                        .prepareGetAliases()
                        .get()
                        .getAliases();

                    for (ObjectCursor<List<AliasMetaData>> listObjectCursor : indexAliasesMap.values()) {
                        for (AliasMetaData aliasMetaData : listObjectCursor.value) {
                            if (!allAliases.contains(aliasMetaData.alias())) {
                                allAliases.add(aliasMetaData.alias());
                            }
                        }
                    }

// Path: src/main/java/net/itimothy/util/CollectionUtil.java
// public class CollectionUtil {
// 
//     /**
//      * Sorts the specified list according to the order induced by comparing the keys extracted by the given
//      * {keyExtractor}
//      *
//      * @param items        List of items to sort
//      * @param keyExtractor The function which produces the value to compare
//      */
//     public static <T, K extends Comparable> void sort(List<T> items, final Function<T, K> keyExtractor) {
//         if (items == null) {
//             return;
//         }
// 
//         java.util.Collections.sort(
//             items,
//             new Comparator<T>() {
//                 @Override
//                 public int compare(T o1, T o2) {
//                     K key1 = o1 != null ? keyExtractor.apply(o1) : null;
//                     K key2 = o2 != null ? keyExtractor.apply(o2) : null;
// 
//                     if (key1 == key2) {
//                         return 0;
//                     }
// 
//                     if (key1 == null) {
//                         return -1;
//                     }
// 
//                     if (key2 == null) {
//                         return 1;
//                     }
// 
//                     return key1.compareTo(key2);
//                 }
//             }
//         );
//     }
// }


// Path: src/main/java/net/itimothy/elasticsearch/routes/RoutesProvider.java
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.base.Function;
import net.itimothy.elasticsearch.routes.model.*;
import net.itimothy.util.CollectionUtil;
import net.itimothy.util.SimpleCache;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import static java.util.Arrays.asList;

                    );

                    Collections.sort(allIndices);

                    return allIndices;
                }
            }
        );
    }

    protected List<String> getAllAliases() {
        return cache.getOrResolve("getAllAliases",
            new Callable<List<String>>() {
                @Override
                public List<String> call() throws Exception {
                    List<String> allAliases = new ArrayList<String>();

                    ImmutableOpenMap<String, List<AliasMetaData>> indexAliasesMap = client.admin().indices()
                        .prepareGetAliases()
                        .get()
                        .getAliases();

                    for (ObjectCursor<List<AliasMetaData>> listObjectCursor : indexAliasesMap.values()) {
                        for (AliasMetaData aliasMetaData : listObjectCursor.value) {
                            if (!allAliases.contains(aliasMetaData.alias())) {
                                allAliases.add(aliasMetaData.alias());
                            }
                        }
                    }

                    CollectionUtil.sort(allAliases, new Function<String, Comparable>() {