001 /* 002 * Copyright 2003-2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.commons.events.observable; 017 018 /** 019 * Defines event constants for event handling and matching. 020 * <p> 021 * The constants in this class are of two types: 022 * <ol> 023 * <li>Methods - the base definitions (unique bits) 024 * <li>Groups - combination definitions (method bits combined) 025 * </ol> 026 * <p> 027 * Only a method constant may be compared using == to an event type. 028 * This can include use in a switch statement 029 * <p> 030 * Any constant may be used for filtering. 031 * They may combined using the bitwise OR, <code>|</code>. 032 * They may negated using the bitwise NOT, <code>~</code>. 033 * 034 * @since Commons Events 1.0 035 * @version $Revision: 155443 $ $Date: 2005-02-26 13:19:51 +0000 (Sat, 26 Feb 2005) $ 036 * 037 * @author Stephen Colebourne 038 */ 039 public class ModificationEventType { 040 041 /** The method add(Object) */ 042 public static final int ADD = 0x00000001; 043 /** The method add(int,Object) */ 044 public static final int ADD_INDEXED = 0x00000002; 045 /** The method add(Object,int) */ 046 public static final int ADD_NCOPIES = 0x00000004; 047 /** The method iterator.add(Object) */ 048 public static final int ADD_ITERATED = 0x00000008; 049 050 /** The method addAll(Collection) */ 051 public static final int ADD_ALL = 0x00000010; 052 /** The method addAll(int,Collection) */ 053 public static final int ADD_ALL_INDEXED=0x00000020; 054 055 /** The method remove(Object) */ 056 public static final int REMOVE = 0x00000100; 057 /** The method remove(int) */ 058 public static final int REMOVE_INDEXED =0x00000200; 059 /** The method remove(Object,int) */ 060 public static final int REMOVE_NCOPIES =0x00000400; 061 /** The method remove() */ 062 public static final int REMOVE_NEXT =0x00000800; 063 /** The method iterator.remove() */ 064 public static final int REMOVE_ITERATED=0x00001000; 065 066 /** The method removeAll(Collection) */ 067 public static final int REMOVE_ALL = 0x00002000; 068 /** The method retainAll(Collection) */ 069 public static final int RETAIN_ALL = 0x00004000; 070 /** The method clear() */ 071 public static final int CLEAR = 0x00008000; 072 073 /** The method set(int,Object) */ 074 public static final int SET_INDEXED = 0x00010000; 075 /** The method iterator.set(Object) */ 076 public static final int SET_ITERATED = 0x00020000; 077 078 /** All add methods */ 079 public static final int GROUP_ADD = ADD | ADD_INDEXED | ADD_NCOPIES | ADD_ITERATED | ADD_ALL | ADD_ALL_INDEXED; 080 /** All methods that change without structure modification */ 081 public static final int GROUP_CHANGE = SET_INDEXED | SET_ITERATED; 082 /** All remove methods */ 083 public static final int GROUP_REMOVE = REMOVE | REMOVE_INDEXED | REMOVE_NCOPIES | REMOVE_ITERATED | REMOVE_NEXT | REMOVE_ALL; 084 /** All retain methods */ 085 public static final int GROUP_RETAIN = RETAIN_ALL; 086 /** All clear methods */ 087 public static final int GROUP_CLEAR = CLEAR; 088 /** All reducing methods (remove, retain and clear) */ 089 public static final int GROUP_REDUCE = GROUP_REMOVE | GROUP_CLEAR | GROUP_RETAIN; 090 091 /** All indexed methods */ 092 public static final int GROUP_INDEXED = ADD_INDEXED | ADD_ALL_INDEXED | REMOVE_INDEXED | SET_INDEXED; 093 /** All ncopies methods */ 094 public static final int GROUP_NCOPIES = ADD_NCOPIES | REMOVE_NCOPIES; 095 /** All iterated methods */ 096 public static final int GROUP_ITERATED = ADD_ITERATED | REMOVE_ITERATED | SET_ITERATED; 097 /** All 'next' methods */ 098 public static final int GROUP_NEXT = REMOVE_NEXT; 099 /** All bulk methods (xxxAll, clear) */ 100 public static final int GROUP_BULK = ADD_ALL | ADD_ALL_INDEXED | REMOVE_ALL | RETAIN_ALL | CLEAR; 101 /** All methods that modify the structure */ 102 public static final int GROUP_STRUCTURE_MODIFIED = GROUP_ADD | GROUP_REDUCE; 103 104 /** All methods sent by a Collection */ 105 public static final int GROUP_FROM_COLLECTION = ADD | ADD_ALL | REMOVE | REMOVE_ALL | RETAIN_ALL | CLEAR; 106 /** All methods sent by a Set */ 107 public static final int GROUP_FROM_SET = GROUP_FROM_COLLECTION; 108 /** All methods sent by a List */ 109 public static final int GROUP_FROM_LIST = GROUP_FROM_COLLECTION | ADD_INDEXED | ADD_ALL_INDEXED | REMOVE_INDEXED | SET_INDEXED; 110 /** All methods sent by a Bag */ 111 public static final int GROUP_FROM_BAG = GROUP_FROM_COLLECTION | ADD_NCOPIES | REMOVE_NCOPIES; 112 /** All methods sent by a Buffer */ 113 public static final int GROUP_FROM_BUFFER = GROUP_FROM_COLLECTION | REMOVE_NEXT; 114 115 /** No methods */ 116 public static final int GROUP_NONE = 0x00000000; 117 /** All methods */ 118 public static final int GROUP_ALL = 0xFFFFFFFF; 119 120 /** 121 * Constructor. 122 */ 123 protected ModificationEventType() { 124 super(); 125 } 126 127 /** 128 * Gets a string version of a method event type. 129 * 130 * @param methodType the method event type constant 131 * @return a string description 132 */ 133 public static String toString(final int methodType) { 134 switch (methodType) { 135 case ADD: 136 return "Add"; 137 case ADD_INDEXED: 138 return "AddIndexed"; 139 case ADD_NCOPIES: 140 return "AddNCopies"; 141 case ADD_ITERATED: 142 return "AddIterated"; 143 case ADD_ALL: 144 return "AddAll"; 145 case ADD_ALL_INDEXED: 146 return "AddAllIndexed"; 147 case REMOVE: 148 return "Remove"; 149 case REMOVE_NCOPIES: 150 return "RemoveNCopies"; 151 case REMOVE_INDEXED: 152 return "RemoveIndexed"; 153 case REMOVE_ITERATED: 154 return "RemoveIterated"; 155 case REMOVE_NEXT: 156 return "RemoveNext"; 157 case REMOVE_ALL: 158 return "RemoveAll"; 159 case RETAIN_ALL: 160 return "RetainAll"; 161 case CLEAR: 162 return "Clear"; 163 case SET_INDEXED: 164 return "SetIndexed"; 165 case SET_ITERATED: 166 return "SetIterated"; 167 default: 168 return "Unknown"; 169 } 170 } 171 172 }