Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#2 filter #10

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open

Feat/#2 filter #10

wants to merge 12 commits into from

Conversation

Hoyoung027
Copy link
Collaborator

@Hoyoung027 Hoyoung027 commented Jan 15, 2025

πŸ›°οΈ Issue Number

#2

πŸͺ μž‘μ—… λ‚΄μš©

  • μ½”λ“œ 리뷰 λ°˜μ˜ν•˜μ—¬ λ¦¬νŽ™ν† λ§ 진행
  • μ΄ˆκΈ°κ°’ μ΄ˆκΈ°ν™”λ₯Ό ν†΅ν•©λœ ν•¨μˆ˜ initializeFilter()둜 μˆ˜ν–‰
private Map<String, Object> initializeFilter(List<String> options) {
        return options.stream().collect(Collectors.toMap(option -> option, option -> 1));
    }

    private Map<String, Object> initializePriceFilter(int minPrice, int maxPrice) {
        Map<String, Object> priceFilter = new HashMap<>();
        priceFilter.put("minPrice", minPrice);
        priceFilter.put("maxPrice", maxPrice);
        return priceFilter;
    }
  • getFilteredCategory의 필터링 κΈ°λŠ₯을 matchesFilter둜 λΆ„λ¦¬ν•˜μ—¬ μ½”λ“œ 가독성을 λ†’μž„
 public List<Long> getFilteredCategory(List<CategoryEntity> categoryEntities) {
        Integer binaryRegionFilter = convertToBinaryFilter(regionFilter);
        Integer binaryTypeFilter = convertToBinaryFilter(typeFilter);
        Integer binaryPurposeFilter = convertToBinaryFilter(purposeFilter);
        Integer binaryActivityFilter = convertToBinaryFilter(activityFilter);
        Integer binaryEtcFilter = convertToBinaryFilter(etcFilter);
        Integer minPrice = (Integer) priceFilter.getOrDefault("minPrice", DEFAULT_MIN_PRICE);
        Integer maxPrice = (Integer) priceFilter.getOrDefault("maxPrice", MAX_PRICE);

        return categoryEntities.stream()
                .filter(category -> matchesFilter(category, binaryRegionFilter, binaryTypeFilter, binaryPurposeFilter, binaryActivityFilter, binaryEtcFilter, minPrice, maxPrice))
                .map(CategoryEntity::getId)
                .collect(Collectors.toList());
    }

    private boolean matchesFilter(CategoryEntity category, int binaryRegionFilter, int binaryTypeFilter, int binaryPurposeFilter, int binaryActivityFilter, int binaryEtcFilter, int minPrice, int maxPrice) {
        return (category.getRegion() & binaryRegionFilter) != 0 &&
                (category.getType() & binaryTypeFilter) != 0 &&
                (category.getPurpose() & binaryPurposeFilter) != 0 &&
                (category.getActivity() & binaryActivityFilter) != 0 &&
                (category.getEtc() & binaryEtcFilter) != 0 &&
                category.getPrice() >= minPrice &&
                category.getPrice() <= maxPrice;
    }
  • μœ μ‚¬λ„κ°€ λ†’μ•˜λ˜ getRegionFilterKey(), getTypeFilterKey()λ₯Ό 단일 ν•¨μˆ˜ getFilterKey()둜 톡합
public String getFilterKey(int binaryFilter, Map<String, Object> filterMap) {

        String filterKey = "";
        int position = 0;

        for (Map.Entry<String, Object> entry : filterMap.entrySet()) {
            if ((binaryFilter & (1 << position)) != 0) {
                filterKey = entry.getKey();
                break;
            }
            position++;
        }
        return filterKey;
    }
  • replaceAll κΈ°λŠ₯을 μ΄μš©ν•˜μ—¬ setFilter()의 반볡적인 μ½”λ“œ κ°„μ†Œν™”
public void setFilterValue(Map<String, Object> filter, int value) {
        filter.replaceAll((key, oldValue) -> value);
    }

πŸ“š Reference


βœ… Check List

  • μ½”λ“œκ°€ μ •μƒμ μœΌλ‘œ μ»΄νŒŒμΌλ˜λ‚˜μš”?
  • ν¬μŠ€νŠΈλ§¨μ—μ„œ 결과값을 μ œλŒ€λ‘œ ν™•μΈν–ˆλ‚˜μš”?
  • 리뷰어 섀정을 μ§€μ •ν–ˆλ‚˜μš”?
  • mergeν•  브랜치의 μœ„μΉ˜λ₯Ό ν™•μΈν–ˆλ‚˜μš”?
  • Label을 μ§€μ •ν–ˆλ‚˜μš”?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant