Class MdibStorageUtil


  • public class MdibStorageUtil
    extends Object
    Helper class to expose information hosted by MdibStorage.

    MdibStorageUtil is used for but not limited to type-dependent data exposition.

    • Method Detail

      • exposeInstance

        public <T> Optional<T> exposeInstance​(@Nullable
                                              Object instance,
                                              Class<T> clazz)
        Accepts an object of a certain instance and cast it to a given type.
        Type Parameters:
        T - the resulting type.
        Parameters:
        instance - the instance to cast.
        clazz - the class that the instance is supposed to be cast to.
        Returns:
        a cast version of instance or Optional.empty() if instance is null or not assignable from the given type.
      • exposeListOfType

        public <T,​V> List<T> exposeListOfType​(Collection<V> collection,
                                                    Class<T> clazz)
        Accepts a collection of objects and cast it to a list of the given type.
        Type Parameters:
        T - the resulting type.
        V - the collection type.
        Parameters:
        collection - the collection with objects to cast.
        clazz - the class that the collection is supposed to carry.
        Returns:
        a cast version of collection as list that only includes assignable objects.
      • exposeEntityList

        public List<MdibEntity> exposeEntityList​(Map<String,​MdibEntity> entities,
                                                 Collection<String> collection)
        Takes a map of entities and a collection of handles and converts it to a list of entities.
        Parameters:
        entities - the entities to access.
        collection - an ordered collection of handles.
        Returns:
        a list of entities sorted by the order of collection. Entities that cannot be found in entities are omitted from the result.