001/*
002 * Copyright 2011-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-2024 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-2024 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.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043
044
045
046/**
047 * This enum defines a set of filter types for filters that may be generated
048 * for an object using the LDAP SDK persistence framework.  Classes created by
049 * {@link GenerateSourceFromSchema} (including the
050 * {@code generate-source-from-schema} command-line tool) will include methods
051 * that may be used to generate filters for object contents.
052 */
053public enum PersistFilterType
054{
055  /**
056   * The filter type that may be used to generate a presence filter, like
057   * "(attrName=*)".
058   */
059  PRESENCE,
060
061
062
063  /**
064   * The filter type that may be used to generate an equality filter, like
065   * "(attrName=value)".
066   */
067  EQUALITY,
068
069
070
071  /**
072   * The filter type that may be used to generate a substring filter with a
073   * subInitial element, like "(attrName=value*)".
074   */
075  STARTS_WITH,
076
077
078
079  /**
080   * The filter type that may be used to generate a substring filter with a
081   * subFinal element, like "(attrName=*value)".
082   */
083  ENDS_WITH,
084
085
086
087  /**
088   * The filter type that may be used to generate a substring filter with a
089   * subAny element, like "(attrName=*value*)".
090   */
091  CONTAINS,
092
093
094
095  /**
096   * The filter type that may be used to generate a greater-than-or-equal-to
097   * filter, like "(attrName&gt;=value)".
098   */
099  GREATER_OR_EQUAL,
100
101
102
103  /**
104   * The filter type that may be used to generate a less-than-or-equal-to
105   * filter, like "(attrName&lt;=value)".
106   */
107  LESS_OR_EQUAL,
108
109
110
111  /**
112   * The filter type that may be used to generate an approximate match filter,
113   * like "(attrName~=value)".
114   */
115  APPROXIMATELY_EQUAL_TO;
116
117
118
119  /**
120   * Retrieves the filter type with the specified name.
121   *
122   * @param  name  The name of the filter type to retrieve.  It must not be
123   *               {@code null}.
124   *
125   * @return  The requested filter type, or {@code null} if no such type is
126   *          defined.
127   */
128  @Nullable()
129  public static PersistFilterType forName(@NotNull final String name)
130  {
131    switch (StaticUtils.toLowerCase(name))
132    {
133      case "presence":
134        return PRESENCE;
135      case "equality":
136        return EQUALITY;
137      case "startswith":
138      case "starts-with":
139      case "starts_with":
140        return STARTS_WITH;
141      case "endswith":
142      case "ends-with":
143      case "ends_with":
144        return ENDS_WITH;
145      case "contains":
146        return CONTAINS;
147      case "greaterorequal":
148      case "greater-or-equal":
149      case "greater_or_equal":
150        return GREATER_OR_EQUAL;
151      case "lessorequal":
152      case "less-or-equal":
153      case "less_or_equal":
154        return LESS_OR_EQUAL;
155      case "approximatelyequalto":
156      case "approximately-equal-to":
157      case "approximately_equal_to":
158        return APPROXIMATELY_EQUAL_TO;
159      default:
160        return null;
161    }
162  }
163}