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; 017 018import org.kuali.rice.core.api.mo.common.Coded; 019import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter; 020 021import java.util.Arrays; 022import java.util.Collection; 023import java.util.Collections; 024 025/** 026 * Enum for the representation of the Logical Operators AND OR 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public enum LogicalOperator implements Coded { 031 032 /** 033 * use this flag with the static factory to get a {@link LogicalOperator} AND 034 */ 035 AND("&"), 036 037 /** 038 * use this flag with the static factory to get a {@link LogicalOperator} OR 039 */ 040 OR("|"); 041 042 private final String code; 043 044 /** 045 * Create the LogicalOperator from the given code 046 * @param code to type LogicalOperator as 047 */ 048 private LogicalOperator(String code){ 049 this.code = code; 050 } 051 052 @Override 053 public String getCode(){ 054 return code; 055 } 056 057 /** 058 * Collection<String> OP_CODES 059 */ 060 public static final Collection<String> OP_CODES = 061 Collections.unmodifiableCollection(Arrays.asList(AND.code, OR.code)); 062 063 /** 064 * Collection<String> OP_CODE_NAMES 065 */ 066 public static final Collection<String> OP_CODE_NAMES = 067 Collections.unmodifiableCollection(Arrays.asList(AND.name(), OR.name())); 068 069 /** 070 * Create a LogicalOperator from the given code 071 * @param code used to type LogicalOperator 072 * @return LogicalOperator whose code is given 073 * @throws IllegalArgumentException if the code does not exist 074 */ 075 public static LogicalOperator fromCode(String code) { 076 if (code == null) { 077 return null; 078 } 079 for (LogicalOperator logicalOperator : values()) { 080 if (logicalOperator.code.equals(code)) { 081 return logicalOperator; 082 } 083 } 084 throw new IllegalArgumentException("Failed to locate the LogicalOperator with the given code: " + code); 085 } 086 087 @Override 088 public String toString(){ 089 return code; 090 } 091 092 static final class Adapter extends EnumStringAdapter<LogicalOperator> { 093 @Override 094 protected Class<LogicalOperator> getEnumClass() { 095 return LogicalOperator.class; 096 } 097 098 } 099 100}