View Javadoc
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      ADD(1),
46  
47      DELETE(2),
48  
49      MODIFY(4),
50  
51      MODDN(8);
52  
53      private int value;
54  
55  
56      /**
57       * 
58       * Creates a new instance of ChangeType.
59       *
60       * @param value The value for the ChangeType.
61       */
62      private ChangeType( int value )
63      {
64          this.value = value;
65      }
66  
67  
68      /**
69       * @return The int value of the ChangeType
70       */
71      public int getValue()
72      {
73          return value;
74      }
75  
76  
77      /**
78       * Checks via bitwise AND to see if this ChangeType value is within the
79       * supplied changeTypes.
80       *
81       * @param changeTypes The supplied changeTypes.
82       * @return true, if this ChangeType is present in the supplied changeTypes.
83       */
84      public boolean presentIn( int changeTypes )
85      {
86          return value == ( value & changeTypes );
87      }
88  
89  
90      /**
91       * Gets the changeType enumeration type for an integer value.
92       * 
93       * @param value the value to get the enumeration for
94       * @return the enueration type for the value if the value is valid
95       * @throws IllegalArgumentException if the value is undefined
96       */
97      public static ChangeType getChangeType( int value )
98      {
99          switch ( value )
100         {
101             case ( 1 ):
102                 return ADD;
103             case ( 2 ):
104                 return DELETE;
105             case ( 4 ):
106                 return MODIFY;
107             case ( 8 ):
108                 return MODDN;
109             default:
110                 throw new IllegalArgumentException( I18n.err( I18n.ERR_04055, value ) );
111         }
112     }
113 }