Class GroupItem

    • Constructor Detail

      • GroupItem

        public GroupItem​(String name)
        Creates a plain GroupItem
        Parameters:
        name - name of the group
      • GroupItem

        public GroupItem​(String name,
                         @Nullable Item baseItem)
      • GroupItem

        public GroupItem​(String name,
                         @Nullable Item baseItem,
                         @Nullable GroupFunction function)
        Creates a GroupItem with function
        Parameters:
        name - name of the group
        baseItem - type of items in the group
        function - function to calculate group status out of member status
    • Method Detail

      • dispose

        public void dispose()
        Description copied from class: GenericItem
        Disposes this item. Clears all injected services and unregisters all change listeners. This does not remove this item from its groups. Removing from groups should be done externally to retain the member order in case this item is exchanged in a group.
        Overrides:
        dispose in class GenericItem
      • getBaseItem

        public @Nullable Item getBaseItem()
        Returns the base item of this GroupItem. This method is only intended to allow instance checks of the underlying BaseItem. It must not be changed in any way.
        Returns:
        the base item of this GroupItem
      • getFunction

        public @Nullable GroupFunction getFunction()
        Returns the function of this GroupItem.
        Returns:
        the function of this GroupItem
      • getMembers

        public Set<Item> getMembers()
        Returns the direct members of this GroupItem regardless if these members are GroupItems as well.
        Returns:
        the direct members of this GroupItem
      • getAllMembers

        public Set<Item> getAllMembers()
        Returns the direct members of this GroupItem and recursively all members of the potentially contained GroupItems as well. The GroupItems itself aren't contained. The returned items are unique.
        Returns:
        all members of this and all contained GroupItems
      • getMembers

        public Set<Item> getMembers​(Predicate<Item> filterItem)
        Retrieves ALL members of this group and filters it with the given Predicate
        Parameters:
        filterItem - Predicate with settings to filter member list
        Returns:
        Set of member items filtered by filterItem
      • addMember

        public void addMember​(Item item)
        Adds the given item to the members of this group item.
        Parameters:
        item - the item to be added (must not be null)
        Throws:
        IllegalArgumentException - if the given item is null
      • replaceMember

        public void replaceMember​(Item oldItem,
                                  Item newItem)
      • removeMember

        public void removeMember​(Item item)
        Removes the given item from the members of this group item.
        Parameters:
        item - the item to be removed (must not be null)
        Throws:
        IllegalArgumentException - if the given item is null
      • getAcceptedDataTypes

        public List<Class<? extends State>> getAcceptedDataTypes()
        The accepted data types of a group item is the same as of the underlying base item. If none is defined, the intersection of all sets of accepted data types of all group members is used instead.
        Specified by:
        getAcceptedDataTypes in interface Item
        Returns:
        the accepted data types of this group item
      • getAcceptedCommandTypes

        public List<Class<? extends Command>> getAcceptedCommandTypes()
        The accepted command types of a group item is the same as of the underlying base item. If none is defined, the intersection of all sets of accepted command types of all group members is used instead.
        Specified by:
        getAcceptedCommandTypes in interface Item
        Returns:
        the accepted command types of this group item
      • send

        public void send​(Command command)
      • getStateAs

        public <T extends State> @Nullable T getStateAs​(Class<T> typeClass)
        Description copied from interface: Item
        returns the current state of the item as a specific type
        Specified by:
        getStateAs in interface Item
        Overrides:
        getStateAs in class GenericItem
        Returns:
        the current state in the requested type or null, if state cannot be provided as the requested type
      • stateChanged

        public void stateChanged​(Item item,
                                 State oldState,
                                 State newState)
        Description copied from interface: StateChangeListener
        This method is called, if a state has changed.
        Specified by:
        stateChanged in interface StateChangeListener
        Parameters:
        item - the item whose state has changed
        oldState - the previous state
        newState - the new state
      • stateUpdated

        public void stateUpdated​(Item item,
                                 State state)
        Description copied from interface: StateChangeListener
        This method is called, if a state was updated, but has not changed
        Specified by:
        stateUpdated in interface StateChangeListener
        Parameters:
        item - the item whose state was updated
        state - the current state, same before and after the update
      • setState

        public void setState​(State state)
        Description copied from class: GenericItem
        Set a new state. Subclasses may override this method in order to do necessary conversions upfront. Afterwards, GenericItem.applyState(State) should be called by classes overriding this method.
        Overrides:
        setState in class GenericItem
        Parameters:
        state - new state of this item