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

Create a generic utility for filtering enums #3146

Closed
anandwana001 opened this issue Apr 30, 2021 · 14 comments · Fixed by #5529
Closed

Create a generic utility for filtering enums #3146

anandwana001 opened this issue Apr 30, 2021 · 14 comments · Fixed by #5529
Assignees
Labels
enhancement End user-perceivable enhancements. good first issue This item is good for new contributors to make their pull request. Impact: Low Low perceived user impact (e.g. edge cases). Work: Low Solution is clear and broken into good-first-issue-sized chunks. Z-ibt Temporary label for Ben to keep track of issues he's triaged.

Comments

@anandwana001
Copy link
Contributor

anandwana001 commented Apr 30, 2021

Is your feature request related to a problem? Please describe.
Currently, in all our enum files, we usually use similar items filtering.

Some examples of filtering include:

chapterSummaries.map(ChapterSummary::getChapterPlayState)

Describe the solution you'd like
Generalize filtering which can be used by all the enum.

Describe alternatives you've considered

interface EnumWithKey<T : Enum<T>, K> {
  val T.key: K
}
inline fun <reified T : Enum<T>, K> EnumWithKey<T, K>.getValue(key: K): T {
  return enumValues<T>().find { it.key == key }
    ?: throw IllegalStateException("In the enum ${T::class.java} " +
      "there should be at least one enumeration")
}

Additional context
Look here for learning purpose - https://gist.github.com/programmerr47/e1a62f912c735249c89c3f5c44b6b366#file-enum-kt

@Broppia Broppia added issue_type_infrastructure Impact: Low Low perceived user impact (e.g. edge cases). labels Jul 29, 2022
@BenHenning BenHenning added Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. Z-ibt Temporary label for Ben to keep track of issues he's triaged. issue_user_developer labels Sep 15, 2022
@seanlip seanlip added enhancement End user-perceivable enhancements. and removed issue_type_infrastructure labels Mar 28, 2023
@MohitGupta121 MohitGupta121 added the Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. label Jun 16, 2023
@adhiamboperes adhiamboperes added good first issue This item is good for new contributors to make their pull request. and removed Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. labels Mar 26, 2024
@adhiamboperes adhiamboperes changed the title Generalize Enum Findings Create a generic utility for filtering enums Mar 26, 2024
@adhiamboperes adhiamboperes added Work: Low Solution is clear and broken into good-first-issue-sized chunks. and removed Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. labels Mar 26, 2024
@whyash8
Copy link
Contributor

whyash8 commented Aug 7, 2024

I want to work on this issue.

@adhiamboperes
Copy link
Collaborator

adhiamboperes commented Aug 7, 2024

@whyash8, Please feel free to put up a draft PR with a solution.

@whyash8
Copy link
Contributor

whyash8 commented Aug 7, 2024

Ok sir

@whyash8
Copy link
Contributor

whyash8 commented Aug 26, 2024

i have found a solution for the issue and i need some guidance. please help!

@adhiamboperes
Copy link
Collaborator

Hi @whyash8, please let us know how we can help. What challenge are you experiencing?

@whyash8
Copy link
Contributor

whyash8 commented Aug 26, 2024

i made some changes in the code. Now i need help in testing the changes. Please help

@adhiamboperes
Copy link
Collaborator

@whyash8, could you please create a PR with the code changes so that we can better help with the required tests?

@whyash8
Copy link
Contributor

whyash8 commented Aug 26, 2024

Ok

@whyash8
Copy link
Contributor

whyash8 commented Sep 4, 2024

I am getting this issues while pushing
Error: Invalid or corrupt jarfile ../oppia-android-tools/ktlint


Ktlint issue found.
Please help !!

@adhiamboperes
Copy link
Collaborator

Hi @whyash8, go to your project folder > oppia-android-tools > delete the ktlint file. Then on you terminal inside the project root, run bash setup.sh again. Should this not resolve your issue, please use the discussions tab to share more details on the issue with a screenshot of the error.

@whyash8
Copy link
Contributor

whyash8 commented Sep 5, 2024

Ok! thank you

@whyash8
Copy link
Contributor

whyash8 commented Sep 8, 2024

i made a PR . please help me to proceed further.

@whyash8

This comment was marked as off-topic.

@adhiamboperes
Copy link
Collaborator

@whyash8, if facing an issue that's not related to the issue, please post under the affected PR or discussions to avoid loss of context and cluttering the issue thread

subhajitxyz pushed a commit to subhajitxyz/oppia-android that referenced this issue Nov 19, 2024
## Explanation

Fixes: oppia#3146

This PR introduces a new utility function filterByEnumCondition to
standardize filtering of enums across various parts of the oppia-android
codebase. This utility function allows filtering of collections based on
a condition applied to enum values.

This PR introduces a new utility function filterByEnumCondition to
standardize filtering of enums across various parts of the oppia-android
codebase. This utility function allows filtering of collections based on
a condition applied to enum values.

**Key Changes**:
Added Utility Function:
filterByEnumCondition: A generic function to filter a collection based
on a condition applied to an enum extracted from each item in the
collection.

**Updated Existing Code**:
Refactored code in getLeastRecentMetricLogIndex,
getLeastRecentMediumPriorityEventIndex, and other methods to utilize the
new filterByEnumCondition function.
Updated the calculation of completedChapterCount and
inProgressChapterCount using the new utility function.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [ x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x ] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x ] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x ] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [ x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x ] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
-

---------

Co-authored-by: Adhiambo Peres <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement End user-perceivable enhancements. good first issue This item is good for new contributors to make their pull request. Impact: Low Low perceived user impact (e.g. edge cases). Work: Low Solution is clear and broken into good-first-issue-sized chunks. Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Development

Successfully merging a pull request may close this issue.

7 participants