<commit_before>package cn.momia.service.product.facade;

import cn.momia.api.common.region.Region;
import cn.momia.service.base.util.TimeUtil;
import cn.momia.service.product.base.BaseProduct;
import cn.momia.service.product.place.Place;
import cn.momia.service.product.sku.Sku;
import com.alibaba.fastjson.JSONArray;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

public class Product implements Serializable {
    public static class Type {
        public static final int MINI = 1;
        public static final int BASE = 2;
        public static final int BASE_WITH_SKU = 3;
        public static final int FULL = 4;
    }

    private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("M月d日");

    public static final Product NOT_EXIST_PRODUCT = new Product() {
        @Override
        public long getId() {
            return 0;
        }
    };

    private BaseProduct baseProduct;
    private List<ProductImage> imgs;
    private List<Place> places;
    private List<Sku> skus;

    public long getId() {
        return baseProduct.getId();
    }

    public int getCityId() {
        return baseProduct.getCityId();
    }

    public List<String> getTags() {
        return baseProduct.getTags();
    }

    public String getTitle() {
        return baseProduct.getTitle();
    }

    public String getAbstracts(){ return baseProduct.getAbstracts(); }

    public String getCover() {
        return baseProduct.getCover();
    }

    public String getThumb() {
        return baseProduct.getThumb();
    }

    public String getCrowd() {
        return baseProduct.getCrowd();
    }

    public JSONArray getContent() {
        return baseProduct.getContent();
    }

    public int getJoined() {
        return baseProduct.getJoined();
    }

    public int getSales() {
        return baseProduct.getSales();
    }

    public boolean isSoldOut() {
        return baseProduct.isSoldOut();
    }

    public Date getOnlineTime() {
        return baseProduct.getOnlineTime();
    }

    public Date getOfflineTime() {
        return baseProduct.getOfflineTime();
    }

    public int getStatus() {
        return baseProduct.getStatus();
    }

    public boolean isOpened() {
        Date now = new Date();
        if (getOfflineTime().before(now) || isSoldOut() || getStatus() != 1) return false;

        return !Sku.filterClosed(skus).isEmpty();
    }

    public void setBaseProduct(BaseProduct baseProduct) {
        this.baseProduct = baseProduct;
    }

    public List<ProductImage> getImgs() {
        return imgs;
    }

    public void setImgs(List<ProductImage> imgs) {
        this.imgs = imgs;
    }

    public int getRegionId() {
        if (places.size() > 1) return Region.MULTI_REGION_ID;
        return places.get(0).getRegionId();
    }

    public String getAddress() {
        if (places.size() > 1) return "多个地点可供选择";
        return places.get(0).getAddress();
    }

    public String getPoi() {
        Place nearestPlace = places.get(0); // TODO 选最近的
        return nearestPlace.getLng() + ":" + nearestPlace.getLat();
    }

    public List<Place> getPlaces() {
        return places;
    }

    public void setPlaces(List<Place> places) {
        this.places = places;
    }

    public List<Sku> getSkus() {
        return skus;
    }

    public void setSkus(List<Sku> skus) {
        this.skus = skus;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Product)) return false;

        Product product = (Product) o;

        return getId() == product.getId();
    }

    @Override
    public int hashCode() {
        return (int) (getId() ^ (getId() >>> 32));
    }

    public boolean exists() {
        return !this.equals(NOT_EXIST_PRODUCT);
    }

    public boolean isInvalid() {
        return !(baseProduct != null && baseProduct.exists() &&
                imgs != null && !imgs.isEmpty() &&
                places != null && !places.isEmpty() &&
                skus != null && !skus.isEmpty());
    }

    public String getScheduler() {
        if(skus == null || skus.isEmpty()) return "";

        List<Date> times = new ArrayList<Date>();
        for (Sku sku : Sku.filterFinished(skus)) {
            times.addAll(sku.getStartEndTimes());
        }
        Collections.sort(times);

        return format(times);
    }

    private String format(List<Date> times) {
        if (times.isEmpty()) return "";
        if (times.size() == 1) {
            Date start = times.get(0);
            return DATE_FORMATTER.format(start) + " " + TimeUtil.getWeekDay(start);<commit_msg>改用sku.isFinished<commit_after>package cn.momia.service.product.facade;

import cn.momia.api.common.region.Region;
import cn.momia.service.base.util.TimeUtil;
import cn.momia.service.product.base.BaseProduct;
import cn.momia.service.product.place.Place;
import cn.momia.service.product.sku.Sku;
import com.alibaba.fastjson.JSONArray;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

public class Product implements Serializable {
    public static class Type {
        public static final int MINI = 1;
        public static final int BASE = 2;
        public static final int BASE_WITH_SKU = 3;
        public static final int FULL = 4;
    }

    private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("M月d日");

    public static final Product NOT_EXIST_PRODUCT = new Product() {
        @Override
        public long getId() {
            return 0;
        }
    };

    private BaseProduct baseProduct;
    private List<ProductImage> imgs;
    private List<Place> places;
    private List<Sku> skus;

    public long getId() {
        return baseProduct.getId();
    }

    public int getCityId() {
        return baseProduct.getCityId();
    }

    public List<String> getTags() {
        return baseProduct.getTags();
    }

    public String getTitle() {
        return baseProduct.getTitle();
    }

    public String getAbstracts(){ return baseProduct.getAbstracts(); }

    public String getCover() {
        return baseProduct.getCover();
    }

    public String getThumb() {
        return baseProduct.getThumb();
    }

    public String getCrowd() {
        return baseProduct.getCrowd();
    }

    public JSONArray getContent() {
        return baseProduct.getContent();
    }

    public int getJoined() {
        return baseProduct.getJoined();
    }

    public int getSales() {
        return baseProduct.getSales();
    }

    public boolean isSoldOut() {
        return baseProduct.isSoldOut();
    }

    public Date getOnlineTime() {
        return baseProduct.getOnlineTime();
    }

    public Date getOfflineTime() {
        return baseProduct.getOfflineTime();
    }

    public int getStatus() {
        return baseProduct.getStatus();
    }

    public boolean isOpened() {
        Date now = new Date();
        if (getOfflineTime().before(now) || isSoldOut() || getStatus() != 1) return false;

        return !Sku.filterClosed(skus).isEmpty();
    }

    public void setBaseProduct(BaseProduct baseProduct) {
        this.baseProduct = baseProduct;
    }

    public List<ProductImage> getImgs() {
        return imgs;
    }

    public void setImgs(List<ProductImage> imgs) {
        this.imgs = imgs;
    }

    public int getRegionId() {
        if (places.size() > 1) return Region.MULTI_REGION_ID;
        return places.get(0).getRegionId();
    }

    public String getAddress() {
        if (places.size() > 1) return "多个地点可供选择";
        return places.get(0).getAddress();
    }

    public String getPoi() {
        Place nearestPlace = places.get(0); // TODO 选最近的
        return nearestPlace.getLng() + ":" + nearestPlace.getLat();
    }

    public List<Place> getPlaces() {
        return places;
    }

    public void setPlaces(List<Place> places) {
        this.places = places;
    }

    public List<Sku> getSkus() {
        return skus;
    }

    public void setSkus(List<Sku> skus) {
        this.skus = skus;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Product)) return false;

        Product product = (Product) o;

        return getId() == product.getId();
    }

    @Override
    public int hashCode() {
        return (int) (getId() ^ (getId() >>> 32));
    }

    public boolean exists() {
        return !this.equals(NOT_EXIST_PRODUCT);
    }

    public boolean isInvalid() {
        return !(baseProduct != null && baseProduct.exists() &&
                imgs != null && !imgs.isEmpty() &&
                places != null && !places.isEmpty() &&
                skus != null && !skus.isEmpty());
    }

    public String getScheduler() {
        if(skus == null || skus.isEmpty()) return "";

        Date now = new Date();
        List<Date> times = new ArrayList<Date>();
        for (Sku sku : skus) {
            if (!sku.isFinished(now)) times.addAll(sku.getStartEndTimes());
        }
        Collections.sort(times);

        return format(times);
    }

    private String format(List<Date> times) {
        if (times.isEmpty()) return "";
        if (times.size() == 1) {
            Date start = times.get(0);
            return DATE_FORMATTER.format(start) + " " + TimeUtil.getWeekDay(start);
{'fraction_non_alphanumeric': 0.11768368617683686, 'fraction_numerical': 0.00311332503113325, 'mean_word_length': 2.399294532627866, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 39, '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': '262698', 'n_tokens_mistral': 2984, 'n_tokens_neox': 2855, 'n_words': 693}