J.Dhaik
J.Dhaik

Reputation: 103

Filter on Unequal Hash Set List

I have hashset 1-7.

These Hashset respond to 9 priorityCodes;

Hash Set Value 1 means 1, 2 and 3

The Hash Set is the filter values, except the first value in the Hash Set correspond to three of the prioritycodes.

How do I filter my list on this? Is there any way to basically do a "if hashSet has the value 1 to turn that into priorityCode 1-3?

This is how it used to work, but the design changed to represent 1-7 while the priority code values set in the database/backend remained the same.

   private static IEnumerable<TabularScheduledItemViewModel> FilterByPriority(
            ICollection<int> hashSet,
            IEnumerable<TabularScheduledItemViewModel> jobList)
        {
                
            if (hashSet.Contains(1))
            {
              
            }
            
            return priorityFilter.Count == 0
                ? jobList
                : jobList.Where(c => priorityFilter.Any(o => o == c.PriorityCode));
        }

How the UI looks enter image description here

Upvotes: 0

Views: 285

Answers (1)

Eric J.
Eric J.

Reputation: 150108

Nothing in your code looks like a hash set. As I understand the problem, you receive a collection of numbers in the range 1..9 coming from the database and you want to map that to the range 1..7 for the UI by collapsing the first 3 database values into 1 and shifting the rest down. You can do that e.g. with a new line at the start of your function:

var mapped = hashSet.Select(i => i <= 3 ? 1 : i - 2).ToHashSet();

Then use mapped instead of hashSet. Note this gives you a true hash set, so duplicate values in the input are collapsed. If you don't desire that, use .ToList() or .ToArray() instead.

Upvotes: 2

Related Questions