001/* 002 * Copyright 2010-2018 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2010-2018 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.controls; 022 023 024 025import com.unboundid.util.StaticUtils; 026 027 028 029/** 030 * This enum defines the synchronization states for entries returned with the 031 * content synchronization state control. See the documentation for the 032 * {@link ContentSyncRequestControl} class for more information about using the 033 * content synchronization operation. 034 */ 035public enum ContentSyncState 036{ 037 /** 038 * Indicates that the associated entry or reference was already present in 039 * the server when the synchronization was initiated. 040 */ 041 PRESENT(0), 042 043 044 045 /** 046 * Indicates that the associated entry or reference was just created by an 047 * add or modify DN operation. 048 */ 049 ADD(1), 050 051 052 053 /** 054 * Indicates that the associated entry or reference was just updated by a 055 * modify or modify DN operation. 056 */ 057 MODIFY(2), 058 059 060 061 /** 062 * Indicates that the associated entry or reference was just removed by a 063 * delete or modify DN operation. 064 */ 065 DELETE(3); 066 067 068 069 // The integer value of this state. 070 private final int intValue; 071 072 073 074 /** 075 * Creates a new content synchronization state with the specified integer 076 * value. 077 * 078 * @param intValue The integer value for this request mode. 079 */ 080 ContentSyncState(final int intValue) 081 { 082 this.intValue = intValue; 083 } 084 085 086 087 /** 088 * Retrieves the integer value for this synchronization state. 089 * 090 * @return The integer value for this synchronization state. 091 */ 092 public int intValue() 093 { 094 return intValue; 095 } 096 097 098 099 /** 100 * Retrieves the content synchronization state with the specified integer 101 * value. 102 * 103 * @param intValue The integer value for which to retrieve the corresponding 104 * synchronization state. 105 * 106 * @return The content synchronization state with the specified integer 107 * value, or {@code null} if the given value does not correspond with 108 * any defined state. 109 */ 110 public static ContentSyncState valueOf(final int intValue) 111 { 112 if (intValue == PRESENT.intValue()) 113 { 114 return PRESENT; 115 } 116 else if (intValue == ADD.intValue()) 117 { 118 return ADD; 119 } 120 else if (intValue == MODIFY.intValue()) 121 { 122 return MODIFY; 123 } 124 else if (intValue == DELETE.intValue()) 125 { 126 return DELETE; 127 } 128 else 129 { 130 return null; 131 } 132 } 133 134 135 136 /** 137 * Retrieves the content synchronization state with the specified name. 138 * 139 * @param name The name of the content synchronization state to retrieve. 140 * It must not be {@code null}. 141 * 142 * @return The requested content synchronization state, or {@code null} if no 143 * such state is defined. 144 */ 145 public static ContentSyncState forName(final String name) 146 { 147 switch (StaticUtils.toLowerCase(name)) 148 { 149 case "present": 150 return PRESENT; 151 case "add": 152 return ADD; 153 case "modify": 154 return MODIFY; 155 case "delete": 156 return DELETE; 157 default: 158 return null; 159 } 160 } 161}