001/*
002 * Copyright 2011-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2011-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.persist;
037
038
039
040import com.unboundid.util.StaticUtils;
041
042
043
044/**
045 * This enum defines a set of filter types for filters that may be generated
046 * for an object using the LDAP SDK persistence framework.  Classes created by
047 * {@link GenerateSourceFromSchema} (including the
048 * {@code generate-source-from-schema} command-line tool) will include methods
049 * that may be used to generate filters for object contents.
050 */
051public enum PersistFilterType
052{
053  /**
054   * The filter type that may be used to generate a presence filter, like
055   * "(attrName=*)".
056   */
057  PRESENCE,
058
059
060
061  /**
062   * The filter type that may be used to generate an equality filter, like
063   * "(attrName=value)".
064   */
065  EQUALITY,
066
067
068
069  /**
070   * The filter type that may be used to generate a substring filter with a
071   * subInitial element, like "(attrName=value*)".
072   */
073  STARTS_WITH,
074
075
076
077  /**
078   * The filter type that may be used to generate a substring filter with a
079   * subFinal element, like "(attrName=*value)".
080   */
081  ENDS_WITH,
082
083
084
085  /**
086   * The filter type that may be used to generate a substring filter with a
087   * subAny element, like "(attrName=*value*)".
088   */
089  CONTAINS,
090
091
092
093  /**
094   * The filter type that may be used to generate a greater-than-or-equal-to
095   * filter, like "(attrName&gt;=value)".
096   */
097  GREATER_OR_EQUAL,
098
099
100
101  /**
102   * The filter type that may be used to generate a less-than-or-equal-to
103   * filter, like "(attrName&lt;=value)".
104   */
105  LESS_OR_EQUAL,
106
107
108
109  /**
110   * The filter type that may be used to generate an approximate match filter,
111   * like "(attrName~=value)".
112   */
113  APPROXIMATELY_EQUAL_TO;
114
115
116
117  /**
118   * Retrieves the filter type with the specified name.
119   *
120   * @param  name  The name of the filter type to retrieve.  It must not be
121   *               {@code null}.
122   *
123   * @return  The requested filter type, or {@code null} if no such type is
124   *          defined.
125   */
126  public static PersistFilterType forName(final String name)
127  {
128    switch (StaticUtils.toLowerCase(name))
129    {
130      case "presence":
131        return PRESENCE;
132      case "equality":
133        return EQUALITY;
134      case "startswith":
135      case "starts-with":
136      case "starts_with":
137        return STARTS_WITH;
138      case "endswith":
139      case "ends-with":
140      case "ends_with":
141        return ENDS_WITH;
142      case "contains":
143        return CONTAINS;
144      case "greaterorequal":
145      case "greater-or-equal":
146      case "greater_or_equal":
147        return GREATER_OR_EQUAL;
148      case "lessorequal":
149      case "less-or-equal":
150      case "less_or_equal":
151        return LESS_OR_EQUAL;
152      case "approximatelyequalto":
153      case "approximately-equal-to":
154      case "approximately_equal_to":
155        return APPROXIMATELY_EQUAL_TO;
156      default:
157        return null;
158    }
159  }
160}