1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.message.controls; 21 22 23 import org.apache.directory.api.i18n.I18n; 24 25 26 /** 27 * Enumeration type for entry changes associates with the persistent search 28 * control and the entry change control. Used for the following ASN1 29 * enumeration: 30 * 31 * <pre> 32 * changeType ENUMERATED 33 * { 34 * add (1), 35 * delete (2), 36 * modify (4), 37 * modDN (8) 38 * } 39 * </pre> 40 * 41 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 42 */ 43 public enum ChangeType 44 { 45 /** An ADD */ 46 ADD(1), 47 48 /** A Delete */ 49 DELETE(2), 50 51 /** A Modify */ 52 MODIFY(4), 53 54 /** A MODDN */ 55 MODDN(8); 56 57 private int value; 58 59 60 /** 61 * 62 * Creates a new instance of ChangeType. 63 * 64 * @param value The value for the ChangeType. 65 */ 66 ChangeType( int value ) 67 { 68 this.value = value; 69 } 70 71 72 /** 73 * @return The int value of the ChangeType 74 */ 75 public int getValue() 76 { 77 return value; 78 } 79 80 81 /** 82 * Checks via bitwise AND to see if this ChangeType value is within the 83 * supplied changeTypes. 84 * 85 * @param changeTypes The supplied changeTypes. 86 * @return true, if this ChangeType is present in the supplied changeTypes. 87 */ 88 public boolean presentIn( int changeTypes ) 89 { 90 return value == ( value & changeTypes ); 91 } 92 93 94 /** 95 * Gets the changeType enumeration type for an integer value. 96 * 97 * @param value the value to get the enumeration for 98 * @return the enueration type for the value if the value is valid 99 * @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 }