001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.types;
028
029import static org.opends.server.util.StaticUtils.*;
030
031
032
033/**
034 * This class implements an enumeration that may be used to define the
035 * ways in which an attribute may be indexed within the server.
036 */
037@org.opends.server.types.PublicAPI(
038     stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
039     mayInstantiate=false,
040     mayExtend=false,
041     mayInvoke=true)
042public enum IndexType
043{
044  /**
045   * Used to denote a presence index, which may be used to identify
046   * entries containing the associated attribute (regardless of the
047   * value for that attribute).
048   */
049  PRESENCE("presence"),
050
051
052
053  /**
054   * Used to denote an equality index, which may be used to identify
055   * entries containing a specified value for the associated
056   * attribute.
057   */
058  EQUALITY("equality"),
059
060
061
062  /**
063   * Used to denote a substring index, which may be used to identify
064   * entries with one or more values for the associated attribute that
065   * match a given substring assertion.  That substring assertion may
066   * contain any or all of subInitial, subAny, and subFinal elements.
067   */
068  SUBSTRING("substring"),
069
070
071
072  /**
073   * Used to denote a subInitial index, which may be used to identify
074   * entries with one or more values for the associated attribute that
075   * begin with a specified string.
076   */
077  SUBINITIAL("subinitial"),
078
079
080
081  /**
082   * Used to denote a subAny index, which may be used to identify
083   * entries with one or more values for the associated attribute that
084   * contain a specified string.
085   */
086  SUBANY("subany"),
087
088
089
090  /**
091   * Used to denote a subFinal index, which may be used to identify
092   * entries with one or more values for the associated attribute that
093   * end with a specified string.
094   */
095  SUBFINAL("subfinal"),
096
097
098
099  /**
100   * Used to denote a greater-or-equal index, which may be used to
101   * identify entries with one or more values that are greater than or
102   * equal to a specified value.
103   */
104  GREATER_OR_EQUAL("greater-or-equal"),
105
106
107
108  /**
109   * Used to denote a less-or-equal index, which may be used to
110   * identify entries with one or more values that are less than or
111   * equal to a specified value.
112   */
113  LESS_OR_EQUAL("less-or-equal"),
114
115
116
117  /**
118   * Used to denote an approximate index, which may be used to
119   * identify entries with one or more values that are approximately
120   * equal to a specified value.
121   */
122  APPROXIMATE("approximate");
123
124
125
126  /** The human-readable name for this index type. */
127  private final String indexName;
128
129
130
131  /**
132   * Creates a new index type with the specified name.
133   *
134   * @param  indexName  The human-readable name for this index type.
135   */
136  private IndexType(String indexName)
137  {
138    this.indexName = indexName;
139  }
140
141
142
143  /**
144   * Retrieves the index type for the specified name.
145   *
146   * @param  indexName  The name for which to retrieve the
147   *                    associated index type.
148   *
149   * @return  The requested index type, or {@code null} if there is no
150   *          such index type.
151   */
152  public static IndexType forName(String indexName)
153  {
154    String lowerName = toLowerCase(indexName);
155    if (lowerName.equals("presence") || lowerName.equals("pres"))
156    {
157      return PRESENCE;
158    }
159    else if (lowerName.equals("equality") || lowerName.equals("eq"))
160    {
161      return EQUALITY;
162    }
163    else if (lowerName.equals("substring") || lowerName.equals("sub"))
164    {
165      return SUBSTRING;
166    }
167    else if (lowerName.equals("subinitial"))
168    {
169      return SUBINITIAL;
170    }
171    else if (lowerName.equals("subany"))
172    {
173      return SUBANY;
174    }
175    else if (lowerName.equals("subfinal"))
176    {
177      return SUBFINAL;
178    }
179    else if (lowerName.equals("greater-or-equal") ||
180             lowerName.equals("greaterorequal") ||
181             lowerName.equals("greater-than-or-equal-to") ||
182             lowerName.equals("greaterthanorequalto"))
183    {
184      return GREATER_OR_EQUAL;
185    }
186    else if (lowerName.equals("less-or-equal") ||
187             lowerName.equals("lessorequal") ||
188             lowerName.equals("less-than-or-equal-to") ||
189             lowerName.equals("lessthanorequalto"))
190    {
191      return LESS_OR_EQUAL;
192    }
193    else if (lowerName.equals("approximate") ||
194             lowerName.equals("approx"))
195    {
196      return APPROXIMATE;
197    }
198
199    return null;
200  }
201
202
203
204  /**
205   * Retrieves the human-readable name for this index type.
206   *
207   * @return  The human-readable name for this index type.
208   */
209  public String toString()
210  {
211    return indexName;
212  }
213}
214