/**
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.cdlflex.ui.util;

import java.util.Optional;

import org.apache.wicket.model.IModel;

/**
 * Utility functions for IModels.
 */
public final class Models {
    private Models() {

    }

    /**
     * Returns an Optional describing the object value of the given model. If the model or the object in the model is
     * null, an empty optional is returned.
     * 
     * @param model the possibly-null value to describe
     * @param <T> the model object type
     * @return an Optional
     */
    public static <T> Optional<T> optional(IModel<T> model) {
        return Optional.ofNullable(model).map(IModel::getObject);
    }

    /**
     * Checks whether the given Model, or the Object it wraps, is null, and returns true if either is null.
     *
     * @param model The model to check
     * @return true if either the given model, or the object it wraps is null
     */
    public static boolean isNull(IModel<?> model) {
        return model == null || model.getObject() == null;
    }

    /**
     * Checks whether the given Model is null, or the String it wraps is null or empty.
     *
     * @param model The model to check
     * @return True if the model is null, the object it wraps is null or the wrapped string is empty
     */
    public static boolean isEmpty(IModel<String> model) {
        return isNull(model) || model.getObject().isEmpty();
    }
}

@@ -1218,32 +1218,742 @@
 Object);%0A    %7D%0A%0A
+    /**%0A     * Nullsafe way of returning model's object.%0A     *%0A     * @param model the possibly-null model to extract the object from%0A     * @param %3CT%3E the model object type%0A     * @return the model's object, or null%0A     */%0A    public static %3CT%3E T getObject(IModel%3CT%3E model) %7B%0A        return (model == null) ? null : model.getObject();%0A    %7D%0A%0A    /**%0A     * Nullsafe way of setting a model's object.%0A     *%0A     * @param model the possibly-null model to set the object in%0A     * @param object the object to set%0A     * @param %3CT%3E the model object type%0A     */%0A    public static %3CT%3E void setObject(IModel%3CT%3E model, T object) %7B%0A        if (model != null) %7B%0A            model.setObject(object);%0A        %7D%0A    %7D%0A%0A
     /**%0A     * C

Add some model utils functions