001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.language.simple; 018 019 /** 020 * Operators supported by simple language 021 * <ul> 022 * <li>EQ : ==</li> 023 * <li>GT : ></li> 024 * <li>GTE : >=</li> 025 * <li>LT : <</li> 026 * <li>LTE : <=</li> 027 * <li>NOT : !=</li> 028 * <li>contains : tested for if it contains the value</li> 029 * <li>not contains : tested for if it does not contain the value</li> 030 * <li>regex : matching a regular expression</li> 031 * <li>not regex : not matching a regular expression</li> 032 * <li>in : tested for in a list of values separated by comma</li> 033 * <li>not in : tested for not in a list of values separated by comma</li> 034 * </ul> 035 */ 036 public enum SimpleLangaugeOperator { 037 038 EQ, GT, GTE, LT, LTE, NOT, CONTAINS, NOT_CONTAINS, REGEX, NOT_REGEX, IN, NOT_IN; 039 040 public static SimpleLangaugeOperator asOperator(String text) { 041 if ("==".equals(text)) { 042 return EQ; 043 } else if (">".equals(text)) { 044 return GT; 045 } else if (">=".equals(text)) { 046 return GTE; 047 } else if ("<".equals(text)) { 048 return LT; 049 } else if ("<=".equals(text)) { 050 return LTE; 051 } else if ("!=".equals(text)) { 052 return NOT; 053 } else if ("contains".equals(text)) { 054 return CONTAINS; 055 } else if ("not contains".equals(text)) { 056 return NOT_CONTAINS; 057 } else if ("regex".equals(text)) { 058 return REGEX; 059 } else if ("not regex".equals(text)) { 060 return NOT_REGEX; 061 } else if ("in".equals(text)) { 062 return IN; 063 } else if ("not in".equals(text)) { 064 return NOT_IN; 065 } 066 throw new IllegalArgumentException("Operator not supported: " + text); 067 } 068 069 public String getOperatorText(SimpleLangaugeOperator operator) { 070 if (operator == EQ) { 071 return "=="; 072 } else if (operator == GT) { 073 return ">"; 074 } else if (operator == GTE) { 075 return ">="; 076 } else if (operator == LT) { 077 return "<"; 078 } else if (operator == LTE) { 079 return "<="; 080 } else if (operator == NOT) { 081 return "!="; 082 } else if (operator == CONTAINS) { 083 return "contains"; 084 } else if (operator == NOT_CONTAINS) { 085 return "not contains"; 086 } else if (operator == REGEX) { 087 return "regex"; 088 } else if (operator == NOT_REGEX) { 089 return "not regex"; 090 } else if (operator == IN) { 091 return "in"; 092 } else if (operator == NOT_IN) { 093 return "not in"; 094 } 095 return ""; 096 } 097 098 @Override 099 public String toString() { 100 return getOperatorText(this); 101 } 102 }