<commit_before>package net.classicube.launcher;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.logging.Level;
import java.util.prefs.Preferences;

// Stores metadata about a user account.
// Handled by AccountManager.
public final class UserAccount {

    public String signInUsername;
    public String playerName;
    public String password;
    public Date signInDate;

    public UserAccount(final String username, final String password) {
        if (username == null) {
            throw new NullPointerException("username");
        }
        if (password == null) {
            throw new NullPointerException("password");
        }
        this.signInUsername = username;
        this.playerName = username;
        this.password = password;
        this.signInDate = new Date(0);
    }

    // Loads all information from a given Preferences node
    public UserAccount(final Preferences prefs) {
        if (prefs == null) {
            throw new NullPointerException("prefs");
        }
        this.signInUsername = prefs.get("SignInUsername", null);
        this.playerName = prefs.get("PlayerName", null);
        if (Prefs.getRememberPasswords()) {
            this.password = prefs.get("Password", "");
        } else {
            this.password = "";
        }
        final long dateTicks = prefs.getLong("SignInDate", 0);
        this.signInDate = new Date(dateTicks);
        if (this.signInUsername == null || this.playerName == null || this.password == null) {
            LogUtil.getLogger().log(Level.WARNING, "Could not parse pref as a sign-in account.");
            throw new IllegalArgumentException("Pref could not be parsed");
        }
    }

    // Stores all information into a given Preferences node
    public void store(final Preferences prefs) {
        if (prefs == null) {
            throw new NullPointerException("prefs");
        }
        prefs.put("SignInUsername", this.signInUsername);
        prefs.put("PlayerName", this.playerName);
        if (Prefs.getRememberPasswords()) {
            prefs.put("Password", <PASSWORD>);
        } else {
            prefs.put("Password", "");
        }
        prefs.putLong("SignInDate", this.signInDate.getTime());
    }

    // Gets a comparator that sorts servers by signInDate (most recent first)
    public static Comparator<UserAccount> getUptimeComparator() {
        return comparatorInstance;
    }
    private static final UserAccountDateComparator comparatorInstance = new UserAccountDateComparator();

    private static class UserAccountDateComparator
            implements Comparator<UserAccount>, Serializable {
        static final long serialVersionUID = 1L;

        @Override
        public int compare(final UserAccount o1, final UserAccount o2) {
            if(o1.signInDate.getTime()==0) return 1;
            if(o2.signInDate.getTime()==0) return -1;
            final Long delta = o2.signInDate.getTime() - o1.signInDate.getTime();
            return delta.intValue();
        }
    }
}<commit_msg>Fixed a possible overflow in UserAccountDateComparator, which would result in wrong sort order in "username" drop-down menu.<commit_after>package net.classicube.launcher;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.logging.Level;
import java.util.prefs.Preferences;

// Stores metadata about a user account.
// Handled by AccountManager.
public final class UserAccount {

    public String signInUsername;
    public String playerName;
    public String password;
    public Date signInDate;

    public UserAccount(final String username, final String password) {
        if (username == null) {
            throw new NullPointerException("username");
        }
        if (password == null) {
            throw new NullPointerException("password");
        }
        this.signInUsername = username;
        this.playerName = username;
        this.password = password;
        this.signInDate = new Date(0);
    }

    // Loads all information from a given Preferences node
    public UserAccount(final Preferences prefs) {
        if (prefs == null) {
            throw new NullPointerException("prefs");
        }
        this.signInUsername = prefs.get("SignInUsername", null);
        this.playerName = prefs.get("PlayerName", null);
        if (Prefs.getRememberPasswords()) {
            this.password = prefs.get("Password", "");
        } else {
            this.password = "";
        }
        final long dateTicks = prefs.getLong("SignInDate", 0);
        this.signInDate = new Date(dateTicks);
        if (this.signInUsername == null || this.playerName == null || this.password == null) {
            LogUtil.getLogger().log(Level.WARNING, "Could not parse pref as a sign-in account.");
            throw new IllegalArgumentException("Pref could not be parsed");
        }
    }

    // Stores all information into a given Preferences node
    public void store(final Preferences prefs) {
        if (prefs == null) {
            throw new NullPointerException("prefs");
        }
        prefs.put("SignInUsername", this.signInUsername);
        prefs.put("PlayerName", this.playerName);
        if (Prefs.getRememberPasswords()) {
            prefs.put("Password", <PASSWORD>);
        } else {
            prefs.put("Password", "");
        }
        prefs.putLong("SignInDate", this.signInDate.getTime());
    }

    // Gets a comparator that sorts servers by signInDate (most recent first)
    public static Comparator<UserAccount> getUptimeComparator() {
        return comparatorInstance;
    }
    private static final UserAccountDateComparator comparatorInstance = new UserAccountDateComparator();

    private static class UserAccountDateComparator
            implements Comparator<UserAccount>, Serializable {
        static final long serialVersionUID = 1L;

        @Override
        public int compare(final UserAccount o1, final UserAccount o2) {
            if(o1.signInDate.getTime()==0) return 1;
            if(o2.signInDate.getTime()==0) return -1;
            final Long delta = o2.signInDate.getTime() - o1.signInDate.getTime();
            return Long.signum(delta);
        }
    }
}
{'fraction_non_alphanumeric': 0.10242025965699632, 'fraction_numerical': 0.004167334508735374, 'mean_word_length': 2.5759312320916905, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2768124', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1658, 'n_words': 446}