001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.dataAccess.filtering; 019 020import io.stallion.exceptions.UsageException; 021 022public enum FilterOperator { 023 EQUAL, 024 NOT_EQUAL, 025 LESS_THAN, 026 LESS_THAN_OR_EQUAL, 027 GREATER_THAN, 028 IN, 029 LIKE, 030 ANY, 031 GREATER_THAN_OR_EQUAL 032 ; 033 public static FilterOperator fromString(String op) { 034 switch (op) { 035 case "eq": 036 case "=": 037 case "==": 038 case "===": 039 return EQUAL; 040 case "like": 041 return LIKE; 042 case "any": 043 return ANY; 044 case "!=": 045 case "neq": 046 return NOT_EQUAL; 047 case ">": 048 case "gt": 049 return GREATER_THAN; 050 case ">=": 051 case "gte": 052 return GREATER_THAN_OR_EQUAL; 053 case "lt": 054 case "<": 055 return LESS_THAN; 056 case "lte": 057 case "<=": 058 return LESS_THAN_OR_EQUAL; 059 case "in": 060 return IN; 061 default: 062 return Enum.valueOf(FilterOperator.class, op); 063 } 064 } 065 066 public String forSql() { 067 switch (this) { 068 case EQUAL: 069 return "="; 070 case NOT_EQUAL: 071 return "!="; 072 case LESS_THAN: 073 return "<"; 074 case GREATER_THAN: 075 return ">"; 076 case LESS_THAN_OR_EQUAL: 077 return "<="; 078 case LIKE: 079 return "LIKE"; 080 case ANY: 081 return "IN"; 082 case IN: 083 return "LIKE"; 084 case GREATER_THAN_OR_EQUAL: 085 return ">="; 086 default: 087 throw new UsageException("Can use FilterOperator " + this.toString() + " with SQL"); 088 } 089 } 090}