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;
019import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter;
020
021import java.util.HashSet;
022import java.util.Set;
023
024/**
025 * Enumeration for PropositionTypes.  SIMPLE or COMPOUND.
026 *
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 *
029 */
030public enum PropositionType implements Coded {
031
032    /**
033     * use this flag with the static factory to get a {@link PropositionType} Compound
034     */
035        COMPOUND("C"),
036
037    /**
038     * use this flag with the static factory to get a {@link PropositionType} Simple
039     */
040        SIMPLE("S");
041        
042        private final String code;
043
044    /**
045     * Create a PropositionType of the given code
046     * @param code code the PropositionType should be of.
047     */
048        private PropositionType(String code) {
049                this.code = code;
050        }
051        
052        /**
053         * Returns the operator code for this evaluation operator.
054         * 
055         * @return the operatorCode
056         */
057        @Override
058        public String getCode() {
059                return code;
060        }
061
062    /**
063     * Set of valid type codes
064     */
065        public static final Set<String> VALID_TYPE_CODES = new HashSet<String>();
066        static {
067                for (PropositionType propositionType : values()) {
068                        VALID_TYPE_CODES.add(propositionType.getCode());
069                }
070        }
071
072    /**
073     * Create a PropositionType for the given code
074     * @param code to type the PropositionType
075     * @return PropositionType of the given code
076     * @throws IllegalArgumentException if the given code does not exist
077     */
078        public static PropositionType fromCode(String code) {
079                if (code == null) {
080                        return null;
081                }
082                for (PropositionType propositionType : values()) {
083                        if (propositionType.code.equals(code)) {
084                                return propositionType;
085                        }
086                }
087                throw new IllegalArgumentException("Failed to locate the PropositionType with the given code: " + code);
088        }
089        
090        static final class Adapter extends EnumStringAdapter<PropositionType> {
091        @Override
092                protected Class<PropositionType> getEnumClass() {
093                        return PropositionType.class;
094                }
095                
096        }
097        
098}