Interface IModel<T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default <R extends T>
      IModel<R>
      as​(Class<R> clazz)
      Returns an IModel, returning the object typed as R if it is an instance of that type, otherwise null.
      default <R,​U>
      IModel<R>
      combineWith​(IModel<U> other, org.danekja.java.util.function.serializable.SerializableBiFunction<? super T,​? super U,​R> combiner)
      Returns a IModel applying the given combining function to the current model object and to the one from the other model, if they are not null.
      default void detach()
      Detaches model after use.
      default IModel<T> filter​(org.danekja.java.util.function.serializable.SerializablePredicate<? super T> predicate)
      Returns a IModel checking whether the predicate holds for the contained object, if it is not null.
      default <R> IModel<R> flatMap​(org.danekja.java.util.function.serializable.SerializableFunction<? super T,​IModel<R>> mapper)
      Returns a IModel applying the given IModel-bearing mapper to the contained object, if it is not null.
      T getObject()
      Gets the model object.
      default IModel<Boolean> isPresent()
      Returns a IModel, returning whether the contained object is non-null.
      default <R> IModel<R> map​(org.danekja.java.util.function.serializable.SerializableFunction<? super T,​R> mapper)
      Returns a IModel applying the given mapper to the contained object, if it is not null.
      static <T> IModel<T> of​(IModel<?> model)
      Suppresses generics warning when casting model types.
      default IModel<T> orElse​(T other)
      Returns a IModel, returning either the contained object or the given default value, depending on the nullness of the contained object.
      default IModel<T> orElseGet​(org.danekja.java.util.function.serializable.SerializableSupplier<? extends T> other)
      Returns a IModel, returning either the contained object or invoking the given supplier to get a default value.
      default void setObject​(T object)
      Sets the model object.
    • Method Detail

      • getObject

        T getObject()
        Gets the model object.
        Returns:
        The model object
      • detach

        default void detach()
        Description copied from interface: IDetachable
        Detaches model after use. This is generally used to null out transient references that can be re-attached later.
        Specified by:
        detach in interface IDetachable
      • filter

        default IModel<Tfilter​(org.danekja.java.util.function.serializable.SerializablePredicate<? super T> predicate)
        Returns a IModel checking whether the predicate holds for the contained object, if it is not null. If the predicate doesn't evaluate to true, the contained object will be null.
        Parameters:
        predicate - a predicate to be used for testing the contained object
        Returns:
        a new IModel
      • map

        default <R> IModel<R> map​(org.danekja.java.util.function.serializable.SerializableFunction<? super T,​R> mapper)
        Returns a IModel applying the given mapper to the contained object, if it is not null.
        Type Parameters:
        R - the new type of the contained object
        Parameters:
        mapper - a mapper, to be applied to the contained object
        Returns:
        a new IModel
      • combineWith

        default <R,​U> IModel<R> combineWith​(IModel<U> other,
                                                  org.danekja.java.util.function.serializable.SerializableBiFunction<? super T,​? super U,​R> combiner)
        Returns a IModel applying the given combining function to the current model object and to the one from the other model, if they are not null.
        Type Parameters:
        R - the resulting type
        U - the other models type
        Parameters:
        other - another model to be combined with this one
        combiner - a function combining this and the others object to a result.
        Returns:
        a new IModel
      • flatMap

        default <R> IModel<R> flatMap​(org.danekja.java.util.function.serializable.SerializableFunction<? super T,​IModel<R>> mapper)
        Returns a IModel applying the given IModel-bearing mapper to the contained object, if it is not null.
        Type Parameters:
        R - the new type of the contained object
        Parameters:
        mapper - a mapper, to be applied to the contained object
        Returns:
        a new IModel
        See Also:
        LambdaModel.of(IModel, SerializableFunction, SerializableBiConsumer)
      • orElse

        default IModel<TorElse​(T other)
        Returns a IModel, returning either the contained object or the given default value, depending on the nullness of the contained object.

        Possible usages:

        • myComponent = new AnyComponent(&quot;someId&quot;, someModel.orElse(defaultValue)); - This way Wicket will make use of the default value if the model object of someModel is null.
        • in the middle of the application logic: ... = someModel.orElse(default).getModelObject();

        Parameters:
        other - a default value
        Returns:
        a new IModel
      • orElseGet

        default IModel<TorElseGet​(org.danekja.java.util.function.serializable.SerializableSupplier<? extends T> other)
        Returns a IModel, returning either the contained object or invoking the given supplier to get a default value.
        Parameters:
        other - a supplier to be used as a default
        Returns:
        a new IModel
      • isPresent

        default IModel<BooleanisPresent()
        Returns a IModel, returning whether the contained object is non-null.
        Returns:
        a new IModel
      • as

        default <R extends TIModel<R> as​(Class<R> clazz)
        Returns an IModel, returning the object typed as R if it is an instance of that type, otherwise null.
        Type Parameters:
        R - the type the object should be an instance of
        Parameters:
        clazz - the Class the current model object should be an instance of
        Returns:
        a new IModel
      • of

        static <T> IModel<T> of​(IModel<?> model)
        Suppresses generics warning when casting model types.
        Type Parameters:
        T -
        Parameters:
        model -
        Returns:
        cast model