View Javadoc

1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krms.api.repository;
17  
18  import org.kuali.rice.core.api.mo.common.Coded;
19  import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter;
20  
21  import java.util.Arrays;
22  import java.util.Collection;
23  import java.util.Collections;
24  
25  /**
26   * Enum for the representation of the Logical Operators AND OR
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public enum LogicalOperator implements Coded {
31  
32      /**
33       * use this flag with the static factory to get a {@link LogicalOperator} AND
34       */
35  	AND("&"),
36  
37      /**
38       * use this flag with the static factory to get a {@link LogicalOperator} OR
39       */
40  	OR("|");
41  
42  	private final String code;
43  
44      /**
45       * Create the LogicalOperator from the given code
46       * @param code to type LogicalOperator as
47       */
48  	private LogicalOperator(String code){
49  		this.code = code;
50  	}
51  	
52  	@Override
53  	public String getCode(){
54  		return code;
55  	}
56  
57      /**
58       * Collection<String> OP_CODES
59       */
60  	public static final Collection<String> OP_CODES =
61  		Collections.unmodifiableCollection(Arrays.asList(AND.code, OR.code));
62  
63      /**
64       * Collection<String> OP_CODE_NAMES
65       */
66      public static final Collection<String> OP_CODE_NAMES =
67          Collections.unmodifiableCollection(Arrays.asList(AND.name(), OR.name()));
68  
69      /**
70       * Create a LogicalOperator from the given code
71       * @param code used to type LogicalOperator
72       * @return LogicalOperator whose code is given
73       * @throws IllegalArgumentException if the code does not exist
74       */
75  	public static LogicalOperator fromCode(String code) {
76  		if (code == null) {
77  			return null;
78  		}
79  		for (LogicalOperator logicalOperator : values()) {
80  			if (logicalOperator.code.equals(code)) {
81  				return logicalOperator;
82  			}
83  		}
84  		throw new IllegalArgumentException("Failed to locate the LogicalOperator with the given code: " + code);
85  	}
86  	
87  	@Override
88  	public String toString(){
89  		return code;
90  	}
91  	
92  	static final class Adapter extends EnumStringAdapter<LogicalOperator> {
93  		@Override
94  		protected Class<LogicalOperator> getEnumClass() {
95  			return LogicalOperator.class;
96  		}
97  		
98  	}
99  
100 }