001/*
002 * Copyright 2010-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2010-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) 2010-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.controls;
037
038
039
040import com.unboundid.util.StaticUtils;
041
042
043
044/**
045 * This enum defines the synchronization states for entries returned with the
046 * content synchronization state control.  See the documentation for the
047 * {@link ContentSyncRequestControl} class for more information about using the
048 * content synchronization operation.
049 */
050public enum ContentSyncState
051{
052  /**
053   * Indicates that the associated entry or reference was already present in
054   * the server when the synchronization was initiated.
055   */
056  PRESENT(0),
057
058
059
060  /**
061   * Indicates that the associated entry or reference was just created by an
062   * add or modify DN operation.
063   */
064  ADD(1),
065
066
067
068  /**
069   * Indicates that the associated entry or reference was just updated by a
070   * modify or modify DN operation.
071   */
072  MODIFY(2),
073
074
075
076  /**
077   * Indicates that the associated entry or reference was just removed by a
078   * delete or modify DN operation.
079   */
080  DELETE(3);
081
082
083
084  // The integer value of this state.
085  private final int intValue;
086
087
088
089  /**
090   * Creates a new content synchronization state with the specified integer
091   * value.
092   *
093   * @param  intValue  The integer value for this request mode.
094   */
095  ContentSyncState(final int intValue)
096  {
097    this.intValue = intValue;
098  }
099
100
101
102  /**
103   * Retrieves the integer value for this synchronization state.
104   *
105   * @return  The integer value for this synchronization state.
106   */
107  public int intValue()
108  {
109    return intValue;
110  }
111
112
113
114  /**
115   * Retrieves the content synchronization state with the specified integer
116   * value.
117   *
118   * @param  intValue  The integer value for which to retrieve the corresponding
119   *                   synchronization state.
120   *
121   * @return  The content synchronization state with the specified integer
122   *          value, or {@code null} if the given value does not correspond with
123   *          any defined state.
124   */
125  public static ContentSyncState valueOf(final int intValue)
126  {
127    if (intValue == PRESENT.intValue())
128    {
129      return PRESENT;
130    }
131    else if (intValue == ADD.intValue())
132    {
133      return ADD;
134    }
135    else if (intValue == MODIFY.intValue())
136    {
137      return MODIFY;
138    }
139    else if (intValue == DELETE.intValue())
140    {
141      return DELETE;
142    }
143    else
144    {
145      return null;
146    }
147  }
148
149
150
151  /**
152   * Retrieves the content synchronization state with the specified name.
153   *
154   * @param  name  The name of the content synchronization state to retrieve.
155   *               It must not be {@code null}.
156   *
157   * @return  The requested content synchronization state, or {@code null} if no
158   *          such state is defined.
159   */
160  public static ContentSyncState forName(final String name)
161  {
162    switch (StaticUtils.toLowerCase(name))
163    {
164      case "present":
165        return PRESENT;
166      case "add":
167        return ADD;
168      case "modify":
169        return MODIFY;
170      case "delete":
171        return DELETE;
172      default:
173        return null;
174    }
175  }
176}