Skip to content

Configuration should accept values of Typed features #126

@jmhorcas

Description

@jmhorcas

Is your feature request related to a problem? Please describe.
Current configuration only considers boolean values for features.

Describe the solution you'd like
Here the code adapted to support Typed features (I do not upload until fully tested).
Changes:

  • change: type of elements from bool to Any.
  • add: new get_value() method to return the value of an element.
  • add: is_selected(element) method to check whether an element is selected.
  • fix: get_selected_elements() method to consider typed features.
from typing import Any, Iterator
from flamapy.core.models import VariabilityModel


class Configuration(VariabilityModel):

    @staticmethod
    def get_extension() -> str:
        return 'configuration'

    def __init__(self, elements: dict[Any, Any]) -> None:
        self.elements = elements
        self.is_full = False

    def set_full(self, is_full: bool) -> None:
        self.is_full = is_full

    def get_selected_elements(self) -> list[Any]:
        return [e for e in self.elements if self.is_selected(e) and self.elements[e] is not None]

    def is_selected(self, element: Any) -> bool:
        return element in self.elements and (not isinstance(self.elements[element], bool) or 
                                             self.elements[element])

    def get_value(self, element: Any) -> Any:
        return self.elements[element]
    
    def __eq__(self, other: object) -> bool:
        if isinstance(other, Configuration):
            return self.elements == other.elements
        return False

    def __hash__(self) -> int:
        return hash(frozenset(self.elements.items()))

    def __str__(self) -> str:
        return ', '.join([str(e) for e in self.get_selected_elements()])

    def __repr__(self) -> str:
        return f"Configuration({self.elements})"

    def __iter__(self) -> Iterator[Any]:
        return iter(self.elements)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions