001/**
002 * Copyright 2005-2016 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.krms.api.repository.proposition;
017
018import org.kuali.rice.core.api.mo.common.Coded;
019
020import java.util.HashSet;
021import java.util.Set;
022
023/**
024 * enum used to specify the PropositionParameterType CONSTANT TERM FUNCTION OPERATOR
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 *
028 */
029public enum PropositionParameterType implements Coded {
030
031    /**
032     * use this flag with the static factory to get a {@link PropositionParameterType} Constant
033     */
034        CONSTANT("C"),
035
036    /**
037     * use this flag with the static factory to get a {@link PropositionParameterType} Term
038     */
039        TERM("T"),
040
041    /**
042     * use this flag with the static factory to get a {@link PropositionParameterType} Function
043     */
044        FUNCTION("F"),
045
046    /**
047     * use this flag with the static factory to get a {@link PropositionParameterType} Operator
048     */
049        OPERATOR("O");
050        
051        private final String code;
052
053    /**
054     * Create a PropositionParameterType of the given code
055     * @param code code the PropositionParameterType should be of
056     */
057        private PropositionParameterType(String code) {
058                this.code = code;
059        }
060
061    @Override
062        public String getCode() {
063                return code;
064        }
065
066    /**
067     * Set of valid type codes
068     */
069        public static final Set<String> VALID_TYPE_CODES = new HashSet<String>();
070        static {
071                for (PropositionParameterType propositionParameterType : values()) {
072                        VALID_TYPE_CODES.add(propositionParameterType.getCode());
073                }
074        }
075
076    /**
077     * Create a PropositionParameterType from the given code
078     * @param code to type the PropositionParameter
079     * @return PropositionParameterType of the given code
080     * @throws IllegalArgumentException if the type code does not exist
081     */
082        public static PropositionParameterType fromCode(String code) {
083                if (code == null) {
084                        return null;
085                }
086                for (PropositionParameterType propositionParameterType : values()) {
087                        if (propositionParameterType.code.equals(code)) {
088                                return propositionParameterType;
089                        }
090                }
091                throw new IllegalArgumentException("Failed to locate the PropositionParameterType with the given code: " + code);
092        }
093        
094}