001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.util;
017
018import java.util.HashMap;
019import java.util.Map;
020import java.util.Set;
021
022/**
023 * Map implementation takes a <code>Set</code> of Strings and converts to Map
024 * where the string is the map key and value is the Boolean true, convenience
025 * collection for expression language.
026 *
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public class BooleanMap extends HashMap<String, Boolean> {
030    private static final long serialVersionUID = 4042557657401395547L;
031
032    /**
033     * Copy constructor.
034     *
035     * @param m map to copy
036     */
037    public BooleanMap(Map<? extends String, ? extends Boolean> m) {
038        super(m);
039    }
040
041    /**
042     * Sets an initial value of {@link Boolean#TRUE} for a given provided set of keys.
043     *
044     * @param keys set of keys to map to {@link Boolean#TRUE}
045     */
046    public BooleanMap(Set<String> keys) {
047        super();
048
049        for (String key : keys) {
050            this.put(key, Boolean.TRUE);
051        }
052    }
053
054    /**
055     * Overrides the get method to return Boolean false if the key does not
056     * exist in the Map.
057     *
058     * {@inheritDoc}
059     */
060    @Override
061    public Boolean get(Object key) {
062        if (super.containsKey(key)) {
063            return super.get(key);
064        }
065
066        return Boolean.FALSE;
067    }
068
069}