001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.message.controls; 021 022 023import org.apache.directory.api.i18n.I18n; 024 025 026/** 027 * Enumeration type for entry changes associates with the persistent search 028 * control and the entry change control. Used for the following ASN1 029 * enumeration: 030 * 031 * <pre> 032 * changeType ENUMERATED 033 * { 034 * add (1), 035 * delete (2), 036 * modify (4), 037 * modDN (8) 038 * } 039 * </pre> 040 * 041 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 042 */ 043public enum ChangeType 044{ 045 /** An ADD */ 046 ADD(1), 047 048 /** A Delete */ 049 DELETE(2), 050 051 /** A Modify */ 052 MODIFY(4), 053 054 /** A MODDN */ 055 MODDN(8); 056 057 private int value; 058 059 060 /** 061 * 062 * Creates a new instance of ChangeType. 063 * 064 * @param value The value for the ChangeType. 065 */ 066 ChangeType( int value ) 067 { 068 this.value = value; 069 } 070 071 072 /** 073 * @return The int value of the ChangeType 074 */ 075 public int getValue() 076 { 077 return value; 078 } 079 080 081 /** 082 * Checks via bitwise AND to see if this ChangeType value is within the 083 * supplied changeTypes. 084 * 085 * @param changeTypes The supplied changeTypes. 086 * @return true, if this ChangeType is present in the supplied changeTypes. 087 */ 088 public boolean presentIn( int changeTypes ) 089 { 090 return value == ( value & changeTypes ); 091 } 092 093 094 /** 095 * Gets the changeType enumeration type for an integer value. 096 * 097 * @param value the value to get the enumeration for 098 * @return the enueration type for the value if the value is valid 099 * @throws IllegalArgumentException if the value is undefined 100 */ 101 public static ChangeType getChangeType( int value ) 102 { 103 switch ( value ) 104 { 105 case 1 : 106 return ADD; 107 108 case 2 : 109 return DELETE; 110 111 case 4 : 112 return MODIFY; 113 114 case 8 : 115 return MODDN; 116 117 default: 118 throw new IllegalArgumentException( I18n.err( I18n.ERR_04055, value ) ); 119 } 120 } 121}