View Javadoc

1   /**
2    * Copyright 2005-2012 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   * Representations of the Logical Operator's 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  	public static final Collection<String> OP_CODES =
58  		Collections.unmodifiableCollection(Arrays.asList(AND.code, OR.code));
59  		
60      public static final Collection<String> OP_CODE_NAMES =
61          Collections.unmodifiableCollection(Arrays.asList(AND.name(), OR.name()));
62  
63      /**
64       * Create a LogicalOperator from the given code
65       * @param code used to type LogicalOperator
66       * @return LogicalOperator whose code is given
67       * @throws IllegalArgumentException if the code does not exist
68       */
69  	public static LogicalOperator fromCode(String code) {
70  		if (code == null) {
71  			return null;
72  		}
73  		for (LogicalOperator logicalOperator : values()) {
74  			if (logicalOperator.code.equals(code)) {
75  				return logicalOperator;
76  			}
77  		}
78  		throw new IllegalArgumentException("Failed to locate the LogicalOperator with the given code: " + code);
79  	}
80  	
81  	@Override
82  	public String toString(){
83  		return code;
84  	}
85  	
86  	static final class Adapter extends EnumStringAdapter<LogicalOperator> {
87  		@Override
88  		protected Class<LogicalOperator> getEnumClass() {
89  			return LogicalOperator.class;
90  		}
91  		
92  	}
93  
94  }