All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazon.ask.mvc.view.ModelAndView Maven / Gradle / Ivy

Go to download

The Alexa Skills Kit MVC Framework extends the existing ASK SDK, adding features for mapping requests to methods and rendering responses via view scripts and templates such as Nashorn Javascript and Freemarker. It also integrates with the ASK SDK Interaction Model Mapper framework to create a single environment where both the interaction model and business logic of skills can be managed as code packages.

The newest version!
/*
    Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.

    Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
    except in compliance with the License. A copy of the License is located at

        http://aws.amazon.com/apache2.0/

    or in the "license" file accompanying this file. This file 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 com.amazon.ask.mvc.view;

import com.amazon.ask.util.ValidationUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * Holds a view name used to render the response for the current request,
 * as well as the model used to render it.
 */
public class ModelAndView {
    protected final String viewName;
    protected final Map model;

    /**
     * Builds a new model and view with an empty model and the specified view name
     *
     * @param viewName name of the view
     */
    public ModelAndView(String viewName) {
        this(viewName, new HashMap<>());
    }

    /**
     * Builds a new model and view with the specified view name and a model
     *
     * @param viewName name of the view
     * @param model of key value pairs
     */
    public ModelAndView(String viewName, Map model) {
        this.viewName = ValidationUtils.assertStringNotEmpty(viewName, "viewName");
        this.model = new HashMap<>(model);
    }

    public int size() {
        return model.size();
    }

    public boolean isEmpty() {
        return model.isEmpty();
    }

    public boolean containsKey(Object key) {
        return model.containsKey(key);
    }

    public boolean containsValue(Object value) {
        return model.containsValue(value);
    }

    public Object get(Object key) {
        return model.get(key);
    }

    public Object put(String key, Object value) {
        return model.put(key, value);
    }

    public Object remove(Object key) {
        return model.remove(key);
    }

    public void putAll(Map m) {
        model.putAll(m);
    }

    public void clear() {
        model.clear();
    }

    public Set keySet() {
        return model.keySet();
    }

    public Collection values() {
        return model.values();
    }

    public Set> entrySet() {
        return model.entrySet();
    }

    public Object getOrDefault(Object key, Object defaultValue) {
        return model.getOrDefault(key, defaultValue);
    }

    public void forEach(BiConsumer action) {
        model.forEach(action);
    }

    public void replaceAll(BiFunction function) {
        model.replaceAll(function);
    }

    public Object putIfAbsent(String key, Object value) {
        return model.putIfAbsent(key, value);
    }

    public boolean remove(Object key, Object value) {
        return model.remove(key, value);
    }

    public boolean replace(String key, Object oldValue, Object newValue) {
        return model.replace(key, oldValue, newValue);
    }

    public Object replace(String key, Object value) {
        return model.replace(key, value);
    }

    public Object computeIfAbsent(String key, Function mappingFunction) {
        return model.computeIfAbsent(key, mappingFunction);
    }

    public Object computeIfPresent(String key, BiFunction remappingFunction) {
        return model.computeIfPresent(key, remappingFunction);
    }

    public Object compute(String key, BiFunction remappingFunction) {
        return model.compute(key, remappingFunction);
    }

    public Object merge(String key, Object value, BiFunction remappingFunction) {
        return model.merge(key, value, remappingFunction);
    }

    public String getViewName() {
        return viewName;
    }

    public Map getModel() {
        return model;
    }
}