001/*
002 * Copyright (c) 2013 Nu Echo Inc. All rights reserved.
003 */
004
005package com.nuecho.rivr.voicexml.turn.first;
006
007import java.util.*;
008
009import com.nuecho.rivr.core.channel.*;
010import com.nuecho.rivr.voicexml.dialogue.*;
011
012/**
013 * First turn passed when running a {@link VoiceXmlDialogue}, it can be used to
014 * consult the parameters from the initial request.
015 *
016 * @author Nu Echo Inc.
017 * @see VoiceXmlDialogue
018 */
019public class VoiceXmlFirstTurn implements FirstTurn {
020
021    private final Map<String, String> mParameters;
022
023    public VoiceXmlFirstTurn() {
024        mParameters = Collections.emptyMap();
025    }
026
027    public VoiceXmlFirstTurn(Map<String, String> parameters) {
028        mParameters = new HashMap<String, String>(parameters);
029    }
030
031    public Map<String, String> getParameters() {
032        return Collections.unmodifiableMap(mParameters);
033    }
034
035    /**
036     * Checks if a parameter has been provided.
037     *
038     * @param key the parameter name
039     * @return true if the parameter exists
040     * @since 1.0.1
041     */
042    public boolean hasParameter(String key) {
043        return mParameters.containsKey(key);
044    }
045
046    /**
047     * Checks if a parameter has been provided.
048     *
049     * @param key the parameter name
050     * @return true if the parameter exists
051     * @deprecated use {@link #hasParameter(String)} instead
052     */
053    @Deprecated
054    public boolean hasParameter(Object key) {
055        return mParameters.containsKey(key);
056    }
057
058    /**
059     * Get a parameter.
060     *
061     * @param key the parameter name
062     * @return the parameter value
063     * @deprecated use {@link #getParameter(String)} instead
064     */
065    @Deprecated
066    public String getParameters(Object key) {
067        return mParameters.get(key);
068    }
069
070    /**
071     * Get a parameter.
072     *
073     * @param key the parameter name
074     * @return the parameter value
075     * @since 1.0.1
076     */
077    public String getParameter(String key) {
078        return mParameters.get(key);
079    }
080
081    /**
082     * Get the list of parameter names.
083     *
084     * @return the parameter names
085     * @since 1.0.1
086     */
087    public Set<String> keySet() {
088        return mParameters.keySet();
089    }
090}