Collections.sort( sortedEntities, new Comparator() { public int compare( Object aa, Object bb ) { Entity a = (Entity)aa; Entity b = (Entity)bb;
Collections.sort( sortedEntities, new Comparator<Entity>() { public int compare( Entity a, Entity b ) {
    public void refreshEntities() {        lisEntities.removeAll();        int listIndex = 0;        boolean localUnits = false;        entityCorrespondance = new int[client.game.getNoOfEntities()];        /* We will attempt to sort by the following criteria: My units        first, then my teamates units, then other teams units.  We        will also sort by player name within the forementioned        categories.  Finally, a players units will be sorted by the        order they were "added" to the list.        */        LinkedList sortedEntities = new LinkedList();        for (Enumeration i = client.getEntities(); i.hasMoreElements();) {            Entity entity = (Entity) i.nextElement();            sortedEntities.add(entity);        }        Collections.sort( sortedEntities, new Comparator() {                public int compare( Object aa, Object bb ) {                    Entity a = (Entity)aa;                    Entity b = (Entity)bb;                    Player p_a = a.getOwner();                    Player p_b = b.getOwner();                    int t_a = p_a.getTeam();                    int t_b = p_b.getTeam();                    if (p_a.equals(client.getLocalPlayer()) &&                        !p_b.equals(client.getLocalPlayer())) {                        return -1;                    } else if (p_b.equals(client.getLocalPlayer()) &&                               !p_a.equals(client.getLocalPlayer())) {                        return 1;                    } else if (t_a == client.getLocalPlayer().getTeam()                               && t_b != client.getLocalPlayer().getTeam()) {                        return -1;                    } else if (t_b == client.getLocalPlayer().getTeam()                               && t_a != client.getLocalPlayer().getTeam()) {                        return 1;                    } else if (t_a != t_b) {                        return t_a - t_b;                    } else if (!p_a.equals(p_b)) {                        return p_a.getName().compareTo(p_b.getName());                    } else {                        return a.getId() - b.getId();                    }                }            } );        for (Iterator i = sortedEntities.iterator(); i.hasNext();) {            Entity entity = (Entity) i.next();            // Remember if the local player has units.            if (!localUnits && entity.getOwner().equals(client.getLocalPlayer())) {                localUnits = true;            }            if (!client.game.getOptions().booleanOption("pilot_advantages")) { //$NON-NLS-1$                entity.getCrew().clearAdvantages();            }            // Handle the "Blind Drop" option.            if (!entity.getOwner().equals(client.getLocalPlayer())                && client.game.getOptions().booleanOption("blind_drop") //$NON-NLS-1$                && !client.game.getOptions().booleanOption("real_blind_drop")) { //$NON-NLS-1$                lisEntities.add(ChatLounge.formatUnit(entity, true));                entityCorrespondance[listIndex++] = entity.getId();            } else if (entity.getOwner().equals(client.getLocalPlayer())                       || (!client.game.getOptions().booleanOption("blind_drop") //$NON-NLS-1$                       && !client.game.getOptions().booleanOption("real_blind_drop"))) { //$NON-NLS-1$                lisEntities.add(ChatLounge.formatUnit(entity, false));                entityCorrespondance[listIndex++] = entity.getId();            }        }        // Enable the "Save Unit List..." and "Delete All"        // buttons if the local player has units.        butSaveList.setEnabled(localUnits);        butDeleteAll.setEnabled(localUnits);        butViewGroup.setEnabled(lisEntities.getItemCount() != 0);        // Disable the "must select" buttons.        butCustom.setEnabled(false);        butMechReadout.setEnabled(false);        butDelete.setEnabled(false);    }