Example usage for java.util ArrayList sort

List of usage examples for java.util ArrayList sort

Introduction

In this page you can find the example usage for java.util ArrayList sort.

Prototype

@Override
    @SuppressWarnings("unchecked")
    public void sort(Comparator<? super E> c) 

Source Link

Usage

From source file:org.candlepin.controller.PoolManagerFunctionalTest.java

@Test
public void testFabricateWithBranding() throws Exception {
    Pool masterPool = poolManager.getMasterPoolBySubscriptionId(sub4.getId());
    Set<Branding> brandingSet = poolManager.fabricateSubscriptionFromPool(masterPool).getBranding();

    Assert.assertNotNull(brandingSet);//from   w  w  w . j a v  a  2s.  com
    Assert.assertEquals(2, brandingSet.size());
    ArrayList<Branding> list = new ArrayList<Branding>();
    list.addAll(brandingSet);
    list.sort(new Comparator<Branding>() {

        @Override
        public int compare(Branding o1, Branding o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });

    Assert.assertEquals("branding1", list.get(0).getName());
    Assert.assertEquals("product1", list.get(0).getProductId());
    Assert.assertEquals("type1", list.get(0).getType());
    Assert.assertEquals("branding2", list.get(1).getName());
    Assert.assertEquals("product2", list.get(1).getProductId());
    Assert.assertEquals("type2", list.get(1).getType());
}

From source file:com.bouncestorage.swiftproxy.v1.AccountResource.java

@GET
public Response getAccount(@NotNull @PathParam("account") String account,
        @QueryParam("limit") Optional<Integer> limit, @QueryParam("marker") Optional<String> marker,
        @QueryParam("end_marker") Optional<String> endMarker, @QueryParam("format") Optional<String> format,
        @QueryParam("prefix") Optional<String> prefix, @QueryParam("delimiter") Optional<String> delimiter,
        @HeaderParam("X-Auth-Token") String authToken,
        @HeaderParam("X-Newest") @DefaultValue("false") boolean newest,
        @HeaderParam("Accept") Optional<String> accept) {
    delimiter.ifPresent(x -> logger.info("delimiter not supported yet"));

    BlobStore blobStore = getBlobStore(authToken).get();
    ArrayList<ContainerEntry> entries = blobStore.list().stream().map(StorageMetadata::getName)
            .filter(name -> marker.map(m -> name.compareTo(m) > 0).orElse(true))
            .filter(name -> endMarker.map(m -> name.compareTo(m) < 0).orElse(true))
            .filter(name -> prefix.map(name::startsWith).orElse(true)).map(ContainerEntry::new)
            .collect(Collectors.toCollection(ArrayList::new));

    MediaType formatType;/* w  w  w  . j av a2 s . com*/
    if (format.isPresent()) {
        formatType = BounceResourceConfig.getMediaType(format.get());
    } else if (accept.isPresent()) {
        formatType = MediaType.valueOf(accept.get());
    } else {
        formatType = MediaType.TEXT_PLAIN_TYPE;
    }

    if (blobStore.getContext().unwrap().getId().equals("transient")) {
        entries.sort((a, b) -> a.getName().compareTo(b.getName()));
    }

    long count = entries.size();
    limit.ifPresent((max) -> {
        if (entries.size() > max) {
            entries.subList(max, entries.size()).clear();
        }
    });

    Account root = new Account();
    root.name = account;
    root.container = entries;
    return output(root, entries, formatType).header("X-Account-Container-Count", count)
            .header("X-Account-Object-Count", -1).header("X-Account-Bytes-Used", -1).header("X-Timestamp", -1)
            .header("X-Trans-Id", -1).header("Accept-Ranges", "bytes").build();
}

From source file:pl.betoncraft.betonquest.editor.model.QuestPackage.java

public void sort() {
    // sort lists
    ArrayList<ObservableList<? extends ID>> lists = new ArrayList<>();
    lists.add(conversations);/* ww w.j av  a 2 s  . c o  m*/
    lists.add(events);
    lists.add(conditions);
    lists.add(objectives);
    lists.add(items);
    lists.add(journal);
    lists.add(staticEvents);
    lists.add(variables);
    lists.add(npcBindings);
    lists.add(mainPage);
    for (Conversation conv : conversations) {
        lists.add(conv.getNpcOptions());
        lists.add(conv.getPlayerOptions());
        lists.add(conv.getStartingOptions());
        lists.add(conv.getFinalEvents());
        ArrayList<ConversationOption> list = new ArrayList<>(conv.getNpcOptions());
        list.addAll(conv.getPlayerOptions());
        for (ConversationOption option : list) {
            lists.add(option.getConditions());
            lists.add(option.getEvents());
            lists.add(option.getPointers());
        }
    }
    for (ObservableList<? extends ID> list : lists) {
        list.sort((ID o1, ID o2) -> o1.getIndex() - o2.getIndex());
        int index = 0;
        for (ID object : list) {
            object.setIndex(index++);
        }
    }
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private boolean downloadAddons() throws NetworkException {
    boolean isNew;
    Manifest mf;//from  w w w .j a  va  2s .  c o  m
    int n;
    ArrayList<Addon> installList = new ArrayList<>();
    ArrayList<String> removeList = new ArrayList<>();
    int modpackIndex = modpackChooser.getSelectedIndex();
    Gson gson = new GsonBuilder().create();

    log.setIndeterminate();
    isNew = !manifest.containsKey(workingPack);
    if (isNew) {
        mf = new Manifest();
        availablePacks.get(modpackIndex).addons.stream().filter((Addon t) -> t.install)
                .forEach(installList::add);
    } else {
        mf = manifest.get(workingPack);
        availablePacks.get(modpackIndex).addons.stream().forEach((Addon a) -> {
            if (a.install && !mf.containsKey(a.name)) {
                installList.add(a);
            } else if ((mf.containsKey(a.name)) && !a.install) {
                removeList.add(a.name);
            }
        });
    }

    /* searching it in the list is better than relaying on the dirBox */
    String directory = null;
    for (Pack p : packList) {
        if (p.name.equals(workingPack)) {
            directory = p.directory;
            break;
        }
    }

    for (String t : removeList) {
        ArrayList<String> files = mf.get(t).files;
        files.sort(new PathComparator());
        for (String f : files) {
            new File(directory, f).delete();
        }
        mf.remove(t);
        log.println("Addon " + t + " removed.");
    }

    n = 0;
    for (Addon a : installList) {
        log.setIndeterminate();
        log.setStatusText("Installing Addon " + Integer.toString(++n) + "/" + installList.size());
        AddonManifest amf = new AddonManifest();
        amf.version = a.version;
        if (downloadArchive(workingPack + "/" + a.archive)) {
            amf.files = downloadedFiles;
            mf.put(a.name, amf);
            log.reset();
        } else {
            log.println("Addon " + a.name + " failed.");
            log.setStatusText("Error");
            log.reset();
            return false;
        }
    }

    if (isNew) {
        manifest.put(workingPack, mf);
    }

    try (FileWriter fw = new FileWriter(new File(directory, "manifest.json"))) {
        gson.toJson(mf, fw);
    } catch (IOException ex1) {
        log.println("Writing manifest file failed.");
        Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex1);
    }
    return true;
}

From source file:fr.arlefebvre.pronostics.controller.UEFATeamsController.java

@RequestMapping("/uefa/teams")
public List<Team> teams() {
    if (pseudoCache != null && !pseudoCache.isEmpty())
        return pseudoCache;
    ArrayList<Team> result = new ArrayList<Team>();
    String uri = "http://fr.fifa.com/fifa-world-ranking/ranking-table/men/uefa.html";

    //On se connecte au site et on charge le document html

    Document doc;/*from   w w w.j  a  va 2  s .  co  m*/
    try {
        doc = Jsoup.connect(uri).get();
        Elements elements = doc.getElementsByClass("table");
        for (Element element : elements) {
            Element tbody = element.getElementsByTag("tbody").first();
            for (Element child : tbody.children()) {
                Element teamNameElement = child.getElementsByClass("tbl-teamname").first();
                String name = teamNameElement.text();
                String countryCode = child.getElementsByClass("tbl-countrycode").first().text();
                String imgUrl = teamNameElement.select("img").first().absUrl("src");
                Team team = new Team();
                team.setName(name);
                team.setCountryCode(countryCode);
                team.setImgUrl(imgUrl);
                team.setNationalTeam(true);
                result.add(team);
            }
        }

        //String titre =  element.text();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //        RestTemplate restTemplate = new RestTemplate();
    //        ResponseEntity<ChampionListDto> response = restTemplate.getForEntity(
    //                uri,
    //                ChampionListDto.class);
    //
    //        List<ChampionDto> champions = response.getBody().getChampions();
    //        return champions.stream().map(c -> getChampionById(c.getId()).getName()).collect(Collectors.toList());
    result.sort((t1, t2) -> t1.getName().compareTo(t2.getName()));
    if (pseudoCache == null)
        pseudoCache = result;
    return result;
}

From source file:pcgen.io.PCGVer2Creator.java

private void appendAbilityLines(StringBuilder buffer) {
    ArrayList<AbilityCategory> categories = new ArrayList<>(getGameMode().getAllAbilityCategories());
    categories.add(AbilityCategory.LANGBONUS);

    Collection<CNAbilitySelection> virtSave = thePC.getSaveAbilities();

    categories.sort((a, b) -> a.getKeyName().compareTo(b.getKeyName()));

    for (final AbilityCategory cat : categories) {
        final List<CNAbility> normalAbilitiesToSave = new ArrayList<>(
                thePC.getPoolAbilities(cat, Nature.NORMAL));

        // ABILITY:FEAT|NORMAL|Feat Key|APPLIEDTO:xxx|TYPE:xxx|SAVE:xxx|DESC:xxx
        Collections.sort(normalAbilitiesToSave);
        for (final CNAbility ability : normalAbilitiesToSave) {
            writeAbilityToBuffer(buffer, ability);
        }//w  w  w  .  ja  v  a2  s .  c om
        boolean hasVirt = false;
        for (final CNAbilitySelection ability : virtSave) {
            CNAbility cnAbility = ability.getCNAbility();
            if (cnAbility.getAbilityCategory().equals(cat)) {
                //TODO Need to write each CNAbility only once :/
                writeAbilityToBuffer(buffer, cnAbility);
                hasVirt = true;
            }
        }
        if (!normalAbilitiesToSave.isEmpty() || hasVirt || thePC.getUserPoolBonus(cat) != 0.0) {
            buffer.append(IOConstants.TAG_USERPOOL).append(IOConstants.TAG_END);
            buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
            buffer.append(IOConstants.TAG_POOLPOINTS).append(IOConstants.TAG_END);
            buffer.append(thePC.getUserPoolBonus(cat));
            buffer.append(IOConstants.LINE_SEP);
        }
    }
}