// Copyright 2015 Eivind Vegsundvåg
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.metacodestudio.hotsuploader.concurrent.tasks;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.metacodestudio.hotsuploader.models.Hero;
import com.metacodestudio.hotsuploader.utils.SimpleHttpClient;
import javafx.concurrent.Task;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * @author Eivind Vegsundvåg
 */
public class HeroListTask extends Task<List<Hero>> {
    public static final String API_ROUTE = "https://www.hotslogs.com/API/Data/Heroes";
    private final SimpleHttpClient httpClient;

    public HeroListTask(SimpleHttpClient httpClient) {
        this.httpClient = httpClient;
    }

    @Override
    protected List<Hero> call() throws Exception {
        final String result = httpClient.simpleRequest(API_ROUTE);
        final Hero[] heroes = new ObjectMapper().readValue(result, Hero[].class);
        return Arrays.asList(heroes);
    }
}

@@ -895,16 +895,45 @@
 Arrays;%0A
+import java.util.Comparator;%0A
 import j
@@ -1499,14 +1499,29 @@
     
-return
+List%3CHero%3E heroList =
  Arr
@@ -1536,20 +1536,132 @@
 st(heroes);%0A
+        heroList.sort((o1, o2) -%3E o1.getPrimaryName().compareTo(o2.getPrimaryName()));%0A        return heroList;%0A
     %7D%0A%7D%0A

fix sort. closes #40