<commit_before>package nxt.http;

import nxt.DigitalGoodsStore;
import nxt.NxtException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

public final class GetDGSGoods extends APIServlet.APIRequestHandler {

    static final GetDGSGoods instance = new GetDGSGoods();

    private GetDGSGoods() {
        super("seller", "firstIndex", "lastIndex", "inStockOnly");
    }

    @Override
    JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
        Long sellerId = ParameterParser.getSellerId(req);
        int firstIndex = ParameterParser.getFirstIndex(req);
        int lastIndex = ParameterParser.getLastIndex(req);
        boolean inStockOnly = !"false".equalsIgnoreCase(req.getParameter("inStockOnly"));

        JSONObject response = new JSONObject();
        JSONArray goodsJSON = new JSONArray();
        response.put("goods", goodsJSON);

        if (sellerId == null) {
            DigitalGoodsStore.Goods[] goods = DigitalGoodsStore.getAllGoods().toArray(new DigitalGoodsStore.Goods[0]);
            for (int i = firstIndex; firstIndex + goodsJSON.size() - 1 <= lastIndex && i < goods.length; i++) {
                DigitalGoodsStore.Goods good = goods[goods.length - 1 - i];
                if (inStockOnly && (((good.isDelisted() || good.getQuantity() == 0)))) {
                    continue;
                }
                goodsJSON.add(JSONData.goods(goods[goods.length - 1 - i]));
            }
            return response;
        }

        Collection<DigitalGoodsStore.Goods> goods = DigitalGoodsStore.getSellerGoods(sellerId);
        int i = 0;
        for (DigitalGoodsStore.Goods good : goods) {
            if (i > lastIndex) {
                break;
            }
            if (i >= firstIndex) {
                goodsJSON.add(JSONData.goods(good));
            }
            i++;
        }
        return response;
    }

}
<commit_msg>apply inStockOnly filter to seller goods too<commit_after>package nxt.http;

import nxt.DigitalGoodsStore;
import nxt.NxtException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

public final class GetDGSGoods extends APIServlet.APIRequestHandler {

    static final GetDGSGoods instance = new GetDGSGoods();

    private GetDGSGoods() {
        super("seller", "firstIndex", "lastIndex", "inStockOnly");
    }

    @Override
    JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
        Long sellerId = ParameterParser.getSellerId(req);
        int firstIndex = ParameterParser.getFirstIndex(req);
        int lastIndex = ParameterParser.getLastIndex(req);
        boolean inStockOnly = !"false".equalsIgnoreCase(req.getParameter("inStockOnly"));

        JSONObject response = new JSONObject();
        JSONArray goodsJSON = new JSONArray();
        response.put("goods", goodsJSON);

        if (sellerId == null) {
            DigitalGoodsStore.Goods[] goods = DigitalGoodsStore.getAllGoods().toArray(new DigitalGoodsStore.Goods[0]);
            for (int i = firstIndex; firstIndex + goodsJSON.size() - 1 <= lastIndex && i < goods.length; i++) {
                DigitalGoodsStore.Goods good = goods[goods.length - 1 - i];
                if (inStockOnly && (((good.isDelisted() || good.getQuantity() == 0)))) {
                    continue;
                }
                goodsJSON.add(JSONData.goods(goods[goods.length - 1 - i]));
            }
            return response;
        }

        Collection<DigitalGoodsStore.Goods> goods = DigitalGoodsStore.getSellerGoods(sellerId);
        int i = 0;
        for (DigitalGoodsStore.Goods good : goods) {
            if (i > lastIndex) {
                break;
            }
            if (i >= firstIndex) {
                if (inStockOnly && (((good.isDelisted() || good.getQuantity() == 0)))) {
                    continue;
                }
                goodsJSON.add(JSONData.goods(good));
            }
            i++;
        }
        return response;
    }

}

{'fraction_non_alphanumeric': 0.1114529105537151, 'fraction_numerical': 0.003076194983435873, 'mean_word_length': 2.387019230769231, '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': '4104370', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1188, 'n_words': 246}