<commit_before>import java.io.PrintStream;
import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: john
 * Date: 11/12/2010
 * Time: 12:17:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class WantList {
    private List<TradeRequest> wants;
    private Geeklist geeklist;
    private Map<String, Integer> spendingLimits = new HashMap<String, Integer>();
    private Set<String> errors;
    private Map<String, Set<String>> wantedBy = new HashMap<String, Set<String>>();

    WantList(List<TradeRequest> wants, Set<String> errors) {
        this.wants = wants;
        this.errors = errors;
        inferSpendingLimits();
    }

    private void inferSpendingLimits() {
        Map<String, Integer> highestOffer = new HashMap<String, Integer>();
        Map<String, Integer> numOffers = new HashMap<String, Integer>();
        for (Iterator<TradeRequest> iter = wants.iterator(); iter.hasNext(); ) {
            TradeRequest request = iter.next();
            if (request.getItemName().equalsIgnoreCase("LIMIT")) {
                if (spendingLimits.containsKey(request.getUserName())) {
                    errors.add(request.getUserName() + " has more than one spending limit");
                }
                if (request.willAccept().size() > 1) {
                    throw new RuntimeException(request.getUserName() + " has a nonsense spending limit");
                }
                spendingLimits.put(request.getUserName(), Money.parseMoney(request.willAccept().get(0)));
                iter.remove();
            } else if (request.isMoney()) {
                int m = request.getAmount();
                if (highestOffer.get(request.getUserName()) == null || m > highestOffer.get(request.getUserName())) {
                    highestOffer.put(request.getUserName(), m);
                }
                Integer n = numOffers.get(request.getUserName());
                if (n == null) n = 0;
                n = n + 1;
                numOffers.put(request.getUserName(), n);
            }
        }
        for (Map.Entry<String, Integer> entry : highestOffer.entrySet()) {
            if (!spendingLimits.containsKey(entry.getKey()) && numOffers.get(entry.getKey()) > 1) {
                spendingLimits.put(entry.getKey(), entry.getValue());
                errors.add(entry.getKey() + " is using a default spending limit");
            }
        }
    }

    public void setGeekList(Geeklist geeklist, Set<String> errors) {
        this.geeklist = geeklist;
        List<String> users = geeklist.getAllUsers();
        for (TradeRequest tr : wants) {
            if (!users.contains(tr.getUserName())) {
                // check for people using the wrong case in their user name in their wants.
                // this happens all the time.
                boolean found = false;
                for (String u : users)  {
                    if (u.equalsIgnoreCase(tr.getUserName())) {
                        tr.setUserName(u);
                        found = true;
                        break;
                    }
                }
                if (!found) errors.add("User " + tr.getUserName() + " has submitted wants but is not in the geeklist.");
            }
        }
    }

    public void check(Set<String> errors, PrintStream out) {<commit_msg>Infer limit with only one cash offer (but no need to output warning)<commit_after>import java.io.PrintStream;
import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: john
 * Date: 11/12/2010
 * Time: 12:17:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class WantList {
    private List<TradeRequest> wants;
    private Geeklist geeklist;
    private Map<String, Integer> spendingLimits = new HashMap<String, Integer>();
    private Set<String> errors;
    private Map<String, Set<String>> wantedBy = new HashMap<String, Set<String>>();

    WantList(List<TradeRequest> wants, Set<String> errors) {
        this.wants = wants;
        this.errors = errors;
        inferSpendingLimits();
    }

    private void inferSpendingLimits() {
        //System.out.println("Infer spending limits");

        Map<String, Integer> highestOffer = new HashMap<String, Integer>();
        Map<String, Integer> numOffers = new HashMap<String, Integer>();
        for (Iterator<TradeRequest> iter = wants.iterator(); iter.hasNext(); ) {
            TradeRequest request = iter.next();
            if (request.getItemName().equalsIgnoreCase("LIMIT")) {
                if (spendingLimits.containsKey(request.getUserName())) {
                    errors.add(request.getUserName() + " has more than one spending limit");

                    System.out.println("ERROR: " + request.getUserName() + " has more than one spending limit");

                }
                if (request.willAccept().size() > 1) {
                    throw new RuntimeException(request.getUserName() + " has a nonsense spending limit");
                }

                //System.out.println("Sending limit " + request.getUserName() + ": " + request.willAccept().get(0));

                spendingLimits.put(request.getUserName(), Money.parseMoney(request.willAccept().get(0)));
                iter.remove();
            } else if (request.isMoney()) {
                //System.out.println("Money offer " + request.getUserName());

                int m = request.getAmount();
                if (highestOffer.get(request.getUserName()) == null || m > highestOffer.get(request.getUserName())) {
                    highestOffer.put(request.getUserName(), m);
                }
                Integer n = numOffers.get(request.getUserName());
                if (n == null) n = 0;
                n = n + 1;
                numOffers.put(request.getUserName(), n);
            }
        }
        for (Map.Entry<String, Integer> entry : highestOffer.entrySet()) {
            //System.out.println("Highest offer " + entry.getKey() + ": " + entry.getValue() + " for " + numOffers.get(entry.getKey()));

            if (!spendingLimits.containsKey(entry.getKey()) && numOffers.get(entry.getKey()) >= 1) {
                spendingLimits.put(entry.getKey(), entry.getValue());
                System.out.println("WARNING: " + entry.getKey() + " is using a default spending limit" + numOffers.get(entry.getKey()) + " cash offer(s)");

                // Need to add default limit for one offer (otherwise it won't count), but only need error message if 2 or more offers
                if (numOffers.get(entry.getKey()) > 1) {
                    errors.add(entry.getKey() + " is using a default spending limit for " + numOffers.get(entry.getKey()) + " cash offer(s)");
                }
            }
        }
    }

    public void setGeekList(Geeklist geeklist, Set<String> errors) {
        this.geeklist = geeklist;
        List<String> users = geeklist.getAllUsers();
        for (TradeRequest tr : wants) {
            if (!users.contains(tr.getUserName())) {
                // check for people using the wrong case in their user name in their wants.
                // this happens all the time.
                boolean found = false;
                for (String u : users)  {
                    if (u.equalsIgnoreCase(tr.getUserName())) {
                        tr.setUserName(u);
                        found = true;
                        break;
                    }
                }
                if (!found) errors.add("User " + tr.getUserName() + " has submitted wants but is not in the geeklist.");
            }
        }
    }

    public void check(Set<String> errors, PrintStream out) {
{'fraction_non_alphanumeric': 0.12529457973291439, 'fraction_numerical': 0.00536789735532862, 'mean_word_length': 1.9700622083981338, 'pattern_counts': {'":': 2, '<': 41, '<?xml version=': 0, '>': 48, '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': '719843', 'n_tokens_mistral': 2136, 'n_tokens_neox': 2035, 'n_words': 514}